Skip to content

ldapasn1: fix recursive Filter schema so composite search filters decode - #2373

Closed
hakarrr wants to merge 2 commits into
fortra:masterfrom
hakarrr:fix-ldap-composite-filter-decode
Closed

hakarrr wants to merge 2 commits into
fortra:masterfrom
hakarrr:fix-ldap-composite-filter-decode

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 13, 2026

Copy link
Copy Markdown

Summary

Fixes #273.

Composite LDAP search filters (and/or/not) fail BER decoding: the
recursive Filter() references embedded in the composite alternatives are
created while Filter.componentType is still the empty univ.Choice
class default, so pyasn1 snapshots an empty componentType into instance
state at creation time and clone() restores that empty snapshot from the
read-only initializers. Every composite member therefore decodes against
an empty schema.

Two additive changes, both required:

  • Filter.clone() clones against the final class-level
    Filter.componentType (object side: clone() re-applies the snapshot
    stored in the read-only initializers).
  • The three embedded Filter() instances' instance state is repaired
    after the assignment (spec side: the BER decoder performs tag dispatch
    on the embedded spec's tag map before cloning it). The read-only
    initializers are deliberately left untouched: storing the recursive
    reference there creates a cyclic object graph that breaks repr() and
    NamedTypes tag-map computation at import time.

Tests

New network-free regression tests in tests/misc/test_ldap_filter.py
(7 tests): the issue's exact wire samples (plain equalityMatch control
plus the failing composite request), byte-identical re-encode of the
issue's composite request, production _parseFilter composite
round-trips, deeply nested composites, every leaf alternative, and clone
invariants.

Verified with pyasn1 0.4.8 and 0.6.5:

  • On master, 5 of the 7 new tests fail; the 2 that pass are the
    non-composite controls. With the fix, all 7 pass.
  • tests/misc under unittest discovery: 357 tests with one pre-existing
    Windows-only DPAPI error before; 364 (357 + 7 new) with the same single
    pre-existing error after. No existing test outcome changed.
  • Encoding of non-composite filters is unchanged (byte-identical
    re-encode of the issue's plain equalityMatch request).

hakarrr and others added 2 commits November 13, 2026 15:44
Composite (and/or/not) LDAP search filters fail BER decoding: the recursive Filter() references embedded in the composite alternatives are created while Filter.componentType is still the empty univ.Choice class default, so pyasn1 snapshots an empty componentType into instance state at creation time and clone() restores that empty snapshot from the read-only initializers.

Override Filter.clone() to clone against the final class definition (object side), and repair the frozen creation-time snapshots on the three embedded Filter instances (spec side: the BER decoder performs tag dispatch on the embedded spec's tagMap before cloning it).

Fixes #273

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Covers the issue #273 wire samples (plain equalityMatch control and the failing composite), byte-identical re-encode, production _parseFilter composite round-trips, deeply nested composites, all leaf alternatives, and clone invariants.

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr

hakarrr commented Nov 13, 2026

Copy link
Copy Markdown
Author

Could a maintainer review this recursive LDAP Filter schema fix for composite search filters? Please let me know if the decoding approach needs changing or if additional cases are needed before review. Thanks.

@hakarrr

hakarrr commented Nov 16, 2026

Copy link
Copy Markdown
Author

Following up once more on this one. Could a maintainer take a look when time allows, or let me know what the next step should be? Happy to make any changes needed. Thank you.

@NeffIsBack

Copy link
Copy Markdown
Contributor

Following up once more on this one. Could a maintainer take a look when time allows, or let me know what the next step should be? Happy to make any changes needed. Thank you.

To be clear, I am not a maintainer of this repo, but usually this is the natural next step when a PR is opened. No need to ping everyone on each and every PR multiple times.

@hakarrr hakarrr closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LDAP SearchRequest parser cannot parse filters using openldap format timestamps

2 participants