Skip to content

Commit 11d0814

Browse files
authored
Merge pull request #97 from pafik13/master
feat(ldapauth): sanitize input for group search filter
2 parents 6c5f777 + 98955a7 commit 11d0814

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

lib/ldapauth.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ var getOption = function(obj, keys) {
5252
return undefined;
5353
};
5454

55+
/**
56+
* Sanitize LDAP special characters from input
57+
*
58+
* {@link https://tools.ietf.org/search/rfc4515#section-3}
59+
*
60+
* @private
61+
* @param {string} input - String to sanitize
62+
* @returns {string} Sanitized string
63+
*/
64+
var sanitizeInput = function(input) {
65+
return input
66+
.replace(/\*/g, '\\2a')
67+
.replace(/\(/g, '\\28')
68+
.replace(/\)/g, '\\29')
69+
.replace(/\\/g, '\\5c')
70+
.replace(/\0/g, '\\00')
71+
.replace(/\//g, '\\2f');
72+
};
73+
5574
/**
5675
* Create an LDAP auth class. Primary usage is the `.authenticate` method.
5776
*
@@ -139,8 +158,8 @@ function LdapAuth(opts) {
139158
var groupSearchFilter = opts.groupSearchFilter;
140159
opts.groupSearchFilter = function(user) {
141160
return groupSearchFilter
142-
.replace(/{{dn}}/g, user[opts.groupDnProperty])
143-
.replace(/{{username}}/g, user.uid);
161+
.replace(/{{dn}}/g, sanitizeInput(user[opts.groupDnProperty] || ''))
162+
.replace(/{{username}}/g, sanitizeInput(user.uid || ''));
144163
};
145164
}
146165

@@ -284,25 +303,6 @@ LdapAuth.prototype._search = function(searchBase, options, callback) {
284303
});
285304
};
286305

287-
/**
288-
* Sanitize LDAP special characters from input
289-
*
290-
* {@link https://tools.ietf.org/search/rfc4515#section-3}
291-
*
292-
* @private
293-
* @param {string} input - String to sanitize
294-
* @returns {string} Sanitized string
295-
*/
296-
var sanitizeInput = function(input) {
297-
return input
298-
.replace(/\*/g, '\\2a')
299-
.replace(/\(/g, '\\28')
300-
.replace(/\)/g, '\\29')
301-
.replace(/\\/g, '\\5c')
302-
.replace(/\0/g, '\\00')
303-
.replace(/\//g, '\\2f');
304-
};
305-
306306
/**
307307
* Find the user record for the given username.
308308
*

0 commit comments

Comments
 (0)