Skip to content

ldap: decode escaped filter values as octets instead of code points - #2358

Merged
alexisbalbachan merged 1 commit into
fortra:masterfrom
RaphaelFakhri:fix-ldap-filter-escaped-octets
Nov 25, 2026
Merged

alexisbalbachan merged 1 commit into
fortra:masterfrom
RaphaelFakhri:fix-ldap-filter-escaped-octets

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

RFC 4515 defines each \XX escape in a search filter value as one octet. LDAPConnection._processLdapString() converts each escape to chr(0xXX) instead. Since AssertionValue became UTF-8 encoded in #1980, every escaped byte of 0x80 or higher goes out as two bytes. Filters such as (objectGUID=\a1\00\ff) send c2 a1 00 c3 bf instead of a1 00 ff and match nothing. UTF-8 escapes such as (cn=Jos\c3\a9) are double-encoded the same way.

Changes

  • _processLdapString() now returns bytes: each \XX escape becomes a single octet and the text around it is UTF-8 encoded. Equality, approximate, ordering, substring and extensible match values all go through this function.
  • Unescaped non-ASCII values such as (cn=José) keep their current UTF-8 encoding, and escapes below 0x80 (\28, \29, \2a, \00) produce the same bytes as before.
  • Adds tests/misc/test_ldap_filter.py with tests for escaped binary, escaped UTF-8, unescaped UTF-8, substring and extensible match values.

Testing

python -m pytest -q tests/misc/test_ldap_filter.py
  • Without the fix: 4 failed, 1 passed.
  • With the fix: 5 passed.
  • python -m pytest -q tests/misc: 348 passed, 1 skipped.

Fixes #2357

@alexisbalbachan

Copy link
Copy Markdown
Collaborator

Hi, everything looks ok, i'm merging this PR, thank you

@alexisbalbachan
alexisbalbachan merged commit 7aa3770 into fortra:master Nov 25, 2026
8 checks passed
@alexisbalbachan alexisbalbachan removed the in review This issue or pull request is being analyzed label Nov 25, 2026
@anadrianmanrique anadrianmanrique added the bug Unexpected problem or unintended behavior label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LDAP search filters with escaped bytes of 0x80 or higher send the wrong value

3 participants