Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
server: prevent crash on blank DN bind
Browse files Browse the repository at this point in the history
req.dn used to be parsed, now it's a string. This causes the server to crash because the assertion error cannot be trapped

Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Nov 28, 2023
1 parent 6ceef13 commit 3a862d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,11 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req) {
}

// Otherwise, match via DN rules
assert.ok(req.dn)
const keys = this._sortedRouteKeys()
let fallbackHandler = [noSuffixHandler]
// invalid DNs in non-strict mode are routed to the default handler
const testDN = (typeof (req.dn) === 'string') ? DN.fromString(req.dn) : req.dn
assert.ok(testDN)

for (let i = 0; i < keys.length; i++) {
const suffix = keys[i]
Expand Down
13 changes: 12 additions & 1 deletion test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,18 @@ tap.test('bind/unbind identity anonymous', function (t) {
client.unbind(function (err) {
t.error(err, 'client anon unbind error')
t.ok(anonDN.equals(c.ldap.bindDN), 'anon unbind dn is correct')
server.close(() => t.end())

// blank bind dn but non-blank password
const client2 = ldap.createClient({ socketPath: t.context.sock })
client2.bind('', 'pw', function (err) {
t.error(err, 'client anon bind with credentials error')
t.ok(anonDN.equals(c.ldap.bindDN), 'anon bind with credentials dn is correct')
client2.unbind(function (err) {
t.error(err, 'client anon with credentials unbind error')
t.ok(anonDN.equals(c.ldap.bindDN), 'anon unbind with credentials dn is correct')
server.close(() => t.end())
})
})
})
})
})
Expand Down

0 comments on commit 3a862d7

Please sign in to comment.