HttpSM.cc: fix SNI/Host check to compare full length, not just prefix#13359
Open
omkhar wants to merge 1 commit into
Open
HttpSM.cc: fix SNI/Host check to compare full length, not just prefix#13359omkhar wants to merge 1 commit into
omkhar wants to merge 1 commit into
Conversation
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.
What
HttpSM::check_sni_host()compares the request Host against the TLS SNI withstrncasecmp(host_name.data(), sni_value, host_len), which only compares thefirst
host_lenbytes. When the SNI is strictly longer than the Host and theHost is a prefix of it (e.g.
Host: secure.example.comwithSNI = secure.example.com.evil), the comparison returns0("match") and thehost_sni_policySNI/Host-mismatch handling (warn / 403) is skipped.This adds a length-equality guard so a differing-length SNI is correctly treated
as a name mismatch.
Why
Without the length check,
host_sni_policy(SNI/Host pinning) enforcement can beside-stepped for any prefix relationship between Host and SNI. The check only
runs when
host_sni_policyis configured (it is a no-op otherwise), so defaultdeployments are unaffected.
Verification
Exercised
check_sni_hostwithhost_sni_policyenforced:Host = secure.example.com,SNI = secure.example.com.evil(prefix): beforethe fix the mismatch was not enforced (request allowed); after the fix it is
correctly rejected (403).
SNI = xsecure.example.com(non-prefix mismatch): rejected before and after.SNI = secure.example.com: allowed before and after (no regression).Minimal one-line guard; happy to add an autest gold test if preferred.