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.requestMiddlewarein 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 setheadersto add the request's http headers toevent.request.headerscookiesto add the request's cookies toevent.request.cookiesHowever, there is a problem if
cookiesis not specified butheadersis: TheCookiehttp header of the incoming request is still added toevent.request.headersas 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
Cookiehttp header from the collected headers, ifcookiesis not specified in the requestHandler options butheadersis. Additionally, it adds two tests to check this new behaviour.The PR applies to both, the deprecated and new options structure.
fixes #5458