Repository navigation
ref: Add internal sensitive-data denylist and key-value filter utility - #5440
Merged
Merged
Conversation
First step of the DataCollection migration (#5420, #5421). Internal only, nothing wired up yet. Mirrors filterKeyValueData/filtering-snippets from the JS reference implementation. Co-Authored-By: Claude Fable 5 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5440 +/- ##
==========================================
+ Coverage 76.65% 76.73% +0.08%
==========================================
Files 531 532 +1
Lines 19713 19782 +69
Branches 3895 3905 +10
==========================================
+ Hits 15111 15180 +69
- Misses 3716 3717 +1
+ Partials 886 885 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 2, 2026
Ignore empty and null terms when matching: an empty term would otherwise filter every value in deny-list mode and allow every value through in allow-list mode, which becomes reachable once terms are bound from configuration. Trim the denylist to the spec's canonical 17 terms. Treating cookie and set-cookie as substring terms over-filtered every other category; the exact header-name rule belongs at the header call site (#5422). Decode keys before matching so an encoded key such as %74oken is recognised, while callers still store the raw key and value. Return an ordered list rather than a dictionary, so repeated headers such as Set-Cookie are preserved instead of silently collapsed. Co-Authored-By: Claude Opus 5 <[email protected]>
…ltPii Adds the option shape from the DataCollection spec as a no-op: nothing reads it yet. The resolver and SendDefaultPii bridge follow in #5426. Co-Authored-By: Claude Opus 5 <[email protected]>
Uri.UnescapeDataString never throws on malformed input, it returns the input unchanged, so the UriFormatException handler could not run. Off mode now returns [Filtered] from FilterValue instead of being asserted away, which drops the unreachable default switch arm and makes the mode's result explicit. Co-Authored-By: Claude Opus 5 <[email protected]>
Mirrors DataCollectionOptions in BindableSentryOptions so the option can be set from appsettings.json, following the nested-bindable pattern used by the platform options. KeyValueCollectionBehavior has no public constructor, so it binds through a Mode/Terms surrogate. Co-Authored-By: Claude Opus 5 <[email protected]>
…nable() Assigning the option is now the opt-in signal, matching sentry-go, sentry-php, sentry-python and sentry-javascript. Removes Enable() and the internal bookkeeping it needed to distinguish an unset option from a default one. Co-Authored-By: Claude Opus 5 <[email protected]>
…to feat/sensitive-data-filter
…filter The internal KeyValueFilterBehavior/KeyValueFilterMode pair was written when this phase was expected to land before the public option shape. That shape now exists with identical modes and semantics, so the internal pair was duplication and is removed. MatchesAny tolerates a null term list, because DenyList(null) leaves Terms null and the SDK must not throw while capturing an event. It also iterates by index, since IReadOnlyList allocates an enumerator where an array does not and this runs per key per event. Co-Authored-By: Claude Opus 5 <[email protected]>
jamescrosswell
changed the base branch from
main
to
feat/data-collection-options
November 3, 2026 00:33
An explicit null for a params array is legal, so DenyList(null) and AllowList(null) produced an instance whose Terms was null, which would throw in any consumer that iterates it. Coalesce in the constructor so both factories are covered. Co-Authored-By: Claude Opus 5 <[email protected]>
…to feat/sensitive-data-filter
additionalDenyTerms is nullable, so passing it straight to MatchesAny replaces a second null check at the call site and keeps the guard load-bearing now that KeyValueCollectionBehavior.Terms is never null. Co-Authored-By: Claude Opus 5 <[email protected]>
The bool shorthand code has for cookies, headers and query params has no configuration equivalent, so a scalar is dropped by the binder. Document the supported shape on the public type and lock the behavior with a test. Co-Authored-By: Claude Opus 5 <[email protected]>
Swaps the IncomingResponse/OutgoingResponse doc comments, which described the wrong direction. Gives KeyValueCollectionBehavior a public constructor and settable properties so the reflection binder can construct it: on netstandard2.0 the options are bound directly rather than through BindableSentryOptions, and any key-value category threw there. Binds HttpBodies from an array so the spec's empty-array opt-out works instead of silently collecting every body. Adds coverage for the four ApplyTo lines no test reached. Co-Authored-By: Claude Opus 5 <[email protected]>
…in config A JSON empty array emits a valueless key with no children, which the binder surfaces as null, so "[]" cannot be told apart from the option being absent and did not disable body collection. The previous test asserted against a hand-built list rather than the binder, so it did not catch this. Co-Authored-By: Claude Opus 5 <[email protected]>
…to feat/sensitive-data-filter
#5853 was squash-merged, so the branch commits this stack carried were no longer ancestors of main. Resolve every DataCollection file to main's version; this branch contributes only SensitiveDataFilter and its tests. Co-Authored-By: Claude Opus 5 <[email protected]>
KeyValueCollectionBehavior sanitizes its own Terms as of #5853, so the four behavior-level null/empty-term tests duplicated DataCollectionOptionsTests. additionalDenyTerms is caller-supplied and unsanitized, so test the guard there. Co-Authored-By: Claude Opus 5 <[email protected]>
jamescrosswell
marked this pull request as ready for review
November 5, 2026 23:55
ric-oliv
reviewed
Nov 8, 2026
ric-oliv
approved these changes
Nov 8, 2026
ric-oliv
left a comment
Member
There was a problem hiding this comment.
Two optional comments only... looking good!
Verified by mutation: with the empty-term guard removed from MatchesAny both stayed green, while the additionalDenyTerms theories failed. The behavior type strips the term before it reaches the guard. Also document that Off requires the caller to drop the key, since FilterValue returns [Filtered] there only to fail closed. Co-Authored-By: Claude Opus 5 <[email protected]>
Uri.UnescapeDataString returns the input unchanged for a malformed escape on modern .NET but throws UriFormatException on .NET Framework. sentry-java guards the same call in decodeQueryParamName. #5424 feeds untrusted query keys through here, and the SDK must not throw while enriching an event. Co-Authored-By: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #5421
Part of #5420. Was stacked on #5853; that has now merged, so this targets
mainand stands on its own.Phase 0 of the DataCollection migration (spec 0.15.0): the internal sensitive-terms denylist and the shared key-value filtering utility that later PRs wire into header, cookie and query-string collection (#5422, #5423, #5424).
SensitiveDataFilterholds the canonical sensitive denylist, cookie-name-only extra terms, the extended GDPR/PII terms (for theSendDefaultPiibridge in #5426), andFilterKeyValueData/FilterValueimplementing the spec's semantics: key names always preserved, sensitive values replaced with[Filtered], built-in denylist applied in every mode including allow-list.It consumes the public
KeyValueCollectionBehaviorfrom #5853 rather than defining its own type. An earlier revision of this branch carried an internalKeyValueFilterBehavior/KeyValueFilterModepair, written when Phase 0 was expected to land before the public option shape. #5853 has since defined that shape with identical modes and semantics, so the internal pair was duplication and has been removed.Internal only, and nothing is wired up yet, so there is no public API or behavior change.
Cross-SDK alignment
Verified against
io.sentry.util.HttpUtilsin sentry-java (shipped in 8.58.0), which is the closest analogue to .NET. Three deliberate decisions where the implementations differ:cookie/set-cookieare not denylist terms. The spec's canonical denylist is exactly 17 terms and excludes them. Java keeps the list canonical and applies an exactequalsIgnoreCasecheck forCookie/Set-Cookieinside header filtering only. Treating them as substring denylist terms (as the JS SDK does) bleeds into every category — a query param?cookie_consent=true, a cookie namedcookie_prefsor a headerX-Cookie-Debugwould all be filtered, which neither the spec nor Java does. The exact-match rule for cookie headers therefore belongs at the header call site, and is scoped to DataCollection phase 0: always redact sensitive header values #5422.Cookie-name extra terms are kept, as a deliberately more conservative choice than Java.
SensitiveCookieNameTermscovers opaque session, sticky-routing and identity-provider cookie names (remember,oidc,pkce,nonce,__secure-,__host-,awsalb,akamai,__stripe,cognito,firebase,supabase,sb-,mfa,2fa). These are not in the spec and Java has no equivalent, so a cookie such asremember_meis filtered here but not by the Java SDK. Terms already implied by a canonical match were dropped —.sidandsessidboth already matchsidby substring — so the list contains only terms that actually add coverage.Query parameter names are decoded before matching, never before storing.
DecodeKeyForMatchingpercent-decodes a key so%74oken=secretis recognised, mirroring Java'sURLDecoderuse infilterQueryParams. Callers emit the original key and value, which spec 0.11.0 requires: encoded query parameters must be stored exactly as they appear in the URL. Used by DataCollection phase 0: scrub sensitive URL query parameters #5424.The decode is wrapped in a
catch (UriFormatException)that returns the key undecoded, matching Java'sdecodeQueryParamName.Uri.UnescapeDataStringreturns a malformed escape unchanged on modern .NET but throws on .NET Framework; CI only exercises the 4.8 runtime, where it does not throw, so thecatchis an intentionally uncovered branch rather than a missing test. It is there because we targetnet462, 4.6.2–4.7.x is untested, and DataCollection phase 0: scrub sensitive URL query parameters #5424 will feed untrusted query keys through this while enriching an event.Notes for review
Empty and null terms are ignored when matching.
"Accept".Contains("")istruein .NET, so a single empty term matches every key: in deny-list mode it filters everything, in allow-list mode it sends everything. The second is the hazard — an apparently restrictive config producing the most permissive outcome.KeyValueCollectionBehaviorstrips null and empty terms in its constructor, and every route reaches that constructor, configuration included:BindableDataCollectionOptionsbuilds throughDenyList(...)/AllowList(...). Sobehavior.Termscannot carry an empty term, and for that argument this guard is belt-and-braces. Nothing meaningful is discarded either — the two things an empty term could express are already spelledAllowList()andDenyList()with no terms.The guard is load-bearing for
additionalDenyTerms, which call sites pass in directly and which never passes through that type. That is where its tests now live; the four behavior-level cases they replace duplicatedDataCollectionOptionsTests.For reference, sentry-java places the equivalent check at match time only —
HttpUtils.containsTermteststerm != null && !term.isEmpty()— and itssetTermsdeliberately does not sanitize, so there the invariant depends on every consumer going through that helper.MatchesAnytreats a null term list as "no terms match".behavior.Termsis guaranteed non-null, butadditionalDenyTermsis genuinely nullable, so the call site passes it straight toMatchesAnyinstead of null-checking it twice.FilterKeyValueDatareturns an ordered list rather than a dictionary, preserving input order and repeated keys. A dictionary silently collapses duplicates, andSet-Cookielegitimately repeats; spec 0.15.0 also now represents cookies as an ordered array ofname=valueelements.MatchesAnyiterates by index rather thanforeach, sinceIReadOnlyList<string>allocates an enumerator where an array doesn't, and this runs per key per event.#skip-changelog
🤖 Generated with Claude Code