feat: block scanner junk at the nginx edge - #2884
Merged
Merged
Conversation
~91% of ChapterController requests are 404s from automated scanners: sensitive-file probes (SSH keys, cloud configs, .env files), Vite RSC source-map probing, and other path guesses landing on the /:id chapter catch-all. Return 404 at nginx instead of forwarding to Rails; every blocked pattern already 404s in the app, so client-visible behaviour is unchanged and the load moves off Rails. Two regex locations in config/nginx.conf.erb: - sensitive or unknown file extensions (nested paths included), excluding the real asset dirs and the advertised /sitemap.xml.gz - extension-less probes seen in the canonical log archive (id_rsa- style key names, wp-* paths, /__vite_rsc_findSourceMapURL, the debug-trigger path) Code review findings shaped the final rules: the extension rule originally 404'd /sitemap.xml.gz, which public/robots.txt advertises (fixed with an exact-filename exclusion so backup-archive probes like site.tar.gz stay blocked), the .env branch missed .env.local and .env.production variants (fixed), and the comment misstated nginx location precedence (corrected: only exact = locations beat the regex blocks). New nginx CI workflow renders the ERB, runs nginx -t, and asserts a curl matrix: scanner probes 404 at the edge, legitimate paths (including /sitemap.xml.gz, chapter slugs, and the exact-match Plausible proxy paths) pass through. Verified against a live nginx:alpine container: the full probe and passthrough matrix passes.
This was referenced Sep 16, 2026
mroderick
marked this pull request as ready for review
September 17, 2026 06:19
KimberleyCook
approved these changes
Sep 17, 2026
olleolleolle
approved these changes
Sep 17, 2026
olleolleolle
left a comment
Collaborator
There was a problem hiding this comment.
Enjoyable to have a CI test run for nginx config!
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.
Block scanner junk at the nginx edge so it never reaches Rails.
Analysis of the canonical log archive (2026-09-16) showed 91% of ChapterController requests are 404s from automated scanning: sensitive-file probes (SSH keys, cloud configs, .env files), Vite RSC source-map probing, and path guesses landing on the
/:idchapter catch-all. The app already answers every one with a 404; this change stops them at nginx instead, with client-visible behaviour unchanged.Changes
Two regex locations in
config/nginx.conf.erb, ahead of thelocation /proxy:/assets,/uploads,/static,/tom-select,/packs) and the advertised/sitemap.xml.gzid_rsa-style key names,wp-*paths,/__vite_rsc_findSourceMapURL, thez9x8c7v6b5-debug-trigger-codebar.ioprobe,Dockerfile,__debug__,userfiles,backup,private[-_]keyNew CI workflow (
.github/workflows/nginx.yml) renders the ERB, runsnginx -t, and asserts a curl matrix: scanner probes 404 at the edge, legitimate paths (including/sitemap.xml.gz, chapter slugs, and the exact-match Plausible proxy paths) pass through.Verification
nginx -tnginx:alpinecontainer (60+ probe paths 404; 20+ legitimate paths unchanged)Review notes
public/asset directory outside the five excluded prefixes would silently 404 its files at the edge; the new CI smoke matrix is the guard, so add new public dirs to both the lookahead and the matrix..gzexclusion is by exact filename (sitemap.xml.gz) rather than droppinggzfrom the extension list, so backup-archive probes (site.tar.gz,db.sql.gz) stay blocked./sponsors.json) return an edge 404 where the app returned 406. Only scanner-style probes hit those; accepted as part of the behaviour-unchanged scope.backup) would 404 at the edge. No current slug collides; the chapter-slug namespace is not checked automatically./staticexclusion).