Repository navigation
fix(tls): reject a certificate name containing a slash - #1384
Merged
Merged
Conversation
`AddCertificate.certificate.names` is a free `Vec<String>` that `CertificateResolver::add_certificate` inserted into the SNI `TrieNode<Fingerprint>` verbatim. That trie is the same `lib/src/router/pattern_trie.rs` the HTTP router uses, where a dot-separated label wrapped in `/.../` is compiled as a REGEX segment, so a certificate declared for `/te.*/.example.com` was served for `test.example.com` and for `tenant.example.com` alike -- one certificate bound to an open-ended class of SNI values, with an inventory that shows a SAN-shaped string. The validation that existed could not catch it: it dry-runs every name into a scratch trie and asks only whether the name INSERTS, which a regex segment does. The check has to be on the name's bytes. `add_certificate` now also refuses a name containing `/`, in the SAME pre-mutation block as the `MAX_HOSTNAME_LENGTH` bound, returning `CertificateResolverError::InvalidName`; nothing is half-registered. A `/` cannot occur in a DNS name, so no legitimate SAN is lost, and an ordinary `*.example.com` wildcard is not a regex segment and still loads. This is the rule `config::validate_sni_pattern` already applies to every path into the TCP SNI route table; the certificate trie was the one SNI table left open. Removal is unaffected: `remove_certificate` re-inserts the names a certificate already carries and never re-validates them, so a certificate an earlier build accepted stays removable. `doc/configure.md` states the rule under "Hostname case" and `CHANGELOG.md` tells an operator how to find an affected configuration -- the bundled CLI never sets the `names` override, so only a control plane that fills it, or a saved state replaying one, can be affected. Reported in #1378. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 20, 2026 22:12
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.
An
AddCertificate.certificate.namesentry containing/was stored as a regexsegment in the SNI trie and bound one certificate to an open-ended class of SNI values.
add_certificatenow refuses it.The validation that existed could not catch this. It dry-runs every name into a scratch
TrieNodeand asks only whether the name inserts — and a regex segment insertsperfectly well, which is exactly why it passed. The check has to be on the name's bytes.
The refusal sits in the same pre-mutation block as the
MAX_HOSTNAME_LENGTHbound, sonothing is half-registered.
Measured on
c7ac070e: a certificate declared for/te.*/.example.comwas served forboth
test.example.comandtenant.example.com.The production change is one line,
|| name.contains('/'). Everything else is theregression test,
doc/configure.mdandCHANGELOG.md.Removal is unaffected.
remove_certificatere-inserts the names a certificate alreadycarries and never re-validates them, so a certificate a previous build accepted stays
removable and the new refusal cannot strand one.
One behaviour change beyond the issue, stated rather than hidden. When
namesis emptythe worker derives names from the certificate's SAN/CN, and the CN fallback applies — so a
Common Name containing
/is now refused too. Consistent with "/cannot occur in a DNSname", but it is a rejection that did not exist before. Covered in
doc/configure.md.This changeset also supersedes a claim in the unreleased #1351 entry which stated the
certificate trie "is not closed that way … it does not reject
/". That is false as of thischange, in the same release.
Red-then-green, re-verified independently of the authoring run: deleting the
|| name.contains('/')disjunct reddensa_certificate_name_carrying_a_regex_segment_is_refused(exit 101 with atest result:line, a real failure); restoring it passes.
BUILD=0 CLIPPY=0 TEST=0 FMT=0—test result: ok. 911 passed; 0 failed.Closes #1378