Skip to content

TLS certificate identity check is skipped when the peer is addressed by IP literal: any CA-issued cert is accepted and reported as verified

High
sreimers published GHSA-7h33-mhw5-7pwr Sep 30, 2026

Package

libre baresip/re (C)

Affected versions

>= 2.0.0, <= 4.11.0

Patched versions

4.12.0

Description

Summary

src/tls/openssl/tls.c, tls_set_verify_server():

if (sa_set_str(&sa, host, 0)) {          /* sa_set_str returns 0 on SUCCESS, so this branch is
                                            taken ONLY when host is NOT parseable as an address */
        SSL_set_hostflags(tc->ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
        SSL_set1_host(tc->ssl, host);            /* identity check */
        SSL_set_tlsext_host_name(tc->ssl, host); /* SNI */
}

SSL_set_verify(tc->ssl, SSL_VERIFY_PEER, tls_verify_handler);   /* chain check, always */

There is no else. When host is an IP literal, OpenSSL is given no expected identity of any
kind
— neither a DNS name via SSL_set1_host() nor an IP via SSL_set1_ip_asc() /
X509_VERIFY_PARAM_set1_ip(). SSL_VERIFY_PEER still runs, so the chain is checked and the
handshake succeeds; tls_peer_verify() then reports 0, meaning verified.

verify_server defaults to true (tls.c:306), so this is the default path, not an opt-in.

SSL_set1_ip_asc appears zero times in the repository.

Reproduction

A server presents a certificate for real.example (SAN DNS:real.example, no IP SAN), signed
by a lab CA. The client connects to 127.0.0.1 in all four runs. Only the string passed to
tls_set_verify_server() and whether the CA is trusted vary.

/* tlsprobe.c — the whole client, minus error handling */
err = tls_alloc(&tls, TLS_METHOD_SSLV23, NULL, NULL);
if (ca)                                     /* trust the lab CA */
        tls_add_cafile(tls, ca);
tls_start_tcp(&sc, tls, tc, 0);
tls_set_verify_server(sc, verify_host);     /* <-- the only variable */
tls_conn_connect(sc);
/* on ESTABLISHED: */
printf("peer_verify=%d peer_cn=%s\n", tls_peer_verify(sc), cn);

Result — four runs, same binary, same server, same certificate

RUN A  verify_host=127.0.0.1     ca=trusted    ->  ACCEPTED   peer_verify=0   peer_cn=real.example
RUN B  verify_host=wrong.example ca=trusted    ->  REJECTED   "hostname mismatch" (err 62)
RUN C  verify_host=real.example  ca=trusted    ->  ACCEPTED   peer_verify=0   peer_cn=real.example
RUN D  verify_host=127.0.0.1     ca=NOT trusted->  REJECTED   "unable to get local issuer cert" (err 20)

Run A is the finding: a certificate issued to real.example is accepted by a client that asked
to verify 127.0.0.1, and tls_peer_verify() returns 0 — verified.

The other three are the controls, and each rules out a different way I could have been wrong:

  • B — the same build, CA and certificate DO reject a mismatched name when a hostname is passed.
    So the identity check works; it simply never runs on the IP path. This is not a broken harness.
  • C — the hostname path accepts when the name genuinely matches. The test can say yes.
  • D — with the CA untrusted, the IP path rejects. So chain validation is still active; it is the
    identity check specifically that is missing.

Affected versions

Introduced by 1041521d (2020-12-01, "tls: extend server verification by host name check (SNI)"),
which added the sa_set_str() gate so that IP connections would stop failing — but removed the
check on that path instead of redirecting it to the IP variant.

first release containing 1041521d : v2.0.0
present at                        : v4.11.0 (current release) and main
SSL_set1_ip_asc / set1_ip in repo : 0 occurrences

Call sites that reach it with a caller-supplied address:

src/sip/transp.c:875    SIP over TLS (sips:)
src/http/client.c:629   HTTPS — and therefore WSS, which SIP-over-WebSocket uses
src/http/client.c:632
src/rtmp/conn.c:709     RTMPS

IPv6 takes the same path; uri_decode_hostport() strips the brackets before this point.

Why the test suite does not catch it

test/tls.c:260 already exercises exactly this call:

tls_set_verify_server(sc, "127.0.0.1");
...
TEST_EQUALS(0, tls_peer_verify(sc));

It passes — but the fixture certificate has CN = 127.0.0.1 and no extensions, so the assertion
holds whether or not the identity check runs. The suite cannot distinguish the two states. That is
offered as an explanation for how this survived six years, not as a criticism.

Suggested fix

Give OpenSSL the identity in the IP case instead of skipping it:

        if (sa_set_str(&sa, host, 0)) {
                /* ... existing DNS-name path, unchanged ... */
        }
        else {
                /* host IS an IP literal: verify it against the cert's iPAddress SAN */
                if (!SSL_set1_ip_asc(tc->ssl, host)) {
                        DEBUG_WARNING("SSL_set1_ip_asc error\n");
                        ERR_clear_error();
                        return EPROTO;
                }
                /* deliberately no SNI: RFC 6066 forbids a literal address in SNI */
        }

A regression test needs a fixture certificate whose identity does not match the address being
verified — the current one cannot fail.

Publication

If you fix these, I would like the advisory published rather than left private, so downstream
projects using libre can see it. Publication matters more to me than credit; list me or don't,
whichever you prefer.

How this was found

The TLS issue came from diffing v4.11.0 against main for security-shaped commits that had not
shipped — b7b9e383 ("verify WSS server identity against the target host") is unreleased, and
reading why led here. Its commit message attributes the WSS failure to the certificate being
"verified against the IP address and failed"; the handshake tests above show what actually happens
is that SNI is skipped (so an SNI-vhosted server returns its default certificate and the chain
check fails), while the identity check is skipped silently. Both observations are consistent;
that fix addresses one call site and does not change tls_set_verify_server().

I am happy to open a PR with the SSL_set1_ip_asc fix and a regression test — just say so. I do
not open PRs unprompted.

For transparency, I use AI assistance in my research. Every result above comes from a run I can
reproduce.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N

CVE ID

No known CVE

Weaknesses

Improper Validation of Certificate with Host Mismatch

The product communicates with a host that provides a certificate, but the product does not properly ensure that the certificate is actually associated with that host. Learn more on MITRE.

Credits