Block bot probe requests before routing (#444)

Fixes #344

* Add bot probe filter middleware and Sentry noise suppression

Block common bot scanning paths (wp-admin, .env, .php, etc.) in Express
before React Router handles them, preventing spurious Sentry errors.
Also filter Sentry events for React Flight protocol probes ($1:aa:aa
multipart body pattern) and any remaining bot-path 404 noise.

https://claude.ai/code/session_01Y5Ca6oxd5zyyM89acmogf7

* Tighten bot probe regex and React Flight Sentry filter

- Remove .xml, .log, .git from bot probe blocklist to avoid false positives
  on legitimate routes (e.g. /sitemap.xml)
- Tighten React Flight error filter from broad string match to precise
  wire-format pattern (/\$\d+:[a-z]/) to avoid swallowing real errors
- Remove redundant URL check from beforeSend (ignoreErrors already covers it)
- Fix missing newline at end of instrument.server.mjs

https://claude.ai/code/session_01Y5Ca6oxd5zyyM89acmogf7

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Chris Parsons 2026-05-18 11:17:18 -07:00 committed by GitHub
parent f258d7a304
commit 68193e31c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -8,5 +8,13 @@ Sentry.init({
ignoreErrors: [ ignoreErrors: [
/No route matches URL ".*\.css"/, /No route matches URL ".*\.css"/,
/No route matches URL ".*\.js"/, /No route matches URL ".*\.js"/,
/No route matches URL ".*\.(php|env|xml|aspx|asp|bak|sql|ini)"/i,
/No route matches URL ".*\/(wp-admin|wp-login|phpmyadmin|xmlrpc)"/i,
], ],
}); beforeSend(event) {
const msg = event.exception?.values?.[0]?.value ?? "";
// Drop React Flight protocol probe errors (e.g. $1:aa:aa in multipart body)
if (/\$\d+:[a-z]/.test(msg)) return null;
return event;
},
});

View file

@ -11,6 +11,18 @@ export const app = express();
app.use((_, __, next) => DatabaseContext.run(db, next)); app.use((_, __, next) => DatabaseContext.run(db, next));
// Block common bot probe paths before React Router (and Sentry) see them
const BOT_PROBE_RE =
/\.(php|env|htaccess|aspx|asp|jsp|config|bak|sql|ini|swp|DS_Store)$|^\/(wp-admin|wp-login|phpmyadmin|xmlrpc|server-status|cgi-bin|shell|cmd|console|actuator)(\/|$)/i;
app.use((req, res, next) => {
if (BOT_PROBE_RE.test(req.path)) {
res.status(404).end();
return;
}
next();
});
app.use( app.use(
createRequestHandler({ createRequestHandler({
build: () => import("virtual:react-router/server-build") as unknown as Promise<ServerBuild>, build: () => import("virtual:react-router/server-build") as unknown as Promise<ServerBuild>,