# The CN That Wasn't a CN

Apigee flattened X.509 subjects to comma-split strings, so a CN= marker inside a quoted OU spoofed the configured CommonName check and approved a wrong-host backend certificate.

- Payout: $11,250
- Severity: high
- Program: Google
- Found by: Nikita Markevich
- Disclosed: 2026-11-16
- Write-up quality: 8/10
- Original: https://bugs.exposed/posts/apigee-common-name-subject-injection
- Library page: https://bugbountylibrary.com/r/blog%3Abugs-exposed-posts-apigee-common-name-subject-injection
- Tags: area:cloud domain:cloud impact:internal-access kind:bounty platform:blog sev:high tech:java technique:parser-differential technique:source-review vuln:auth-bypass vuln:misconfiguration

**Target:** Apigee proxy outbound HTTPTargetConnection TLS <CommonName> verification
**Root cause:** CertUtil.getFields() stringifies X500Principal and splits on every comma with StringTokenizer, then uses indexOf("CN=") on each fragment, so commas inside quoted/escaped attribute values create fake attribute boundaries and any fragment containing CN= is treated as a Common Name.
**Steps:**
1. Configure an Apigee TargetEndpoint SSLInfo with `<CommonName>safe.host</CommonName>` and point it at an attacker HTTPS server.
2. Issue a certificate with real subject `CN=attacker.com, OU="CN=safe.host,"`; Java renders it as `OU="CN=safe.host,", CN=attacker.com`.
3. Apigee's getFields() splits on the comma inside the quoted OU, yielding a fragment containing `CN=safe.host`, and extracts `safe.host` into validNames.
4. verifyCommonNameOnCertificate() matches expectedCN `safe.host` against the injected name and returns true.
5. Control: a plain wrong-CN certificate is rejected with COMMON_NAME_MISMATCH; the OU-injected one is accepted and the request reaches the attacker server.
6. On Google Cloud runtime, also include the server IP in the SAN to satisfy the earlier Java-level identity check.
**How found:** While reviewing Google's recommendation to set <CommonName> after an earlier Apigee TLS issue, the author read the implementation and saw it stringified the X500Principal and split on commas instead of reading structured attributes — then focused on commas inside quoted values.
**Exploitation:** Attacker with a certificate from a trusted CA (or internal CA) for attacker.com crafts a subject with a quoted OU containing `CN=<expected host>,`; the proxy's <CommonName> check approves the connection and the proxy sends backend traffic to the attacker's server, enabling interception of proxied requests/responses.
**Escalation:** On Apigee Edge, where outbound hostname verification could be disabled by default (GCP-2024-006), the same parser bug reaches the layer meant to compensate, per static analysis; not live-reproduced on Edge.
**Insight:** When a security check re-parses a structured identifier (DN, SAN, path) by string-splitting, look for quoting/escaping characters that let you smuggle a second attribute value; validate the parser against an X.500-aware parser like LdapName and confirm the differential flips a real accept/reject decision.

## Proof of concept (copied exactly from the original report)

**Certificate subject with CN injected inside quoted OU**

```
CN=attacker.com, OU="CN=safe.host,"

Java rendered that subject as:

 text Copy code

OU="CN=safe.host,", CN=attacker.com
```

**Vulnerable getFields comma-split parser code**

```
public static List<String> getFields(
 X509Certificate certificate, String fieldWithEqual) {
 List<String> names = new LinkedList<>();
 String subject = certificate.getSubjectX500Principal().toString();
 StringTokenizer tokens = new StringTokenizer(subject, ",");

 while (tokens.hasMoreTokens()) {
 String token = tokens.nextToken();
 int offset = token.indexOf(fieldWithEqual);
 if (offset != -1) {
 names.add(token.substring(
 offset + fieldWithEqual.length()).trim());
 }
 }
 return names;
}
```

**Parser comparison showing false CN extraction**

```
Raw subject: OU="CN=safe.host,", CN=attacker.com
Extracted CNs (Apigee logic): [safe.host, attacker.com]
Extracted CNs (structured parser): [attacker.com]

Apigee-style match against "safe.host": true
Structured match against "safe.host": false
```

