Skip to content

Commit da905a3

Browse files
davimacedofastrde
andauthored
Merge pull request from GHSA-4w46-w44m-3jq3
* strip password after authentication to prevent cleartext password storage * fixed forgotten testcase forcing ;-/ * added test to check if password is not stored in user record Co-authored-by: Fabian Strachanski <[email protected]>
1 parent 4dee0bc commit da905a3

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Diff for: spec/LdapAuth.spec.js

+46
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,49 @@ it('Should fail if the LDAP server encounters an error while searching', done =>
211211
.finally(() => server.close());
212212
});
213213
});
214+
215+
it('Should delete the password from authData after validation', done => {
216+
mockLdapServer(port, 'uid=testuser, o=example', true).then(server => {
217+
const options = {
218+
suffix: 'o=example',
219+
url: `ldap://localhost:${port}`,
220+
dn: 'uid={{id}}, o=example'
221+
};
222+
223+
const authData = { id: 'testuser', password: 'secret' };
224+
225+
ldap
226+
.validateAuthData(authData, options)
227+
.then(() => {
228+
expect(authData).toEqual({ id: 'testuser' });
229+
done();
230+
})
231+
.catch(done.fail)
232+
.finally(() => server.close());
233+
});
234+
});
235+
236+
it('Should not save the password in the user record after authentication', done => {
237+
mockLdapServer(port, 'uid=testuser, o=example', true).then(server => {
238+
const options = {
239+
suffix: 'o=example',
240+
url: `ldap://localhost:${port}`,
241+
dn: 'uid={{id}}, o=example'
242+
};
243+
reconfigureServer({ auth: { ldap: options } }).then(() => {
244+
const authData = { authData: { id: 'testuser', password: 'secret' } };
245+
Parse.User.logInWith('ldap', authData).then((returnedUser) => {
246+
const query = new Parse.Query("User");
247+
query
248+
.equalTo('objectId', returnedUser.id).first({ useMasterKey: true })
249+
.then((user) => {
250+
expect(user.get('authData')).toEqual({ ldap:{ id: 'testuser' }});
251+
expect(user.get('authData').ldap.password).toBeUndefined();
252+
done();
253+
})
254+
.catch(done.fail)
255+
.finally(() => server.close())
256+
})
257+
});
258+
});
259+
});

Diff for: src/Adapters/Auth/ldap.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function validateAuthData(authData, options) {
2323

2424
return new Promise((resolve, reject) => {
2525
client.bind(userCn, authData.password, ldapError => {
26+
delete(authData.password);
2627
if (ldapError) {
2728
let error;
2829
switch (ldapError.code) {

0 commit comments

Comments
 (0)