Skip to content

Match SNI and Host names without regard to ASCII case - #94

Merged
kriszyp merged 6 commits into
mainfrom
fix/sni-case-insensitive
Nov 20, 2026
Merged

kriszyp merged 6 commits into
mainfrom
fix/sni-case-insensitive

Conversation

@dawsontoth

@dawsontoth dawsontoth commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor
A badger posts a big-lettered and a small-lettered envelope into the same mailbox

⊙ Problem

symphony compares route names byte for byte, but host names are case-insensitive (RFC 6066 §3). A client sending PR-12.app.example.com misses the pr-12.app.example.com route and lands on a wildcard or the default route, and a route that failed to build stops failing closed for another spelling. Non-browser clients hit this, as on the dev Central Manager's preview proxy (central-manager#1256).

💡 Solution

  • Routing ignores ASCII case for TLS SNI, the ACME Host header, the failover ingress (the same resolve_with lookup) and peer load queries.
  • Configured API.Example.com and api.example.com are one route, under the existing duplicate rules.
  • Metrics, routeHealth and peer load queries keep the spelling a route was installed with. 'suspended' still reports the client's spelling.
  • Until every peer runs this release, an older peer matches a forwarded mixed-case name the old way (#93).

⚖️ Alternatives

  • Lowercase in sni.rs — misses the ACME Host header and peer load queries.
  • Lowercase labels too — splits metric series for mixed-case configs, and older peers would not recognize the name in a load query.
  • Reject mixed-case configured names — fails updateConfig for every tenant on the port-set.

🤔 Two exact routes that differ only in case

They now collapse last-wins with no log or failingRoutes count, like same-spelling duplicates; before, both served. Central Manager and host-manager configure lowercase names. Should such a pair log and count as failing (#92)?

🤔 Accept a few nanoseconds per connection?

A lowercase exact hit costs what it did, a wildcard hit about 12 ns more, a mixed-case hit about 50 ns, beside a TLS handshake.

🤔 Post-review delta

Post-review delta: 7 lines in src/router.rs, not re-reviewed — the last round's suggestion (skip the fold when a table has no exact names) and a comment trim. Tests rerun.

🔧 Changes

✅ Verification

  • New Rust tests in router.rs, and Node tests sending a mixed-case servername (proxy.spec.ts) and ACME Host (http-listener.spec.ts) through SymphonyProxy. All fail on main (e06db8b).
  • Linux arm64 container (Rust 1.94.1, Node 24): cargo test 255 passed, clippy and fmt clean, npm test 293 passed (2 environment skips).
  • End to end: after release, a central-manager follow-up checks mixed-case preview hosts on dev.

Performance: exact lookups try the name as sent first; only a miss scans it and lowercases it into a stack buffer, never allocated. Measured with a throwaway resolve_with microbenchmark: lowercase exact hit unchanged, wildcard hit +12 ns, miss +1.5 ns.

Microbenchmark

Release build, 100 exact routes plus a wildcard and a default, best of 5 × 20M lookups, two interleaved runs per side, Linux arm64 container.

Lookup main this PR
lowercase exact hit 15.0–15.4 ns 15.2–15.8 ns
lowercase wildcard hit 13.9–14.2 ns 26.4–27.0 ns
no match (default) 14.0–14.2 ns 15.2–15.7 ns
mixed-case exact hit misses, 13.7–14.0 ns 48.7–50.9 ns
mixed-case wildcard hit misses, 14.2–14.6 ns 46.6–51.1 ns
Test cases
  • folding_is_ascii_only_and_skips_names_too_long_for_a_route: non-ASCII bytes are left alone, a 255-byte name folds, a 256-byte one is skipped.
  • sni_matching_ignores_ascii_case: mixed-case client names reach exact and wildcard routes, a mixed-case configured route matches a lowercase client and keeps its spelling as its label, a 300-byte label still matches a wildcard, and A.B.APP.EXAMPLE.COM reaches only the default.
  • a_dropped_route_fails_closed_in_any_case: a dropped exact or wildcard route stays closed for every spelling.
  • routes_that_differ_only_in_case_are_duplicates: exact last-wins, wildcard first-wins, the skipped wildcard counted failing.
  • a_respelled_route_under_a_new_client_cert_policy_is_dropped: a respelled route whose new cert fails and whose client-cert policy changed is not carried forward.
  • a_reload_that_only_changes_case_keeps_the_route: a respelled route keeps its metric identity and installed label, on a healthy reload and on one whose cert fails.
  • load_answer("UP.Example.com") answers for up.example.com.
  • proxy.spec.ts and http-listener.spec.ts: matches … regardless of ASCII case.

🤖 Generated by Claude Code (Claude Opus 5.5); posted via @dawsontoth.

Related PRs: none found
Complexity: medium

Deferred findings

Review-Coverage: authored=claude; ran=cursor-composer,codex,gemini,cursor-grok; late=cursor-grok:adjudicated; adjudicated=domain; declined=muse; rounds=5; full=3 @ 73bf1a5

Review-Attention: read ~5m (decisions: fold-in-table-not-parser, respell-keeps-installed-identity, case-only-duplicates-collapse, perf-cost) @ 73bf1a5

dawsontoth and others added 6 commits November 19, 2026 11:21
RFC 6066 §3 compares host names case-insensitively, but the route table
compared bytes. A client sending PR-12.app.example.com missed the
pr-12.app.example.com route and reached a wildcard or the default route,
a dropped route no longer failed closed for another spelling of its
name, and a route configured in mixed case matched only that spelling.

build_route_table now keys every route on its lowercased name, and
resolve_with and load_answer lowercase the name they look up (into a
stack buffer, since they run per connection), so TLS SNI, the ACME Host
header, the failover ingress and peer load queries all match in any
case. Metric labels, routeHealth events and outgoing load-query names
keep the configured spelling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A name longer than any configured route is skipped before it is scanned
or hashed, and a mixed-case name is lowercased from its first uppercase
byte. The docs now say metrics keep the spelling a route was installed
with, which a reload that changes only case does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An exact lookup now tries the name as given first, so the usual
lowercase SNI costs what it did before, and folds into the stack buffer
only when that misses. fold_case reuses the same fold, so stored keys
and lookup keys cannot drift apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A lowercase name that misses the exact map now skips the stack buffer
entirely instead of zeroing 255 bytes first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dawsontoth
dawsontoth marked this pull request as ready for review November 19, 2026 17:41
@dawsontoth
dawsontoth requested a review from kriszyp November 19, 2026 17:42

@kriszyp kriszyp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Reviewed with Muse Wonder 1.0 · adjudicated by Codex

Comment thread src/router.rs
}
if self.dropped_exact.contains(sni) {
return None;
let has_exact_names = !self.exact.is_empty() || !self.dropped_exact.is_empty();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] Tables without exact names still scan each incoming name for uppercase before falling back

Comment thread src/router.rs
}
let wildcard_suffix = spec.sni.strip_prefix("*.");
let wildcard_suffix = name.strip_prefix("*.");
if wildcard_suffix.is_some_and(|suffix| !configured_wildcards.insert(suffix)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] A skipped case-only wildcard duplicate can hide the rejection of the wildcard that was serving

@kriszyp
kriszyp merged commit 06985e4 into main Nov 20, 2026
27 of 28 checks passed
@dawsontoth
dawsontoth deleted the fix/sni-case-insensitive branch November 20, 2026 17:47
kriszyp added a commit that referenced this pull request Nov 28, 2026
Sync package + platform + crate versions to 1.8.0. Adds opt-in mtls.failureHoldMs/failureHoldJitter (#98), case-insensitive SNI/Host matching (#94), and failover forwarding/probe fixes (#85, #86).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants