Serve only the root path - #28
Merged
Merged
Conversation
The mux registered "/", which in net/http is a catch-all: every request
that did not match /favicon.ico ran the full handler. In a sampled four
hours of production logs, 81 of 97 requests were vulnerability scanners
probing for PHP and WordPress -- /wp-login.php, /666.php, /backup/ and
similar. Each one fetched the King County road alert feed, and each was a
candidate to spend a Gemini call once the analyzer cache expired.
Go 1.22 added the {$} pattern, which matches the root path and nothing
else, so unmatched paths now get a 404 from the mux without reaching the
handler. Every asset the page references is an absolute external URL, so
nothing was being served from a subpath.
The tests assert the absence of work rather than just the status code: a
counting feed server confirms the probes fetch the feed zero times, and
that the root path still fetches it exactly once.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Why
The mux registered
"/", which innet/httpis a catch-all. Every request that didn't match/favicon.icoran the full handler.In a sampled four hours of production logs, 81 of 97 requests were vulnerability scanners —
/wp-login.php,/666.php,/backup/,/wp-content/plugins/core-plugin/include.phpand friends. Only 16 were for/.Each of those probes fetched the King County road alert feed, and each was a candidate to spend a Gemini call once the analyzer's 15-minute cache expired.
What
Go 1.22 added the
{$}pattern, which matches the root path and nothing else. Unmatched paths now get a 404 straight from the mux, never reaching the handler.Safe here because every asset the page references is an absolute external URL — nothing was ever served from a subpath.
/favicon.icokeeps its own exact-match route.Testing
The tests assert the absence of work, not just the status code — a counting feed server verifies the probes fetch the road alert feed zero times, and that
/still fetches it exactly once. That's the property that actually matters.Verified against a real server too:
Exactly 3 requests reached the handler across that run (
GET /×2 andHEAD /); all five scanner paths were rejected by the mux.HEADis checked explicitly since bots use it. Full suite and-raceboth pass.Not included
Two other things worth fixing that aren't in scope here:
IsRoadOpenleaveslastCheckuntouched, so if the cameras start 403ing or the API errors, the 15-minute cache never engages and every request retries. That's the uncapped-cost path.🤖 Generated with Claude Code