Skip to content

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

Closed

Description

@FlorentinDUBOIS

Observed on main at c7ac070e.

AddCertificate.names is a free Vec<String> that tls.rs inserts into the SNI
TrieNode<Fingerprint> verbatim. That trie is the same lib/src/router/pattern_trie.rs
the HTTP router uses, and it gives a label delimited by / regex semantics
(insert_recursive, pattern_trie.rs:318 → Regex::new(&anchored_s), :381).

So a certificate name may be a regular expression, binding one certificate to an
open-ended class of SNI values. Nothing documents this, nothing tests it, and the
validation that exists does not reject it: tls.rs:325-335 dry-runs each name into
a scratch trie and only asks whether it inserts, which a regex segment does.

Measured

Appending a probe to lib/src/router/pattern_trie.rs on c7ac070e and running
cargo +1.93.1 test -p sozu-lib --lib probe_certnames -- --nocapture:

PROBE dry_run = Ok
PROBE insert  = Ok
PROBE lookup test.example.com     -> Some(("/te.*/.example.com", 7))
PROBE lookup tenant.example.com   -> Some(("/te.*/.example.com", 7))
PROBE lookup other.example.com    -> None
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 880 filtered out

The probe reproduces exactly what add_certificate does: dry-run into a scratch
trie (tls.rs:327-334), then domains.insert(name.into_bytes(), fingerprint)
(tls.rs:373-377). Serving-time lookup is tls.rs:707,
domains.domain_lookup(name.as_bytes(), true) — accept_wildcard = true, which
after #1367 still admits regexps entries.

Why it matters

A name like /.*/ .example.com (no space) is one character away from a plausible
typo and expands a certificate's reach across a whole subtree. An operator reading
the certificate inventory sees a SAN-shaped string; the router sees a pattern. The
two readings differ silently and there is no test pinning either.

This is operator-supplied, not attacker-supplied, so it is not a remote
vulnerability. It is an undocumented semantic with no coverage.

Disposition to decide

Either is defensible, but the current state — reachable, unwritten, untested — is not:

  1. Reject it. Have add_certificate refuse a name containing /, alongside
    the existing MAX_HOSTNAME_LENGTH bound, and return
    CertificateResolverError::InvalidName. A / cannot occur in a DNS name, so
    nothing legitimate is lost.
  2. Document and test it. State in doc/ that certificate names share the
    router's pattern grammar, and add a regression test in lib/src/tls.rs pinning
    the match set.

Related

ConfigState::get_certificates (command/src/state.rs:2748-2750) filters with
cert.names.contains(domain) — Vec::contains, exact equality. A certificate
bound by regex (or by the ordinary *.example.com wildcard) is therefore
invisible to query certificates --domain <concrete-host>, even while it is the
certificate that host is served. Filed separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions