Repository navigation
Enforce single-component matching for SSL certificate wildcards - #108472
alexey-milovidov merged 5 commits into
Conversation
A '*' in an ssl_certificate user subject was constrained only by an
equal-slash-count check ("'*' must not represent a '/' in URI"). For CN
and "DNS:" SAN subjects there are no slashes, so the check was always
0 == 0 and did nothing. A user identified by '*.corp.example.com' was
therefore matched by any subject ending in '.corp.example.com',
including multi-label names like 'evil.deep.corp.example.com'. An
attacker able to obtain a CA-signed certificate for a deeper subdomain
could authenticate as the wildcard user.
Per RFC 6125 6.4.3 a wildcard must match exactly one component.
Generalize the separator to be type-aware: '.' for CN and "DNS:" SANs
(DNS label separator), '/' for "URI:" SANs (path separator, preserving
the previous behavior exactly). The matched span between the fixed
prefix and suffix must not contain the separator.
The candidate length is checked before computing the matched span so
its length cannot underflow when the prefix and suffix overlap on a
short candidate (e.g. pattern 'a*a', candidate 'a'), which also removes
a pre-existing overlap false positive. For URI SANs, "matched span has
no '/'" is equivalent to the previous equal-slash-count guard, so
existing URI wildcard behavior is unchanged.
Add integration tests covering DNS and CN wildcards (single-label
positive, multi-label bypass rejected) and a URI SAN whose matched
segment contains a dot (non-regression).
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-18:20260625-113900 |
|
cc @kcmannem @thevar1able — could you review this? It fixes an |
|
Workflow [PR], commit [17b4fda] Summary: ✅
AI ReviewSummaryThis PR tightens Final VerdictStatus: ✅ Approve |
The single-component wildcard check accepted an empty matched span: for a
user subject DNS:*.corp.example.com and a (malformed) certificate SAN
DNS:.corp.example.com the matched span is empty and contains no separator,
so the wildcard user was authenticated even though no label was matched.
extractAllSubjects stores any non-empty dNSName, so such a name is not
rejected before authentication.
Require the matched span to be non-empty for the DNS/CN ('.'-separator)
case. RFC 6125 6.4.3 requires '*' to match exactly one non-empty label.
URI SAN path segments ('/'-separator) may legitimately be empty, so the
URI case keeps its prior behavior (the matched-span-has-no-'/' rule remains
equivalent to the original count('/') guard).
Add empty-label negative cases (cert client10, CN and DNS SAN
.corp.example.com) to both the DNS and CN wildcard integration tests.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed in 0141b64. The match now also requires the matched span to be non-empty for the DNS/CN ( Regression coverage: cert |
A SAN wildcard pattern configured without a recognized "DNS:"/"URI:" prefix
(for example a bare SAN '*') was routed to the DNS '.' separator by the
is_uri allow-list, because '.' was the default for everything that was not
URI-prefixed. As a result such a pattern matched a "URI:" certificate whose
matched span contains no '.', e.g. URI:spiffe://foo/bar, even though the
original slash-count guard rejected it (0 vs 3 slashes). That widened
URI SAN matching in this security-sensitive path.
Choose the '.' (DNS label) separator via an allow-list of exactly CN and
"DNS:" SANs, and keep every other SAN on the '/' separator. For the '/'
case, "no '/' in the matched span" is identical to the original
count('/', pattern) == count('/', candidate) guard, so URI and
unrecognized-prefix matching is provably unchanged. The non-empty-label
requirement remains scoped to the DNS label case.
Adds an integration regression case: a bare SAN '*' user must not match the
URI certificate URI:spiffe://foo/bar (client11).
A DNS label or CN never contains a slash, but the single-label rule only
forbade '.' in the matched wildcard span. Since extractAllSubjects stores
raw non-empty dNSName/CN strings without validation, a configured subject
'DNS:*.corp.example.com' matched a certificate SAN 'DNS:foo/bar.corp.example.com'
(matched span 'foo/bar' has no '.'), and a slash-containing CN wildcard matched
a deeper name. The original slash-count guard rejected these; the single-label
rewrite had dropped that guard for the DNS/CN branch.
For a DNS label (a CN or a 'DNS:' SAN), the matched span must now be a single
non-empty component containing neither '.' nor '/'. Other SANs ('URI:' or
configured without a recognized prefix) keep the original rule (only '/'
forbidden), which is identical to the slash-count guard, so URI matching is
unchanged.
Adds regression certificate client12 (CN and DNS SAN both
'foo/bar.corp.example.com') and negative cases to the DNS and CN wildcard
single-label tests.
Pre-PR validation gate — head
|
| # | Question | Answer |
|---|---|---|
| a | Deterministic repro? | Yes. Configured subject DNS:*.corp.example.com (or CN *.corp.example.com) vs certificate foo/bar.corp.example.com (cert client12, CN + DNS: SAN) authenticates deterministically on the prior binary. |
| b | Root cause explained? | The single-label rewrite forbade only . in the matched span for the DNS/CN branch and dropped the original slash-count guard. extractAllSubjects stores raw non-empty dNSName/CN strings unvalidated, so foo/bar (no .) passed → a slash-containing multi-label name bypassed the wildcard. |
| c | Fix matches root cause? | Yes. For a DNS label the matched span must be a single non-empty component with no . AND no /. Directly restores the slash rejection the guard provided, scoped to the DNS/CN branch. |
| d | Test intent preserved / new tests added? | Yes. Added negative cases to test_x509_dns_san_wildcard_single_label and test_x509_cn_wildcard_single_label (cert client12) asserting slash-in-span is rejected on both native and HTTPS. Existing positive single-label, empty-label, URI dot-in-segment, and unprefixed-SAN cases unchanged. |
| e | Both directions demonstrated? | Yes. Fixed binary (Build ID 20960dad): 5/5 wildcard tests PASS. Prior binary (833a30db, fix reverted + recompiled): dns + cn tests FAIL (client12 wrongly authenticates), URI dot-in-segment PASSES. Build IDs verified; restored fix rebuilt deterministically back to 20960dad. |
| f | Fix is general across code paths? | Yes. checkSSLCertificateAuthentication is the only cert-subject wildcard matcher (confirmed prior rounds). Both the CN and DNS: SAN paths share the is_dns_label branch, so both are covered by one change. |
| g | Fix generalizes across inputs? | Yes. Verified across the input matrix (standalone repro + integration): multi-label, empty-label, single dot-label, slash-in-span, URI dot-in-segment, unprefixed SAN, and the a*a overlap underflow case. The non-DNS / branch is proven equal to the original slash-count guard for all anchored candidates. |
| h | Backward compatible? | Yes. The non-DNS (URI:/unprefixed) branch keeps "only / forbidden", mathematically identical to the original count('/') guard, so valid URI/SPIFFE configs are unaffected. The DNS/CN branch only tightens an authentication bypass (no legitimate hostname contains /). |
| i | Invariants and contracts preserved? | Yes. The certificate_subject.size() < prefix.size()+suffix.size() guard before the substr is retained (no size_t underflow). Candidate SANs are always DNS:/URI: prefixed by extractAllSubjects; the matched-span semantics (single non-empty hostname label) match RFC 6125 6.4.3. |
Session id: cron:clickhouse-worker-slot-9:20260625-153800
A wildcard SAN subject configured without a recognized "DNS:"/"URI:" prefix took the non-DNS branch, so '*' could absorb a candidate's type prefix and span DNS labels: a bare SAN '*.corp.example.com' matched the certificate SAN DNS:evil.deep.corp.example.com (matched span "DNS:evil.deep" has no '/'). Certificate SAN subjects are always stored with a "DNS:"/"URI:" prefix, so a wildcard SAN pattern must carry one of those prefixes to align with a candidate. Reject any unprefixed SAN wildcard up front (it matches nothing). CN patterns (never prefixed) and properly prefixed DNS:/URI: SAN patterns are unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pre-PR validation gate for the unprefixed-SAN-wildcard fix (commit 17b4fda, addressing the residual DNS-label-spanning finding). Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260625-164800 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 21/23 (91.30%) | Lost baseline coverage: none · Uncovered code |
CI finish ledger — 17b4fdaCI is green. The
Session id: cron:our-pr-ci-monitor:20260625-220000 |
Resolve conflicts for the #108472 backport (SSL certificate wildcard single-component matching) onto 25.8. `src/Access/Authentication.cpp` auto-merged: the 25.8 structure (`bool` return types, inline password checks, no one-time-password support) is kept and only the wildcard single-component fix from #108472 is applied on top. The test fixtures conflicted because master carries a separate, un-backported session_log feature that 25.8 lacks. Resolution keeps only what #108472 introduced: - `certs/generate_certs.sh`: add the new client7-client12 generation and signing; drop the `client_far_future` lines (part of the session_log feature, not present in 25.8). - `certs/ca-cert.srl`: take the serial consistent with the cherry-picked client7-client12 certificates. - `test.py`: append the five new wildcard tests; drop the `test_session_log_certificate_*` tests (session_log feature, not in 25.8). `configs/session_log.xml` and the `client_far_future` certificate files are correctly dropped by the merge for the same reason.
Cherry pick #108472 to 25.8: Enforce single-component matching for SSL certificate wildcards
…ertificate wildcards
…ertificate wildcards
…ertificate wildcards
…ertificate wildcards
Cherry pick #108472 to 26.3: Enforce single-component matching for SSL certificate wildcards
…ertificate wildcards
Cherry pick #108472 to 26.4: Enforce single-component matching for SSL certificate wildcards
…ertificate wildcards
Cherry pick #108472 to 26.5: Enforce single-component matching for SSL certificate wildcards
…ertificate wildcards
Backport #108472 to 26.4: Enforce single-component matching for SSL certificate wildcards
Backport #108472 to 26.5: Enforce single-component matching for SSL certificate wildcards
Backport #108472 to 26.3: Enforce single-component matching for SSL certificate wildcards
Backport #108472 to 25.8: Enforce single-component matching for SSL certificate wildcards
Resolve conflicts in tests/integration/test_ssl_cert_authentication caused by master's PR ClickHouse#108472 (SSL certificate SAN wildcard matching), which regenerated the whole certificate set and renumbered clients up to `client12` plus `client_far_future`, colliding with this branch's `client7`. Resolution: - Take master's consistent certificate set as-is (all signed by master's CA) so the existing wildcard / session_log tests keep passing. - Move this branch's EMAIL SAN certificate to a fresh `client13` (`EMAIL:[email protected]`), signed by master's CA, and update `generate_certs.sh` accordingly. - Keep master's `users_with_ssl_auth.xml` users and add back the `alice` user that authenticates by `EMAIL:[email protected]`. - Take master's `test.py` and re-append `test_x509_san_email_support`, switched from `client7` to `client13`. - `src/Common/Crypto/X509Certificate.cpp` auto-merged: `extractAllSubjects` keeps the new `GEN_EMAIL` handling on top of master's changes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@alexey-milovidov this PR introduced many certificate files, then many blobs to the repo. Was this a good idea? |
|
Numbers for that call, since I wrote the change. Honest answer: following the directory's existing convention was defensible, committing the CSRs alongside it was not. #108472 added 24 files under The clearly unnecessary part: the 14 The fully generated shape already exists in the tree: I am glad to do either one: delete just the unused CSRs, or convert the directory to fixture-time generation. It touches every test in the directory, so I would rather have that call from you than assume it. |
…ert-wildcard-single-label Enforce single-component matching for SSL certificate wildcards
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
ssl_certificateuser identification so a single*wildcard matches exactly one name component (RFC 6125 6.4.3). Previously a wildcard in aCNorDNS:SAN subject (for example*.corp.example.com) also matched multi-label names such asevil.deep.corp.example.com, letting a holder of a certificate for a deeper subdomain authenticate as the wildcard user.URI:SAN matching is unchanged.Description
The
ssl_certificatewildcard branch incheckSSLCertificateAuthenticationconstrained*only with an equal-slash-count check (comment: "*must not represent a/in URI").CNandDNS:SAN subjects contain no slashes, so that check was always0 == 0and imposed no constraint: the match reduced to a prefix/suffix test. A user identified by*.corp.example.comwas therefore matched by any subject ending in.corp.example.com, including multi-label names likeevil.deep.corp.example.com. An attacker who can obtain a CA-signed certificate for a deeper subdomain could authenticate as the wildcard user.Fix: make the separator type-aware.
*must not span a separator in the matched component:.forCNandDNS:SAN subjects (DNS label separator), so a wildcard matches exactly one label./forURI:SAN subjects (path separator), preserving existing behavior. "Matched span contains no/" is equivalent to the previous equal-slash-count guard, so URI SAN wildcard behavior is unchanged (URI path segments may still contain dots).The candidate length is checked before computing the matched span, so its length cannot underflow when prefix and suffix overlap on a short candidate (for example pattern
a*a, candidatea); this also removes a pre-existing overlap false positive.Tests added to
tests/integration/test_ssl_cert_authentication:DNS:*.corp.example.com: single-labelnode1.corp.example.comauthenticates; multi-labelevil.deep.corp.example.comis rejected (the bypass), over both the native and HTTPS interfaces.*.corp.example.com: same single-label positive and multi-label negative.URI:spiffe://bar.com/foo/baz.qux/faragainstURI:spiffe://bar.com/foo/*/far): still matches (non-regression).Verified both directions on a local debug build: the two new negative tests FAIL on the unpatched binary (the multi-label bypass succeeds) and PASS with the fix; the URI non-regression test and the existing
test_x509_san_wildcard_supportpass on both.Note for reviewers: this is a security fix that intentionally stops accepting the previously-matched multi-label names, so it is technically a behavior change for wildcard
ssl_certificateusers. The previously-accepted behavior is the vulnerability and is non-compliant with RFC 6125, so no setting is added to restore it. Legitimate single-label wildcard matching is preserved. The wildcard*was introduced in 2068fbb.Version info
26.6.2.7,26.5.4.21,26.4.5.77,26.3.17.3,25.8.26.3