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
This commit is contained in:
parent
f258d7a304
commit
3f5b19d4ba
2 changed files with 23 additions and 0 deletions
|
|
@ -8,5 +8,16 @@ 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,
|
||||
],
|
||||
beforeSend(event) {
|
||||
const url = event.request?.url ?? "";
|
||||
const msg = event.exception?.values?.[0]?.value ?? "";
|
||||
// Drop React Flight protocol probe errors (e.g. $1:aa:aa in multipart body)
|
||||
if (msg.includes("$1:")) return null;
|
||||
// Belt-and-suspenders: drop any remaining bot probe URL errors
|
||||
if (/\.(php|env|htaccess|xml|aspx|bak|sql)$|wp-admin|phpmyadmin/i.test(url)) return null;
|
||||
return event;
|
||||
},
|
||||
});
|
||||
|
|
@ -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|git|htaccess|xml|aspx|asp|jsp|config|bak|sql|ini|log|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<ServerBuild>,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue