fix(node): Remove Cookie
header from event if cookies should not be sent to Sentry
#5898
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.
When using the
Sentry.requestMiddleware
in Node (Express), users have the option to define which properties of the incoming requests should be added to the event that is sent to Sentry. Among other options, they can setheaders
to add the request's http headers toevent.request.headers
cookies
to add the request's cookies toevent.request.cookies
However, there is a problem if
cookies
is not specified butheaders
is: TheCookie
http header of the incoming request is still added toevent.request.headers
as it is treated like a normal http header. Therefore, cookie data (potentially containing sensitive data) is added to the event although users expect it to not be added.This PR fixes this behaviour by removing the
Cookie
http header from the collected headers, ifcookies
is not specified in the requestHandler options butheaders
is. Additionally, it adds two tests to check this new behaviour.The PR applies to both, the deprecated and new options structure.
fixes #5458