Repository navigation
middleware: test ClientIPFromHeader does not fall back to other headers - #1208
Open
renanmpimentel wants to merge 1 commit into
Open
renanmpimentel wants to merge 1 commit into
renanmpimentel wants to merge 1 commit into
Conversation
This branch has not been deployed
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 changed
Adds a subtest to
TestAdvisory_GHSA_rjr7_jggh_pgcp,no_fallback_when_opted_in_header_missing. It covers a request where the header chosen forClientIPFromHeader(X-Real-IP) is absent while attacker-controlledTrue-Client-IPandX-Forwarded-Forare present, and asserts that no client IP is stored.Why
only_opted_in_header_is_readdocuments thatClientIPFromHeaderreads only the opted-in header and ignoresTrue-Client-IP/X-Forwarded-For. But that test always sends the opted-in header too, so it can't tell "reads only that header" apart from "reads that header first, then falls back to the others". The fallback is exactly theRealIPbehaviour behind the advisories this middleware replaces.None of the existing tests cover the missing-header case together with spoofable headers either:
TestClientIPFromHeader/emptysends no headers at all.TestClientIPLastWriteWins/earlier_persists_when_later_finds_nothingsends an XFF that resolves to the same IP either way.As a result, either of these regressions in
ClientIPFromHeaderkeepsgo test ./middlewaregreen:Verification
go test -race -count=1 . ./middleware: ok (run twice)go vet ./...,gofmt -l .,goimports -l .: cleanVULNERABLE: fell back to attacker-supplied header, got "1.1.1.1"... got "2.2.2.2"I found this while experimenting with Supertest, a tool for evaluating test effectiveness using mutation testing and test-harness mutilation.