Skip to content

LDAP SearchRequest parser cannot parse filters using openldap format timestamps #273

Open

Description

@alexmadon

To reproduce run the script:


#!/usr/bin/python3
"""
LDAP SearchRequest

works for filter
(objectclass=groupOfNames)

fails for filter
(&(objectclass=groupOfNames)(!(modifyTimestamp<=20150302092004Z)))

"""
import ldapasn1 as ldap

requests=[
b'0z\x02\x01\x03cu\x04\x1bou=groups,DC=example,DC=foo\n\x01\x02\n\x01\x03\x02\x01\x00\x02\x01\x00\x01\x01\x00\xa3\x1b\x04\x0bobjectclass\x04\x0cgroupOfNames0*\x04\x02cn\x04\x0bdescription\x04\x06member\x04\x0fmodifyTimestamp',
b'0\x81\xa3\x02\x01\x02c\x81\x9d\x04\x1bou=groups,DC=example,DC=foo\n\x01\x02\n\x01\x03\x02\x01\x00\x02\x01\x00\x01\x01\x00\xa0C\xa3\x1b\x04\x0bobjectclass\x04\x0cgroupOfNames\xa2$\xa6"\x04\x0fmodifyTimestamp\x04\x0f20150302092004Z0*\x04\x02cn\x04\x0bdescription\x04\x06member\x04\x0fmodifyTimestamp'

]

for request in requests:
ldapMessage, _ = ldap.decoder.decode(request, asn1Spec=ldap.LDAPMessage())
print(ldapMessage.prettyPrint())


It will fails on the 2nd request:

./bug1.py
LDAPMessage:
messageID=3
protocolOp=Choice:
searchRequest=SearchRequest:
baseObject=b'ou=groups,DC=example,DC=foo'
scope='wholeSubtree'
derefAliases='derefAlways'
sizeLimit=0
timeLimit=0
typesOnly='False'
filter=Filter:
equalityMatch=AttributeValueAssertion:
attributeDesc=b'objectclass'
assertionValue=b'groupOfNames'

attributes=AttributeSelection:
b'cn' b'description' b'member' b'modifyTimestamp'

Traceback (most recent call last):
File "./bug1.py", line 27, in
ldapMessage, _ = ldap.decoder.decode(request, asn1Spec=ldap.LDAPMessage())
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 825, in call
stGetValueDecoder, self, substrateFun
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 342, in valueDecoder
component, head = decodeFun(head, asn1Spec)
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 825, in call
stGetValueDecoder, self, substrateFun
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 445, in valueDecoder
head, r.getComponentTagMap(), tagSet, length, state
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 825, in call
stGetValueDecoder, self, substrateFun
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 342, in valueDecoder
component, head = decodeFun(head, asn1Spec)
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 825, in call
stGetValueDecoder, self, substrateFun
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 445, in valueDecoder
head, r.getComponentTagMap(), tagSet, length, state
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 825, in call
stGetValueDecoder, self, substrateFun
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 388, in valueDecoder
component, head = decodeFun(head, asn1Spec)
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 773, in call
tagSet in __chosenSpec.getTagMap()
TypeError: argument of type 'NoneType' is not iterable

Activity

  1. hakarrr commented on Nov 13, 2026

    @hakarrr

    This is still broken on current master - the recursive Filter schema never decodes composite (and/or/not) filters because the embedded recursive references snapshot an empty componentType at creation time.

    I've submitted PR #2373 with a fix plus network-free regression tests built on the exact wire samples from this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions