Skip to content

Commit 9b701f8

Browse files
committed
1 parent 3535e2f commit 9b701f8

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

spec/LdapAuth.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,40 @@ describe('LDAP Injection Prevention', () => {
9393
});
9494
});
9595

96+
describe('authData validation', () => {
97+
it('should reject missing authData.id', async done => {
98+
const server = await mockLdapServer(port, 'uid=testuser, o=example');
99+
const options = {
100+
suffix: 'o=example',
101+
url: `ldap://localhost:${port}`,
102+
dn: 'uid={{id}}, o=example',
103+
};
104+
try {
105+
await ldap.validateAuthData({ password: 'secret' }, options);
106+
fail('Should have rejected missing id');
107+
} catch (err) {
108+
expect(err.message).toBe('LDAP: Wrong username or password');
109+
}
110+
server.close(done);
111+
});
112+
113+
it('should reject non-string authData.id', async done => {
114+
const server = await mockLdapServer(port, 'uid=testuser, o=example');
115+
const options = {
116+
suffix: 'o=example',
117+
url: `ldap://localhost:${port}`,
118+
dn: 'uid={{id}}, o=example',
119+
};
120+
try {
121+
await ldap.validateAuthData({ id: 123, password: 'secret' }, options);
122+
fail('Should have rejected non-string id');
123+
} catch (err) {
124+
expect(err.message).toBe('LDAP: Wrong username or password');
125+
}
126+
server.close(done);
127+
});
128+
});
129+
96130
describe('DN injection prevention', () => {
97131
it('should prevent DN injection via comma in authData.id', async done => {
98132
// Mock server accepts the DN that would result from an unescaped injection

src/Adapters/Auth/ldap.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ function validateAuthData(authData, options) {
117117
? { url: options.url, tlsOptions: options.tlsOptions }
118118
: { url: options.url };
119119

120+
if (typeof authData.id !== 'string') {
121+
return Promise.reject(
122+
new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'LDAP: Wrong username or password')
123+
);
124+
}
120125
const client = ldapjs.createClient(clientOptions);
121126
const escapedId = escapeDN(authData.id);
122127
const userCn =

0 commit comments

Comments
 (0)