feat(observability): tag Sentry events for SQLSTATE 42501 RLS violations#111
Merged
Merged
Conversation
Adds isRlsViolation() helper in beforeSend that matches PostgreSQL error patterns (42501 code, 'row-level security', 'insufficient privilege'). On match: - fingerprint: ['rls-policy-violation-42501'] — groups all violations into one Sentry issue instead of hundreds of separate ones - tags: rls_violation=true, sqlstate=42501 — enables alert rules - level: fatal — RLS bypass in prod is critical, not just an error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extends
sentry.server.config.tsbeforeSendto detect and tag PostgreSQL RLS violation errors before they reach Sentry.Why
Without this, a leaked RLS violation (SQLSTATE 42501) arrives in Sentry as a generic Prisma error — buried in noise, no grouping, no alert. With this, every 42501 is immediately visible as
fatalwith a single fingerprint.Changes
sentry.server.config.ts— addsisRlsViolation()helper + extendsbeforeSend:On match,
beforeSendsets:fingerprint['rls-policy-violation-42501']tags.rls_violation'true'tags.sqlstate'42501'level'fatal'Only
sentry.server.config.tschanged — SQLSTATE 42501 is a server-side Prisma/PostgreSQL error, never reaches client or edge runtime.Test plan
pnpm typecheckpasses (noSentry.ErrorEventtype errors)app_userwithout org context → confirm Sentry receives event withrls_violation=truetag andfatallevel