Escape functions for LDAP filters and distinguished names to prevent LDAP injection attacks.
Template literal tag functions for LDAP filters and distinguished names to prevent LDAP injection attacks.
Uses the escape codes from Active Directory: Characters to Escape.
npm install --save ldap-escape
Character | Escape |
---|---|
* |
\2A |
( |
\28 |
) |
\29 |
\ |
\5C |
NUL |
\00 |
Character | Escape |
---|---|
, |
\, |
\ |
\\ |
# |
\# |
+ |
\+ |
< |
\< |
> |
\> |
; |
\; |
" |
\" |
= |
\= |
SPC (leading or trailing) |
\ |
Escapes input for use as an LDAP filter.
Escapes input for use as an LDAP distinguished name.
"use strict";
const ldapEscape = require('ldap-escape');
const uid = 1337;
console.log(ldapEscape.filter`uid=${uid}`); // -> 'uid=1337'
"use strict";
const ldapEscape = require('ldap-escape');
const cn = 'alice';
console.log(ldapEscape.dn`cn=${cn},dc=test`); // -> 'cn=alice,dc=test'
npm test
See LICENSE.md