Repository navigation
Report errors to GlitchTip (Sentry SDK) with secret scrubbing - #825
Conversation
Adds the Sentry SDK (pinned 11.10.0) for server, edge and browser, fully disabled unless SENTRY_DSN / NEXT_PUBLIC_SENTRY_DSN is set. Every event, transaction and breadcrumb passes through lib/observability/scrub.ts, which filters sensitive keys, inline credentials and emails. The CSP connect-src gains the DSN's https origin only when the browser DSN is set. Build-time telemetry, source-map upload and tunnel route are off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f846e831e0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const BASIC = /\b(Basic)\s+[A-Za-z0-9+/]{8,}={0,2}/g | ||
| // name=value / name: value / "name":"value" where name looks like a credential | ||
| const KEY_VALUE = | ||
| /\b([\w.-]*?(?:password|passwd|pass|token|secret|api[-_]?key|apikey|auth|dsn|credentials?|session(?:[-_]?id)?))(["']?\s*[=:]\s*["']?)("[^"]*"|'[^']*'|[^\s&;,"'}\]]+)/gi |
There was a problem hiding this comment.
Match quoted credential values before consuming their opening quote
When an exception message or breadcrumb contains a quoted credential with spaces, the separator group greedily consumes the opening quote, so the quoted-value alternatives cannot match and only the first word is filtered. For example, scrubString('password="correct horse battery staple"') returns password="[Filtered] horse battery staple"; serialized JSON strings have the same problem. Because these strings pass through the outgoing event hooks, the remaining password content is sent to GlitchTip. Leave the opening quote for the quoted-value branch and add regression tests for both quote styles and serialized JSON.
Useful? React with 👍 / 👎.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sentry v11 streams spans by default and does not call beforeSendTransaction for them, so add beforeSendSpan (scrubSpan) to server, edge and client init, stop collecting URL query params, and replace the whole query string of any URL in events, spans and breadcrumbs so OAuth code/state cannot leak. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as build args Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…plicitly Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
Reports errors to the self-hosted GlitchTip (Sentry-compatible) via
@sentry/nextjs(pinned exactly11.10.0), with secret scrubbing on everything that leaves the process.SDK disabled without DSN.
enabledis true only when a DSN env var is set; with none set (CI, tests, dev, other worktrees) nothing is initialised or sent.Env vars (names only; see
.env.example,deploy/README.md)SENTRY_DSN(server + edge),NEXT_PUBLIC_SENTRY_DSN(browser, build-time),SENTRY_ENVIRONMENT/NEXT_PUBLIC_SENTRY_ENVIRONMENT(defaultdev),SENTRY_RELEASE/NEXT_PUBLIC_SENTRY_RELEASE(unset = none).Setup
instrumentation.ts: existing startup checks unchanged; adds per-runtime Sentry config imports andonRequestError = Sentry.captureRequestError.sentry.server.config.ts,sentry.edge.config.ts,instrumentation-client.ts:tracesSampleRate 0.05, no Replay/profiling/feedback/Spotlight,beforeSend+beforeSendTransaction=scrubEvent,beforeBreadcrumb=scrubBreadcrumb. SDK v11 has nosendDefaultPii; the equivalentdataCollection(no user info, cookies, bodies, DB query data, queue args, stack vars, client-IP headers) is inlib/observability/data-collection.ts.next.config.ts: wrapped withwithSentryConfig(from@sentry/nextjs/config; the package root has no such export under Node resolution) withtelemetry: false,silent: true,sourcemaps: { disable: true }, no auth token, no tunnel route. All existing options and headers untouched.lib/security/csp.ts/proxy.ts: the DSN's https origin is added toconnect-srconly whenNEXT_PUBLIC_SENTRY_DSNis set and parses as https; otherwise the policy is byte-identical.Scrub rules (
lib/observability/scrub.ts)Recursive over the whole event: values under keys matching
/pass(word)?|secret|token|auth|api[-_]?key|cookie|dsn|session|credential/ibecome[Filtered]; in strings,auth=/password=/token=/secret=style pairs,Authorization:/Bearer/Basictext anduser:pass@URL credentials are removed; emails become[email];user.ip_address,user.emailand request cookies are dropped. Order ids, SKUs and normal text are unchanged. Cycles and depth are handled; it never throws (on failure the event is reduced to[scrub failed]message/exception; a breadcrumb that cannot be scrubbed is dropped).Tested
tests/observability/scrub.test.ts(9 tests) and extendedtests/security/csp.test.ts(set / unset / non-https / invalid DSN); breaking the scrubber (removing the key=value rule) makes 4 of the 9 scrub tests fail.next buildcompile step (see CI for the full build).🤖 Generated with Claude Code