brackt/instrument.server.mjs
Chris Parsons 68193e31c5
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>
2026-05-18 11:17:18 -07:00

20 lines
733 B
JavaScript

import * as Sentry from '@sentry/react-router';
Sentry.init({
dsn: "https://1a366de494f1acf8fc94a4c592807b10@o1356837.ingest.us.sentry.io/4511024367861760",
enabled: process.env.NODE_ENV === "production",
sendDefaultPii: true,
tracesSampleRate: 0,
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 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;
},
});