Skip to content

Commit

Permalink
Sanitize username input to prevent LDAP DoS attack
Browse files Browse the repository at this point in the history
  • Loading branch information
nebulade committed Aug 16, 2020
1 parent 1bd500e commit 060805d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ try {
// start with empty token store
}

// https://tools.ietf.org/search/rfc4515#section-3
var sanitizeInput = function (username) {
return username
.replace(/\*/g, '\\2a')
.replace(/\(/g, '\\28')
.replace(/\)/g, '\\29')
.replace(/\\/g, '\\5c')
.replace(/\0/g, '\\00')
.replace(/\//g, '\\2f');
};

function verifyUser(username, password, callback) {
username = sanitizeInput(username);

if (AUTH_METHOD === 'ldap') {
var ldapClient = ldapjs.createClient({ url: process.env.CLOUDRON_LDAP_URL });
ldapClient.on('error', function (error) {
Expand Down

0 comments on commit 060805d

Please sign in to comment.