Skip to content

fix(tls): reject a certificate name containing a slash - #1384

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/reject-regex-certificate-names
Sep 21, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/reject-regex-certificate-names

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

An AddCertificate.certificate.names entry containing / was stored as a regex
segment in the SNI trie and bound one certificate to an open-ended class of SNI values.
add_certificate now refuses it.

The validation that existed could not catch this. It dry-runs every name into a scratch
TrieNode and asks only whether the name inserts — and a regex segment inserts
perfectly 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_LENGTH bound, so
nothing is half-registered.

Measured on c7ac070e: a certificate declared for /te.*/.example.com was served for
both test.example.com and tenant.example.com.

The production change is one line, || name.contains('/'). Everything else is the
regression test, doc/configure.md and CHANGELOG.md.

Removal is unaffected. remove_certificate re-inserts the names a certificate already
carries 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 names is empty
the 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 DNS
name", 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 this
change, in the same release.

Red-then-green, re-verified independently of the authoring run: deleting the
|| name.contains('/') disjunct reddens
a_certificate_name_carrying_a_regex_segment_is_refused (exit 101 with a test 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

`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
FlorentinDUBOIS merged commit 8595b56 into main Sep 21, 2026
43 of 44 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/reject-regex-certificate-names branch September 21, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tls: a certificate name containing '/' is stored as a regex and binds a class of SNI values, undocumented and untested

1 participant