Summary
A certificate hostname-validation flaw in PJSIP's OpenSSL and GnuTLS TLS backends can accept a trusted certificate whose DNS SubjectAltName contains an embedded NUL byte. When server verification is enabled, an attacker who can intercept traffic and obtain such a certificate may impersonate the SIP server and capture REGISTER credentials.
Affected context
The issue occurs in PJSIP 2.17 and earlier when the OpenSSL or GnuTLS backend is used for TLS or SIPS transport and server verification is enabled through --tls-verify-server. It depends on certificate hostname matching involving a DNS SubjectAltName containing an embedded NUL byte; the mbedTLS backend is not affected because it preserves the certificate-provided string length.
Exploit preconditions
- Attack surface: PJSIP TLS/SIPS connections using the OpenSSL or GnuTLS backend
- Required access: Ability to intercept or redirect the client-to-server connection, plus possession of a specially formed certificate issued by a trusted certificate authority
- Trigger point: Server certificate validation during TLS session establishment
- Why exploitation is possible: String-based hostname processing recalculates length and truncates at an embedded NUL, allowing a certificate suffix to be ignored during comparison
Why this happens
The vulnerability results from treating explicitly length-delimited certificate data as a conventional NUL-terminated string. In the affected backends, DNS SubjectAltName values are copied with string functions that stop at an embedded NUL, so hostname validation may compare only a trusted-looking prefix rather than the complete value. This maps primarily to CWE-295: Improper Certificate Validation and is also related to CWE-297: Improper Validation of Certificate with Host Mismatch.
Potential impact
- An attacker could impersonate a trusted SIP server.
- SIP clients may establish sessions with an unauthorized endpoint.
- REGISTER credentials could be disclosed to the impersonating server.
- Signaling confidentiality and call-control integrity could be weakened.
- An attacker could potentially redirect or manipulate SIP traffic.
General mitigation guidance
Mitigation generally focuses on preserving certificate-provided lengths throughout parsing and hostname comparison, and on rejecting malformed or ambiguous DNS SubjectAltName values.
Common defensive patterns include:
- Using certificate-validation routines that perform length-aware comparisons.
- Rejecting embedded NUL characters and other malformed hostname representations.
- Ensuring hostname verification remains enabled for TLS/SIPS connections.
- Favoring a backend with correct length-preserving certificate handling where operationally appropriate.
- Limiting SIP account privileges and credential scope to reduce the impact of server impersonation.
- Protecting signaling paths with network controls that reduce interception and redirection opportunities.
How teams detect issues like this
Organizations can look for this weakness through:
- Static analysis of certificate parsing and hostname-comparison code for NUL-terminated string APIs used with length-delimited fields.
- Code review checks covering SAN parsing, canonicalization, embedded NUL handling, and hostname matching.
- Negative test certificates containing embedded NUL bytes, mismatched suffixes, and alternate SAN encodings.
- Dependency and configuration inventories identifying TLS/SIPS deployments that use the affected backends with server verification enabled.
- Policy enforcement requiring complete, length-aware certificate validation and rejecting malformed identity fields.
- Neutral automated security-review tools that flag unsafe string handling in certificate-validation paths.

