withSentry in nextjs can not be configured to scrub cookies (sensitive data)
See original GitHub issueProblem Statement
All I want is to scrub certain (or all) cookies from the events sent to Sentry. Basic data scrubbing of sensitive fields.
The beforeSend
hook is never called. Don’t know why, but I saw in the code that the beforeSend
hook is not called when the event type is transaction, and all events I see go through the sentry code are transactions.
I’m using withSentry
from the @sentry/nextjs
package, which internally calls parseRequest
that’s responsible for extracting the relevant sensitive data from the request. The parseRequest
function accepts (optional) options, that AFAICS can be used to limit what keys are extracted from the request (defaults include cookies). The withSentry
function however does not allow passing any options to parseRequest
.
Solution Brainstorm
Allow options to be passed to withSentry
to allow it to override what keys are extracted by extractRequestData
. The requestHandler
function can be configured in such a way, for example.
Or provide a hook that’s called on /all/ events before they are sent to Sentry, not just some.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Couldn’t get it to work with the global event processor, but this appears to work (uses the same means to add the event processor as the code in withSentry, getCurrentHub().currentScope().addEventProcessor()):
Actually, you can prevent the data from being attached in the first place using the
RequestData
integration. (You’re making me realize that though I added it to the node docs, I also need to add it to the browser docs for platforms which are frontend-backend combos (like nextjs). I’ll do that (update: done). In the meantime, see https://docs.sentry.io/platforms/node/configuration/integrations/default-integrations/#requestdata (and the Modifying System Integrations section below it).)TL;DR, you’re going to want to do something like this in your
sentry.server.config.js
: