fix: add sanitizer to ldap account and password (#3372)

Signed-off-by: hsinhoyeh <yhh92u@gmail.com>
This commit is contained in:
hsinhoyeh
2024-03-11 22:46:11 +01:00
committed by GitHub
parent 54ff639312
commit 77333d619c
2 changed files with 16 additions and 0 deletions
+4
View File
@@ -460,6 +460,7 @@ func (c *ldapConnector) userEntry(conn *ldap.Conn, username string) (user ldap.E
func (c *ldapConnector) Login(ctx context.Context, s connector.Scopes, username, password string) (ident connector.Identity, validPass bool, err error) {
// make this check to avoid unauthenticated bind to the LDAP server.
if password == "" {
return connector.Identity{}, false, nil
}
@@ -471,6 +472,9 @@ func (c *ldapConnector) Login(ctx context.Context, s connector.Scopes, username,
user ldap.Entry
)
username = ldap.EscapeFilter(username)
password = ldap.EscapeFilter(password)
err = c.do(ctx, func(conn *ldap.Conn) error {
entry, found, err := c.userEntry(conn, username)
if err != nil {
+12
View File
@@ -83,6 +83,18 @@ func TestQuery(t *testing.T) {
password: "foo",
wantBadPW: true, // Want invalid password, not a query error.
},
{
name: "invalid wildcard username",
username: "a*", // wildcard query is not allowed
password: "foo",
wantBadPW: true, // Want invalid password, not a query error.
},
{
name: "invalid wildcard password",
username: "john",
password: "*", // wildcard password is not allowed
wantBadPW: true, // Want invalid password, not a query error.
},
}
runTests(t, connectLDAP, c, tests)