Skip to content

fix(traffic): anchor traffic_search port matching and ignore host case - #616

Closed
sresarehumantoo wants to merge 1 commit into
BaaRai:mainfrom
sresarehumantoo:fix/traffic-search-anchor-and-case
Closed

sresarehumantoo wants to merge 1 commit into
BaaRai:mainfrom
sresarehumantoo:fix/traffic-search-anchor-and-case

Conversation

@sresarehumantoo

Copy link
Copy Markdown
Contributor

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

  • Port search matched URLs in the query string. query() built the authority prefix as %://host:port, which isn't anchored to the scheme. A capture of http://go.example.com/r?next=http://go.example.com:8443/x (a typical open-redirect or SSRF probe) was returned for traffic_search host=go.example.com:8443 even though it went to port 80. The prefix is now anchored to http, https, ws and wss.
  • Host case. normalizeSearchHost lowercases the input, but record stores URL.Hostname() with the client's case, and host=? is case-sensitive in SQLite. A capture of https://Mixed.Example.com/ was not found by mixed.example.com, Mixed.Example.com or Mixed.Example.com:443. The comparison is now lower(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 touches Hosts() and delete, so I kept this change small.
  • Corrupt compressed bodies. decodeBody kept partial output only for io.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.
  • storeDir ignores case, so a host sanitized to _INDEX can't reach _index on a case-insensitive filesystem (macOS default).

Tests

  • TestQueryHostAnchoredAndCaseInsensitive (new): records through record(), covers the query-string case and three mixed-case searches.
  • TestDecodeBodyKeepsTextOnBadGzipChecksum (new).
  • TestHostDirSkipsStorePaths gains _INDEX.
  • go vet ./traffic and go test ./traffic/... pass, and go test -race ./traffic/ passes.

@BaaRai

BaaRai commented Nov 28, 2026

Copy link
Copy Markdown
Owner

The code is verified, but #606 merged and touched traffic/encoding_test.go (and #615 touched CHANGELOG.md), so this PR is now conflicting. Please rebase on main and rerun the traffic tests; no code change is requested.

@BaaRai

BaaRai commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Landed via #639 with the conflicts after #606 and #615 resolved: the port search is anchored to http, https, ws and wss, and host matching is case-insensitive. Thanks, Owen Pierce.

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