Skip to content
SSRF Write-up Advanced

CVE-2022-21496: Improper Implementation of the LDAP URI Specification Allowing for Host Validation Bypasses

Java's LDAP URL parser accepts a hash character inside the host part of a URI, which the URI specification forbids. An attacker could craft a URL that passes a host allow-list check but causes a DNS lookup or LDAP connection to a server they control.

amlw.dev

Published on amlw.dev

Advisory: https://www.oracle.com/security-alerts/cpuapr2022.html

The author, on amlw.dev

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the LDAP URI parser failed to reject characters such as '#' in the host component, so it accepted a host string that the generic URI parser would treat differently.

Impact

Depending on the DNS resolver, this could cause an unknown-host error, a DNS lookup to an attacker-controlled domain enabling data exfiltration, or a remote LDAP call to an attacker server that could lead to remote code execution; the authors note this was observed on macOS and Alpine Linux.

What the attacker needed

Application validates LDAP URLs with a host allow-list; attacker can supply the LDAP URL; affected DNS resolver behaviour

The fix

The LDAP URI parser should be made compliant with the specification so that such URIs raise a syntax exception.

How it was found

  1. Create an LDAP URL whose host contains a hash character followed by another host name.
  2. Parse it with the LDAP URL class and observe that the host and port are extracted as separate values.
  3. Pass the same URL through a host allow-list check using the generic URI class, which rejects it.
  4. Supply the URL to a JNDI LDAP context and observe that a connection is attempted to the attacker-controlled host.

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 write-up has not been written yet. The Original tab links to the source.

A program sometimes checks a web address to make sure it only talks to a trusted server. Java's LDAP address reader accepted a malformed address containing a hash symbol, so the check saw one host while the actual connection went somewhere else. That let an attacker redirect the connection to their own machine.

What is SSRF?

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.