mirror of
https://github.com/netbirdio/dex.git
synced 2026-05-22 18:43:53 -07:00
fix: add sanitizer to ldap account and password (#3372)
Signed-off-by: hsinhoyeh <yhh92u@gmail.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user