Repository navigation
fix: always filter credentials from URLs, and apply DataCollection to failed HTTP request events - #5935
fix: always filter credentials from URLs, and apply DataCollection to failed HTTP request events#5935jamescrosswell wants to merge 12 commits into
Conversation
…aware filters Adds RequestHeadersWithLegacyPiiGate / ResponseHeadersWithLegacyPiiGate to DataCollectionResolver for the client-side failed-request handlers, restores CookieFilter.FilterSetCookieHeader, and lets the header, cookie and query string helpers take a KeyValueCollectionBehavior. All new parameters default to the current behaviour. Refs #5429 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Collection Headers use the legacy-gated accessors, cookies use Cookies and the query string (in Request.Url and Request.QueryString) uses UrlQueryParams. Response cookies now come from Set-Cookie, which responses send, rather than Cookie, which they never do. Refs #5429 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
URL userinfo used to reach Sentry whenever SendDefaultPii was true. It is now filtered regardless of SendDefaultPii or DataCollection, as sentry-java and sentry-python already do and as the span-description spec requires: - the Redact() cascade over breadcrumbs, transaction and span descriptions runs for every event and transaction - RedactUrl only matches userinfo inside the URL authority, so an '@' in the path, query or later text no longer swallows the host - the failed-request Request.Url always drops userinfo and the fragment, and the fragment moves to the new SentryRequest.Fragment, as in sentry-java Refs #5429 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5935 +/- ##
==========================================
+ Coverage 77.44% 77.76% +0.31%
==========================================
Files 546 535 -11
Lines 20053 19762 -291
Branches 3962 3950 -12
==========================================
- Hits 15531 15368 -163
+ Misses 3658 3543 -115
+ Partials 864 851 -13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ureDataCollection Without ConfigureDataCollection, failed-request events with SendDefaultPii = false never carried the fragment: it was dropped along with the rest of the unfiltered URL. Keep that, and always send it once the app opts into DataCollection, as Java, Python and JS do. Refs #5429 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The single method with a nullable behavior only matched the old rule because an empty DenyList adds nothing to the built-in terms. Restore the original one-liner for callers without a behavior and give the behavior-aware path its own overload, so AddHeaders chooses explicitly. Refs #5429 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches QueryStringFilter.Filter and FilterHeaderValue. Refs #5429 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Note the addition of Fragment here to match what other SDKs are doing.
|
Mutation testing breaks the lines a PR changes on purpose, one mutation at a time, and checks that a test fails each time. A changed line no test runs fails the check, and a mutant that survives the tests only warns. Full report Sentry: tests caught 79 of 84 mutants on the changed linesStryker couldn't build 4 mutants on the changed lines, so no test ran against them.
|
…yClient
Running Redact() on every event and transaction also rewrote breadcrumbs
and span descriptions the app set itself, which the Data Collection spec
forbids ("the SDK MUST NOT modify it"). Restore the SendDefaultPii gate in
SentryClient, as on main, and instead have SentryMessageHandler pass its
subclasses the URL with credentials replaced, per Structuring Data. Trace
propagation targets still match against the original URL. sentry-java
applies the same rule where each integration records a URL.
Refs #5429
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kills two mutants the mutation-testing check reported as surviving. Refs #5429 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
There was a problem hiding this comment.
Good to approve, with optional comments
Moves SentryHttpFailedRequestHandler onto the resolved DataCollection categories and strips URL credentials wherever the SDK records an outgoing URL. This covers #5429 as scoped by the decision recorded there, and the fix is at the cause (the handler's SendDefaultPii branch and the greedy RedactUrl regex), not the symptom.
- Optional:
src/Sentry/SentryGraphQLHttpFailedRequestHandler.cs:76still recordsAbsoluteUri, so withSendDefaultPii = trueGraphQL failed-request events still carryuser:pass@until #5432 lands. Either apply the sameUrl = uri?.FilteredHttpRequestUrl(...)line here (it doesn't depend on the rest of #5432), or keep the "always" claim out of the changelog wording until then. - Optional: There's no
### Changelog Entry, so the auto changelog gets only the title. Users will see several changes: credentials dropped withSendDefaultPii = true, the fragment moving fromrequest.urltorequest.fragment,Set-Cookiecookies now collected incontexts.response.cookies, the unescapedRequest.Urlpath for PII-on apps, andSentryMessageHandlersubclasses (public, with protected ctors) now getting the redactedurlinProcessRequest/HandleResponse(src/Sentry/SentryMessageHandler.cs:86,:109). A short entry listing them would help upgraders. - Optional:
Fragmentisn't filtered at all, and withConfigureDataCollectionit's always sent, even withUrlQueryParams = Off(src/Sentry/SentryHttpFailedRequestHandler.cs:69,src/Sentry/Internal/DataCollectionResolver.cs:61). Fragments can carry tokens (e.g.#access_token=...). Consider running it through the same key/value filter as the query, or dropping it whenUrlQueryParamsisOff.
This is an automated preliminary review.
Fragments can carry tokens such as #access_token=..., so they now go through QueryStringFilter with the query's behaviour. With ConfigureDataCollection the fragment follows UrlQueryParams (Off drops it); without it, it is still sent only with SendDefaultPii = true, now through the sensitive deny list. Raised in sentry-junior's review of #5935. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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 9d4e9f8. Configure here.

Summary
Phase 2 of #5420. This moves
SentryHttpFailedRequestHandlerfromSendDefaultPiito the resolved DataCollection categories. It also strips URL credentials from the HTTP URLs the SDK records, whateverSendDefaultPiiis.RequestHeadersWithLegacyPiiGate/ResponseHeadersWithLegacyPiiGate:Configured ?? (SendDefaultPii ? DenyList : Off)Cookie), response cookies (Set-Cookie)CookiesRequest.Url,Request.QueryStringUrlQueryParams. No gated variant, because the query was never gateduser:pass@inRequest.Url#fragmentRequest.Urlinto the newSentryRequest.Fragment, filtered like the query byUrlFragmentWithLegacyPiiGate:Configured?.UrlQueryParams ?? (SendDefaultPii ? DenyList : Off)The two
*WithLegacyPiiGateaccessors,CookieFilter.FilterSetCookieHeader,GetSetCookiesand the behaviour-awareAddHeaders/QueryStringFilteroverloads are shared withSentryGraphQLHttpFailedRequestHandler. #5432 migrates that handler using them; it is untouched here.What changes for apps that don't call
ConfigureDataCollectionSendDefaultPii = true,user:pass@reached Sentry in the failed-requestRequest.Urland in outgoing HTTP spans and breadcrumbs.SentryMessageHandlernow passes its subclasses the URL with credentials replaced by[Filtered]:[Filtered]@, Structuring Data's placeholder. Span descriptions and breadcrumbs use that. MatchingTracePropagationTargetsstill uses the original.SendDefaultPii = falsepath already did.sendDefaultPii". See the decision on #5429.Redact()pass inSentryClientis unchanged. It still runs only withSendDefaultPii = false. It rewrites every breadcrumb and span description, including ones the app set itself, and the Data Collection spec says the SDK "MUST NOT modify" those.request.fragment. This follows sentry-java'sRequest.fragmentand Relay'srequest.fragment. It is still sent only withSendDefaultPii = true, as before, when it was part ofRequest.Url. It now goes through the sensitive deny list like the query, so#access_token=abcbecomesaccess_token=[Filtered].SendDefaultPii = true, failed-request events now carry the response'sSet-Cookiecookies, filtered, incontexts.response.cookies. The handler used to read aCookieheader, which responses never send. Each cookie loses its attributes, sensitive names get[Filtered]values, and a nameless or malformed cookie becomes[Filtered], per DataCollection phase 0: parse cookies individually and filter sensitive cookie names #5423.SendDefaultPii = true, and the query is kept and filtered as before.With
ConfigureDataCollection, headers, cookies and the query followHttpHeaders.Request/HttpHeaders.Response,CookiesandUrlQueryParams, andSendDefaultPiiis ignored. The fragment followsUrlQueryParamstoo.UrlQueryParams = Offstrips the query fromRequest.Urland dropsRequest.QueryStringandRequest.Fragment. Deny and allow lists filter the fragment'skey=valuepairs, and a fragment without any, such as#top, is kept.Changelog Entry
user:pass@) are no longer sent in outgoing HTTP spans, breadcrumbs or failed HTTP request events fromSentryHttpMessageHandler, even withSendDefaultPii = true. CustomSentryMessageHandlersubclasses now receive the URL with credentials replaced by[Filtered]inProcessRequestandHandleResponse.ConfigureDataCollection, failed HTTP request events follow itsHttpHeaders,CookiesandUrlQueryParamssettings, andUrlQueryParamsapplies to the URL fragment as well as the query. Without it, they still followSendDefaultPii.request.fragmentinstead ofrequest.url, with sensitive values such as#access_token=...replaced by[Filtered], andrequest.urlhas the same unescaped path whateverSendDefaultPiiis.SendDefaultPii = true, failed HTTP request events now include the response'sSet-Cookiecookies, filtered, incontexts.response.cookies.Worth a look in review
RedactUrlwas greedy. It matched fromhttps://to the last@in the string, sohttps://example.com/search?q=a@b.combecamehttps://[Filtered]@b.com. It now matches only the authority, as sentry-java parses it. That matters more now that every outgoing HTTP URL goes through it.SentryMessageHandlersubclasses now get the credential-free URL inProcessRequest/HandleResponse. The signatures are unchanged, andrequest.RequestUristill has the original.[Filtered]:[Filtered]@in request URLs.Request.Urlhere drops it instead, which keeps theSendDefaultPii = falseoutput byte-identical. Breadcrumb and span text get the placeholder.UrlQueryParams, because fragments can carry tokens (#access_token=...). ForSendDefaultPii = trueapps withoutConfigureDataCollection, that means the deny list now applies to a fragment that used to go out unfiltered.Request.Urlnow always comes fromFilteredHttpRequestUrl, soSendDefaultPii = trueapps get the same formSendDefaultPii = falseapps always had: an unescaped path, rather thanAbsoluteUri's escaped one.Response.Cookiesis a string on the event, soSet-Cookiecookies are joined asname=value; name=value, the same way the server-side request path does it. The string-array form from DataCollection phase 0: parse cookies individually and filter sensitive cookie names #5423 is for span attributes.Closes #5429
🤖 Generated with Claude Code