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,