Skip to content

fix: Filter sensitive cookie values instead of sending raw cookies - #5894

Merged
jamescrosswell merged 9 commits into
mainfrom
ai/data-collection-parse-cookies-196ba8
Nov 13, 2026
Merged

jamescrosswell merged 9 commits into
mainfrom
ai/data-collection-parse-cookies-196ba8

Conversation

@jamescrosswell

@jamescrosswell jamescrosswell commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

When SendDefaultPii is on, cookies are now parsed and filtered by name instead of being sent as the raw header. Sensitive values become [Filtered], and nameless or malformed cookies are replaced with [Filtered], as in sentry-java. This applies to the ASP.NET Core and ASP.NET scope/event paths and to the HTTP and GraphQL failed-request handlers.

Cookie: user_session=abc; theme=dark-mode;opaque-token is now sent as:

request.cookies:              "user_session=[Filtered]; theme=dark-mode; [Filtered]"
http.request.header.cookie:   ["user_session=[Filtered]", "theme=dark-mode", "[Filtered]"]

Where the array goes. The string array is the spec's span attribute, so it goes on server transactions through the existing SetData. Error events have no attribute bag and Relay doesn't accept a plain string array in request.cookies, so events keep a filtered string, as sentry-java does. There is no public API or wire-format change, and SendDefaultPii still gates collection. Client failed-request events only get the string.

Worth a look in review:

Closes #5423

🤖 Generated with Claude Code

Parse Cookie and Set-Cookie values per DataCollection spec 0.15.0 and filter each cookie by name, so raw cookie headers no longer reach request.cookies. Server transactions also carry the http.request.header.cookie string-array attribute.

Fixes #5423

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.52941% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.95%. Comparing base (837511d) to head (f6ddbe3).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry/Internal/DataCollection/CookieFilter.cs 97.61% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5894      +/-   ##
==========================================
+ Coverage   76.87%   76.95%   +0.07%     
==========================================
  Files         533      535       +2     
  Lines       19847    19909      +62     
  Branches     3920     3945      +25     
==========================================
+ Hits        15258    15320      +62     
  Misses       3709     3709              
  Partials      880      880              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jamescrosswell and others added 3 commits November 9, 2026 16:37
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A malformed pair now becomes a single [Filtered] element instead of discarding the other cookies in the header, matching sentry-java.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rse-cookies-196ba8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reading cookies by name returned the first match for each duplicate, so a repeated cookie name sent the first value twice. Index the collection instead, which also drops the LINQ closure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jamescrosswell
jamescrosswell marked this pull request as ready for review November 10, 2026 07:57
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 10, 2026
…actions

Adds the .AspNetCore. and .AspNet. prefixes to the sensitive cookie name terms, so default auth, antiforgery and custom-scheme cookies are filtered. Cookie parsing now only runs for sampled transactions. Trims redundant tests and adds a comma-only malformed case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HTTP/2 sends header names in lowercase, so the case-sensitive match skipped Request.Cookies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 62dd4f9. Configure here.

jamescrosswell and others added 2 commits November 11, 2026 07:33
…s off

The case-sensitive skip let a lowercase cookie header fill Request.Cookies without SendDefaultPii.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FilterSetCookieHeader had no caller. It will come back with its first call site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@ric-oliv ric-oliv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good!

Comment thread src/Sentry/HttpHeadersExtensions.cs Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataCollection phase 0: parse cookies individually and filter sensitive cookie names

2 participants