Research details · Patched
- Product
- Google Cloud Apigee
- Affected versions
- v1-15-0-apigee-1
- Patch status
- Patched
- Bounty
- USD 11,250
- Reported
- May 1, 2025
- Series
- Cloud VRP bugSWAT 2025
Introduction
I found this bug while checking the Google recommendations for an earlier Apigee TLS issue. The recommendation was simple: configure <CommonName> on an outbound connection, and Apigee would reject a backend certificate issued for the wrong host. That sounded like a fairly uninteresting final line of defense. The certificate already had a structured subject, Java knew how to read it, and Apigee only needed to compare one name. Then I opened the implementation...
Apigee was not reading the Common Name from the certificate structure! It converted the entire subject to a string, split it on commas, and searched every resulting fragment for the characters CN=.
At that point I stopped thinking about certificates and started thinking about commas.
The protection came down to a list of strings
An Apigee proxy accepts a request and later opens a connection to a backend service. For an HTTPS backend, trusting the certificate chain does not prove that the certificate names the backend the proxy intended to reach. A certificate can be signed by a trusted internal CA and still belong to the wrong service.
The proxy author could add a name check to an HTTPTargetConnection:
<SSLInfo>
<Enabled>true</Enabled>
<CommonName>safe.host</CommonName>
</SSLInfo>Apigee documented <CommonName> as a comparison against the peer certificate's Common Name or DNS Subject Alternative Names. If the certificate named attacker.com while the proxy expected safe.host, the connection should fail.
The outer verification method walked the certificates from the TLS session and passed each X.509 certificate to verifyCommonNameOnCertificate(). That helper assembled the names Apigee was willing to accept:
boolean verifyCommonNameOnCertificate(
X509Certificate certificate, String expectedCN, boolean wildcard)
throws CertificateParsingException {
List<String> validNames = new ArrayList<>();
validNames.addAll(
CertUtil.getFields(certificate, CertUtil.FIELD_COMMON_NAME));
validNames.addAll(CertUtil.getDomainNamesFromSan(certificate));
for (String name : validNames) {
boolean matched = wildcard
? wildcardMatch(expectedCN, name)
: expectedCN.equals(name);
if (matched) {
return true;
}
}
return false;
}The final comparison was exactly what I expected. Apigee combined subject Common Names with DNS SANs and accepted the certificate if one entry matched. The interesting question had moved one layer down: what did CertUtil.getFields() put into validNames?
Then I saw the comma split
An X.509 subject is an X.500 distinguished name. Java exposes it as an X500Principal, preserving attributes such as CN and OU. Apigee immediately flattened that object with toString() and tried to rebuild the fields itself:
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;
}The code assumed that every comma separated two attributes. X.500 strings also allow commas inside quoted or escaped attribute values. StringTokenizer did not know the difference.
The substring search made the mistake exploitable. indexOf("CN=") did not ask whether the fragment was a Common Name attribute. It accepted any fragment that happened to contain those three characters.
I gave a certificate the real Common Name attacker.com and placed another name inside its Organizational Unit:
CN=attacker.com, OU="CN=safe.host,"Java rendered that subject as:
OU="CN=safe.host,", CN=attacker.comThe first comma was part of the quoted OU value. Apigee treated it as an attribute boundary and produced a fragment containing CN=safe.host. The following substring search extracted safe.host and added it to the same list as the certificate's real identity.
That was the primitive. The certificate still said CN=attacker.com; Apigee had invented a second Common Name from text stored under a different attribute.
A fake CN survived the real connection
I first tested the parser by itself. The same certificate went through Apigee's logic and an X.500-aware parser based on LdapName:
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": falseThat proved the parser disagreement, but I still wanted to see the value influence an outbound connection. I deployed a proxy whose <CommonName> was safe.host and pointed it at my HTTPS test server. Then I ran two certificates generated by the same script:
- A plain certificate with the wrong Common Name was rejected with
COMMON_NAME_MISMATCH. - The same wrong Common Name, with
CN=safe.host,added insideOU, was accepted. The request reached my server.
The first request mattered as much as the second. It showed that the protection was enabled and actually capable of stopping the connection. Changing the shape of one subject attribute flipped the decision without changing the certificate's real Common Name.
I reproduced this on Apigee runtime v1-15-0-apigee-1. The Google Cloud runtime performed an earlier Java-level identity check before it reached Apigee's own <CommonName> verifier, so my test certificate also carried the server's IP address in its SAN extension. That satisfied the earlier check honestly and let the request continue to the code I was testing.
The result therefore has a precise boundary: I demonstrated that Apigee extracted a false certificate identity and used it to approve the configured Common Name check. The forged OU did not independently bypass every TLS check in the Google Cloud runtime.
Edge was the reason I cared about this check
I had started here because of Apigee security bulletin GCP-2024-006. The bulletin addressed Apigee Edge installations where outbound hostname verification could be disabled by default. One recommended protection was the same <CommonName> setting I had just bypassed.
The vulnerable parser was present in the Edge-relevant code path I reviewed. Edge also appeared to rely on the configured check without the preliminary validation that complicated my Google Cloud test. A certificate carrying the injected subject could therefore reach the layer that was supposed to provide the missing identity protection.
I did not have an Apigee Edge deployment, so I could not perform the second live reproduction there. The Google Cloud experiment established the parser bug and its effect on Apigee's connection decision. The stronger Edge consequence came from static analysis of the shared path and the different runtime protection.
By the way, this was my thirtieth Apigee report. I expected that milestone to come from some tangled proxy chain. Instead, it came from StringTokenizer, indexOf(), and one comma in quotes.