Skip to content

Report errors to GlitchTip (Sentry SDK) with secret scrubbing - #825

Merged
OneTwo3D merged 10 commits into
developmentfrom
glitchtip-sentry
Nov 1, 2026
Merged

OneTwo3D merged 10 commits into
developmentfrom
glitchtip-sentry

Conversation

@OneTwo3D

Copy link
Copy Markdown
Owner

What

Reports errors to the self-hosted GlitchTip (Sentry-compatible) via @sentry/nextjs (pinned exactly 11.10.0), with secret scrubbing on everything that leaves the process.

SDK disabled without DSN. enabled is 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 (default dev), SENTRY_RELEASE / NEXT_PUBLIC_SENTRY_RELEASE (unset = none).

Setup

  • instrumentation.ts: existing startup checks unchanged; adds per-runtime Sentry config imports and onRequestError = 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 no sendDefaultPii; the equivalent dataCollection (no user info, cookies, bodies, DB query data, queue args, stack vars, client-IP headers) is in lib/observability/data-collection.ts.
  • next.config.ts: wrapped with withSentryConfig (from @sentry/nextjs/config; the package root has no such export under Node resolution) with telemetry: 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 to connect-src only when NEXT_PUBLIC_SENTRY_DSN is 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/i become [Filtered]; in strings, auth=/password=/token=/secret= style pairs, Authorization:/Bearer/Basic text and user:pass@ URL credentials are removed; emails become [email]; user.ip_address, user.email and 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 extended tests/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.
  • tsc in partitions, eslint on changed files, next build compile step (see CI for the full build).

🤖 Generated with Claude Code

OneTwo3D and others added 2 commits October 31, 2026 19:00
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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T20:21:31.659189Z f846e83 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread lib/observability/scrub.ts Outdated
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

OneTwo3D and others added 8 commits October 31, 2026 20:40
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>
@OneTwo3D
OneTwo3D merged commit 4368aed into development Nov 1, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant