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

server: prevent crash on blank DN bind #958

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 21 additions & 0 deletions test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,27 @@ tap.test('bind/unbind identity anonymous', function (t) {
})
})

tap.test('does not crash on empty DN values', function (t) {
const server = ldap.createServer({
connectionRouter: function (c) {
server.newConnection(c)
server.emit('testconnection', c)
}
})

server.listen(t.context.sock, function () {
const client = ldap.createClient({ socketPath: t.context.sock })
server.once('testconnection', () => {
client.bind('', 'pw', function (err) {
t.ok(err, 'blank bind dn throws error')
client.unbind(function () {
server.close(() => t.end())
})
})
})
})
})

tap.test('bind/unbind identity user', function (t) {
const server = ldap.createServer({
connectionRouter: function (c) {
Expand Down