Block credential/exploit scanner paths at middleware#26
Open
stockyard-dev wants to merge 1 commit intomainfrom
Open
Block credential/exploit scanner paths at middleware#26stockyard-dev wants to merge 1 commit intomainfrom
stockyard-dev wants to merge 1 commit intomainfrom
Conversation
Adds outermost middleware that 403s requests for known scanner paths
(.env, phpinfo, wp-admin, wp-login, /debug.php, /php.php) before any
handler, template, or DB work runs.
Cloudflare WAF would do this at the edge, but custom rules require a
WAF-Edit token scope we don't currently have provisioned, and the
in-app approach is portable, tracked in git, and Cloudflare-independent.
Source: 24h Cloudflare analytics on stockyard.dev (2026-04-21) showed
~227 404s/day, ~75% from a single coordinated scanner probing ~60
.env/phpinfo/wp-admin variants. None of these paths exist on the site,
so blocking is safe.
Test covers all 13 observed scanner patterns + 15 real site paths
(/, /pricing/, /desktop/, /api/installer/{macos,linux,windows},
/api/recommend, /api/toolkit-count, /robots.txt, /sitemap.xml, etc.)
to confirm zero false positives.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
stockyard | 91e8d2e | Apr 22 2026, 02:28 AM |
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.
Diagnosis
24h Cloudflare analytics on stockyard.dev (2026-04-21) showed:
.env,phpinfo.php,wp-admin/install.php,wp-login.php,/debug.php,/php.phpfrom rotating IPsFix
Adds
scannerBlockMiddleware(internal/engine/scanner_block.go) wrapped as the outermost handler so it runs first on every request. Matches the path against 6 substrings (.env,phpinfo,wp-admin,wp-login,/debug.php,/php.php) and short-circuits with 403 before any other middleware or handler runs.Cost per blocked request: a handful of
strings.Containscalls. Cost per real request: same calls, all returning false.Why not Cloudflare WAF
WAF custom rules at the zone level are available on Pro, but the API token I had was read-only and the dashboard navigation surfaced "Account-level WAF" (Enterprise add-on) instead of the per-zone Custom rules path. In-app middleware is portable, tracked in git, Cloudflare-independent, and visible to future-you. WAF can still be added later as defense-in-depth without conflict.
Test coverage
scanner_block_test.goruns 28 cases:13 scanner paths blocked (403):
/.env,/.env.bak,/.env.production,/.env.test,/backend/.env,/storage/.env,/phpinfo.php,/old_phpinfo.php,/hosting/phpinfo.php,/wp-admin/install.php,/wp-login.php,/debug.php,/php.php15 real site paths pass through (200):
/,/pricing/,/desktop/,/api/installer/macos,/api/installer/linux,/api/installer/windows,/api/recommend,/api/toolkit-count,/robots.txt,/sitemap.xml,/favicon.ico,/site-assets/...,/for/solo-developers/,/tools/,/playground,/v1/chat/completionsExpected impact
Out of scope (next steps if desired)
/pricing/fromTENCENT-NET-AP-CN) — needs a separate ASN-based rule, ideally at Cloudflare/best-self-hosted-developer-tools/404 (5 hits, only non-scanner 404 in top 25) — possibly a missing SEO landing page someone is linking to/site-assets/*to lift cache hit rate