libcurl LDAP LDIF: entry DN and attribute names written without RFC 2849 base64 encoding, allowing server line injection
libcurl writes the LDAP entry DN and attribute names into its LDIF output without the RFC 2849 base64 encoding that it applies to attribute values. A hostile or man-in-the-middle LDAP server can therefore place a CR/LF in a DN or attribute name and inject extra lines into the LDIF that curl prints.
- Disclosed after 3 days
Summary:
curl 8.22.0 base64-encodes LDAP attribute values that aren't RFC 2849 SAFE-STRINGs (commit 2ba2fe3540, issue #22339), but the entry DN and the attribute names are still written to the LDIF output verbatim. In lib/openldap.c oldap_recv() that's the DN client_write(data, STRCONST("DN: "), bv.bv_val, bv.bv_len, STRCONST("\n")) call and the attribute-name client_write() right after it, neither of which goes through the SAFE-STRING check that values do; lib/ldap.c (WinLDAP/generic backend) has the same pattern in show_vals() and its DN write. So a hostile or MITM LDAP server that puts a CR/LF in a returned DN or attribute name injects its own lines into the LDIF curl prints. RFC 2849 says a DN that isn't a SAFE-STRING must use the dn:: base64 form, and a valid attribute description can't contain a control byte at all, so this is the DN/name counterpart of the value-only fix in #22339. I have a small patch (base64 the DN when it's non-SAFE, reject a control byte in an attribute name) tested on the OpenLDAP backend and can open a PR. AI disclosure: AI assistance was used to help find this and draft the report; I built curl, wrote and ran the mock-server PoC, and applied and tested the fix myself.
Affected version
curl 8.22.0 and current master. Reproduced on Linux with the OpenLDAP backend (lib/openldap.c). Paste your own curl -V when you file.
Steps To Reproduce:
A real directory server won't store a CR/LF in a DN, so the PoC is a small mock LDAP server (attached: mock_ldap.py) that answers an anonymous bind and returns one crafted entry.
- python3 mock_ldap.py 3899 dn # DN = cn=victim,dc=example,dc=com<LF>injected-by-server: OWNED
- curl -s "ldap://127.0.0.1:3899/dc=example,dc=com?cn?sub?(cn=*)" | cat -A
- Output puts injected-by-server: OWNED on its own LDIF line (the server authored it, not curl) and curl exits 0 with no warning.
Attribute-name variant: python3 mock_ldap.py 3900 attr. Control: a clean DN prints a single well-formed DN: line with no injected line.
Impact
A caller that points curl at an untrusted or MITM'd LDAP server and then consumes curl's LDIF output gets lines the server authored rather than curl. If that LDIF is piped into an LDIF processor such as ldapmodify, the server can smuggle in add/modify/delete directives it was never asked for; if it's shown in a terminal it's raw control-byte / escape output. The precondition is that the user aimed curl at the malicious server and further processes the output, so I'd rate this Low, but I'll defer the grade to you.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The DN and attribute names are written to the LDIF output verbatim, bypassing the RFC 2849 SAFE-STRING check that was added for attribute values.
Impact
A user who points curl at an untrusted or intercepted LDAP server and then processes the LDIF output could receive server-authored lines, which may smuggle add, modify or delete directives into an LDIF processor or produce raw control-byte output in a terminal; the report rates this Low because the user must aim curl at the malicious server and further process the output.
What the attacker needed
User points curl at a hostile or MITM'd LDAP server; user further processes curl's LDIF output
The fix
The DN should be base64-encoded when it is not a SAFE-STRING and an attribute name containing a control byte should be rejected; the report offers a patch but does not say it was merged.
How it was found
- Start the mock LDAP server with a crafted DN containing a line feed.
- Run curl against the mock server and pipe the output through cat -A.
- Observe that the injected line appears on its own LDIF line and curl exits successfully.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When curl talks to an LDAP directory server, it can print the results in a text format called LDIF. Some parts of that text are supposed to be encoded so they cannot contain line breaks, but curl only did that for the values, not for the entry name or the field names. A malicious server can put a line break in those parts and add fake lines to what curl prints.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.