From 68193e31c530b0896784740ec90cca8e840ba477 Mon Sep 17 00:00:00 2001 From: Chris Parsons <438676+chrisparsons83@users.noreply.github.com> Date: Mon, 18 May 2026 11:17:18 -0700 Subject: [PATCH] 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 --- instrument.server.mjs | 10 +++++++++- server/app.ts | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/instrument.server.mjs b/instrument.server.mjs index 9159559..486b0b6 100644 --- a/instrument.server.mjs +++ b/instrument.server.mjs @@ -8,5 +8,13 @@ Sentry.init({ ignoreErrors: [ /No route matches URL ".*\.css"/, /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, ], -}); \ No newline at end of file + 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; + }, +}); diff --git a/server/app.ts b/server/app.ts index 48a9e00..2de2ca3 100644 --- a/server/app.ts +++ b/server/app.ts @@ -11,6 +11,18 @@ export const app = express(); 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( createRequestHandler({ build: () => import("virtual:react-router/server-build") as unknown as Promise,