Summary
Erlang/OTP's public_key certificate handling implements TLS hostname verification in a way that allows DNS nameConstraints on an intermediate CA to be bypassed using a Common Name–only leaf certificate.
By omitting subjectAltName DNS entries and relying on Common Name fallback, a constrained subordinate CA can issue certificates that OTP TLS clients may accept for hostnames outside the permitted DNS subtree.
Affected context
The issue arises in Erlang/OTP systems that use the ssl application with peer verification enabled and rely on the public_key library for X.509 path validation and hostname checking.
It specifically impacts TLS client scenarios where:
- The remote endpoint presents a certificate chain anchored in a trusted CA store
- An intermediate CA is restricted with DNS nameConstraints
- Hostname verification is performed using public_key:pkix_verify_hostname/3 or the standard strict HTTPS matcher
In these contexts, a CN-only leaf certificate can be accepted as a valid identity for a hostname that should be outside the constrained DNS namespace.
Exploit preconditions
- Attack surface: TLS client connections in Erlang/OTP using ssl:connect/3 (or similar) with verify_peer enabled and hostname verification based on public_key:pkix_verify_hostname/3.
- Required attacker capability: Ability to obtain or control issuance from a subordinate CA that is constrained by DNS nameConstraints but is otherwise trusted by the client's CA store. This may stem from CA mis-issuance, compromise, or malicious operation of a constrained CA.
- Certificate characteristics: The attacker can issue a leaf certificate:
- Chained to a DNS-constrained intermediate (e.g., permitted;DNS:allowed.example.com)
- With no subjectAltName DNS entries
- With a subject Common Name set to an out-of-scope target hostname (e.g., victim.example.com).
- Trigger point: When the Erlang/OTP TLS client performs:
- Path validation via pubkey_cert:validate_names/6 (nameConstraints check only SAN DNS entries)
- Hostname verification via public_key:pkix_verify_hostname/3, which falls back to the subject CN.
- Why exploitation is possible:
- DNS nameConstraints are only applied to SAN DNS names; a certificate with no SAN is treated as unconstrained.
- Hostname verification still accepts the CN as a presented identity, even under strict HTTPS match mode.
- Combined, these behaviors allow a constrained CA to effectively mint certificates for arbitrary external hostnames that OTP clients will treat as valid.
Why this happens
The vulnerability is rooted in two interacting certificate validation behaviors:
- Partial enforcement of DNS nameConstraints: The function pubkey_cert:validate_names/6 only evaluates DNS nameConstraints against DNS-typed entries in the subjectAltName extension. In practice this means:
- If a leaf certificate contains SAN DNS names, they are correctly constrained by permitted/excluded DNS subtrees.
- If a leaf certificate omits SAN entirely, the DNS nameConstraints logic is not triggered at all, even though the certificate is issued by a constrained intermediate CA.
This reflects an incomplete implementation of RFC 5280 semantics and maps to CWE-297: Improper Validation of Certificate with Host Mismatch, because constraints intended to restrict namespace delegation do not fully apply.
- Common Name fallback for hostname verification: The function public_key:pkix_verify_hostname/3, including the strict pkix_verify_hostname_match_fun(https) mode, falls back to extracting id-at-commonName attributes from the subject distinguished name when no subjectAltName is present. It then matches the reference hostname against the CN value.
This CN fallback undermines the intended role of SAN as the canonical place for DNS identities and leads to CWE-295: Improper Certificate Validation, because the client accepts an identity source (CN) that bypasses the DNS nameConstraints enforcement.
Taken together, these design choices create an abstract bug pattern where:
- Namespace constraints are only applied to one identity channel (SAN DNS), while
- Hostname matching still trusts an alternate channel (CN) that is not constrained.
This discrepancy between constraint enforcement and identity selection enables identity spoofing within TLS, despite apparently correct use of strict verification APIs.
Potential impact
- An attacker controlling or abusing a constrained subordinate CA could have their certificates accepted for hostnames outside the permitted DNS subtree.
- Erlang/OTP TLS clients may establish seemingly secure HTTPS or TLS connections to an attacker-controlled endpoint, believing it to be the legitimate target host.
- Confidential data in transit (credentials, session tokens, API keys) could be intercepted or modified by a man-in-the-middle attacker.
- Service-to-service authentication relying on certificate-based identity could be bypassed, enabling lateral movement or impersonation of internal services.
- Security assumptions around "restricted" or partitioned PKI hierarchies may be invalidated, weakening zero-trust or micro-segmentation designs that rely on strict nameConstraints.
General mitigation guidance
Mitigations focus on aligning hostname verification with modern PKI best practices and ensuring that namespace constraints apply consistently to all identity sources:
- Prefer SAN-based identity exclusively: Treat subjectAltName as the only authoritative source of DNS identities. Avoid CN fallback in hostname validation logic and ensure verification routines reject CN-only certificates by default for DNS hostnames.
- Harden nameConstraints enforcement: Ensure that DNS nameConstraints semantics are applied in a way that prevents constrained intermediates from issuing usable certificates without properly constrained identities. This may include:
- Treating CN DNS names as subject to DNS constraints if they are ever used.
- Or better, rejecting certificates that lack SAN when constraints are present and DNS-based identities are expected.
- Adopt stricter hostname verification policies: Where possible, configure or wrap TLS stacks so that:
- Only SAN DNS names are considered for hostname verification.
- CN is ignored for DNS-name matching, especially when strict verification is requested.
- Reduce trust in broadly or loosely constrained CAs: Architect systems so that:
- Critical services rely on private or dedicated CAs with narrowly scoped trust.
- Constrained intermediates are not relied upon as the sole mechanism for segregating namespaces.
- Defense-in-depth at the application layer: Complement TLS-level checks with:
- Explicit verification that the certificate's SAN matches expected host or service names.
- Additional authorization checks (e.g., service identity claims, mTLS SPIFFE IDs, or application-level tokens) before granting access.
How teams detect issues like this
Detection efforts can aim both at code-level patterns and at operational certificate usage:
- Static analysis and code review:
- Identify all uses of public_key:pkix_verify_hostname/3 and ssl:connect/3 with verify_peer, and check how hostname verification is configured.
- Flag any logic that falls back to subject Common Name for DNS hostname matching, especially in "strict" modes.
- Review implementations of certificate path validation and nameConstraints handling (e.g., pubkey_cert:validate_names/6) to ensure that constraints are consistently applied to all identity sources.
- Policy and configuration checks:
- Enforce secure TLS configurations through centralized policy (e.g., internal guidelines or linters) that mandate SAN-only verification for DNS names.
- Use CI/CD checks or code owners to review changes to TLS configuration or PKI validation logic.
- Runtime monitoring and PKI hygiene:
- Periodically scan issued certificates (both internal and external) to detect:
- CN-only certificates used in production.
- Certificates issued by constrained intermediates with CN values outside the permitted DNS subtree.
- Monitor TLS traffic metadata (e.g., via TLS inspection in controlled environments or connection logs) to identify sessions where CN-only certificates are accepted.
- Automated tooling:
- Leverage PKI linting tools and certificate analyzers to detect non-compliant certificates and misapplied nameConstraints.
- Integrate security scanners or SAST tools (where available) that know about CN fallback and improper certificate validation patterns.

