Skip to content

fix: decode hex-escaped non-ASCII chars in LDAP bind DN#114

Merged
albanm merged 2 commits intomasterfrom
fix/ldap-bind-non-ascii-dn
Mar 31, 2026
Merged

fix: decode hex-escaped non-ASCII chars in LDAP bind DN#114
albanm merged 2 commits intomasterfrom
fix/ldap-bind-non-ascii-dn

Conversation

@aymericcousaert
Copy link
Copy Markdown
Collaborator

Summary

  • ldapjs v3's DN.toString() hex-escapes non-ASCII UTF-8 characters (e.g., é\c3\a9) per RFC 4514, but ber.writeString() in the bind request sends these as literal text instead of actual UTF-8 bytes
  • This causes InvalidCredentialsError on Active Directory for users with accented characters in their CN (e.g., Dié, Marie-Noelle)
  • Added unescapeNonAsciiInDn() utility that decodes hex sequences back to UTF-8 and re-escapes only DN-special chars

Files changed

  • api/src/utils/dn.ts — new utility function (15 lines)
  • api/src/storages/ldap.ts — import + one-line fix in checkPassword
  • test-it/unescape-dn.ts — 4 unit tests + 1 integration test with bind spy (proves the DN encoding issue and that the fix resolves it)

Test plan

  • Unit tests prove \c3\a9é and DN-special chars are re-escaped
  • Integration test spies on client.bind() and asserts the DN contains raw é, not hex-escaped \c3\a9
  • Test fails without the fix, passes with it
  • Full test suite passes (84/84)
  • Deploy and ask client (Marie-Noelle Dié) to retry login

ldapjs v3's DN.toString() hex-escapes non-ASCII UTF-8 characters
(e.g., é → \c3\a9) per RFC 4514. However, ber.writeString() in the
bind request sends these as literal text, not actual UTF-8 bytes.
This causes DN mismatches on Active Directory for users with accented
characters in their CN (e.g., Dié, Marie-Noelle).
@github-actions github-actions bot added the fix label Mar 31, 2026
@albanm albanm merged commit 069cf3a into master Mar 31, 2026
2 checks passed
@albanm albanm deleted the fix/ldap-bind-non-ascii-dn branch March 31, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants