Repository navigation
fix(traffic): anchor traffic_search port matching and ignore host case - #616
Closed
sresarehumantoo wants to merge 1 commit into
Closed
sresarehumantoo wants to merge 1 commit into
sresarehumantoo wants to merge 1 commit into
Conversation
Owner
Owner
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.
Follow-up to the default-port fixes (b8c80cb, d3b2dc7) and #556. We ported those into our downstream fork and a review there turned up a few more edge cases that also exist on main here. Each one has a test that fails on main and passes with this change.
Changes
query()built the authority prefix as%://host:port, which isn't anchored to the scheme. A capture ofhttp://go.example.com/r?next=http://go.example.com:8443/x(a typical open-redirect or SSRF probe) was returned fortraffic_search host=go.example.com:8443even though it went to port 80. The prefix is now anchored tohttp,https,wsandwss.normalizeSearchHostlowercases the input, butrecordstoresURL.Hostname()with the client's case, andhost=?is case-sensitive in SQLite. A capture ofhttps://Mixed.Example.com/was not found bymixed.example.com,Mixed.Example.comorMixed.Example.com:443. The comparison is nowlower(host)=?. One trade-off: that can't use the(host, ts)index from perf(traffic): index exchanges on (host, ts) #540 for this query. If that matters, the alternative is lowercasing the host at record time, which also touchesHosts()and delete, so I kept this change small.decodeBodykept partial output only forio.ErrUnexpectedEOF. A gzip body with a bad CRC or trailing garbage decodes fine and then errors at the end, and it dropped out of the index entirely. It now keeps whatever decoded before any error, with the same size cap.storeDirignores case, so a host sanitized to_INDEXcan't reach_indexon a case-insensitive filesystem (macOS default).Tests
TestQueryHostAnchoredAndCaseInsensitive(new): records throughrecord(), covers the query-string case and three mixed-case searches.TestDecodeBodyKeepsTextOnBadGzipChecksum(new).TestHostDirSkipsStorePathsgains_INDEX.go vet ./trafficandgo test ./traffic/...pass, andgo test -race ./traffic/passes.