fix: reject certs with literal-IP CN and no SAN #5804
Merged
Conversation
alexw91
reviewed
Mar 26, 2026
alexw91
reviewed
Mar 26, 2026
Contributor
alexw91
left a comment
There was a problem hiding this comment.
Small nit. LGTM otherwise.
jouho
reviewed
Mar 26, 2026
jouho
approved these changes
Mar 26, 2026
alexw91
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Restrict the hostname verification CN fallback to fully qualified DNS domain names (FQDN)
Why
When a certificate has no subjectAltName (SAN) extension,
s2n_verify_host_information()falls back to the Common Name (CN) field vias2n_verify_host_information_common_name(). This function passes the raw CN string to theverify_host_fncallback without checking whether the CN value is an IP address. If the client is usings2n_default_verify_host, which performs a plain string comparison againstconn->server_name, a certificate withCN=127.0.0.1(or any IP) and no SAN is accepted when the client targets that same IP literal.This violates RFC 6125 section 6.4.4, which restricts the CN fallback to strings whose form matches that of a fully qualified DNS domain name. Per section 6.2.1, IP reference identities must only be matched against iPAddress SAN entries, never against CN values.
How
In
s2n_verify_host_information_common_name(), after extracting the CN intopeer_cn, check whether it parses as an IPv4 or IPv6 address (viainet_pton). If it does, fail withS2N_ERR_CERT_UNTRUSTEDinstead of forwarding it to the verify callback.Callouts
We would like to thank Oleh Konko from 1seal (https://1seal.org) for reporting this issue.
Testing
Added a new unit test where test certs with IP address CN and no SAN extension are rejected. The test certs are generated from
openssl req -x509. Verify cert configuration:By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.