Repository navigation
feat(nav3): [Part 1] Define an Arguments Protocol when converting back stack entry properties into Sentry arguments - #6705
Open
0xadam-brown wants to merge 2 commits into
Conversation
This was referenced Nov 20, 2026
Contributor
|
5 of 9 tasks
Contributor
PR risk: mediumFor commit Main concerns: data sent to Sentry, reach, host performance. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
📲 Install BuildsAndroid
|
4 of 9 tasks
0xadam-brown
marked this pull request as ready for review
November 20, 2026 15:43
0xadam-brown
requested review from
markushi and
romtsn
and removed request for
a team
November 20, 2026 15:43
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-8
branch
from
November 24, 2026 10:21
122ad95 to
f4a7b52
Compare
5 of 9 tasks
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-7
branch
from
November 25, 2026 15:30
801de33 to
6937bd5
Compare
0xadam-brown
marked this pull request as draft
November 25, 2026 15:37
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-7
branch
2 times, most recently
from
November 27, 2026 15:27
c8bea42 to
1765464
Compare
0xadam-brown
changed the base branch from
feat/nav3-serial-name-mappers-7
to
feat/nav3-serial-name-mappers-base
November 27, 2026 15:36
Bring back the ArgumentSink seam so that a custom mapper's map and the SerialNameAndProperties encoder that follows write their arguments through the same TreeArgumentWriter, which enforces every size and structural limit in one place. ArgumentSanitizer now adapts a custom mapper's map with HostArgumentSource instead of recursing through it directly. Behavior is unchanged: the existing ArgumentSanitizerTest passes, apart from its warnings moving to DropArguments. Duplicate keys are rejected in key(), before a value is spent or computed, which keeps the order of checks the direct recursion had. Co-Authored-By: Claude Opus 5.5 <[email protected]>
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-8
branch
from
December 1, 2026 01:31
f4a7b52 to
d6095b5
Compare
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-base
branch
from
December 1, 2026 01:31
0441799 to
4be993a
Compare
0xadam-brown
marked this pull request as ready for review
December 1, 2026 01:49
Add KotlinxPropertiesEncoder, which encodes a @serializable back stack entry's properties as maps, lists, and scalars, for the upcoming SerialNameAndProperties mapper. It writes through the same ArgumentSink as a custom mapper's map, so the same size and structural limits apply, and it also limits how deeply serializers nest. Values under property names or map keys on Sentry's sensitive denylist are replaced with [Filtered] without running their serializers. To share the denylist, HttpUtils.containsSensitiveDataKey becomes public. Co-Authored-By: Claude Opus 5.5 <[email protected]>
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-8
branch
from
December 1, 2026 10:01
d6095b5 to
7e35dad
Compare
runningcode
reviewed
Dec 1, 2026
| * Preserves the original drop reason even if intervening code (e.g., a host app serializer) | ||
| * catches it and throws its own exception instead. | ||
| */ | ||
| val failure: DropArgumentsException? |
Contributor
There was a problem hiding this comment.
What if instead of asking all the callers to check this, we instead return something like a sealed class, Written, Dropped or Failed?
runningcode
approved these changes
Dec 1, 2026
runningcode
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Just one comment, see it below.
This branch has not been deployed
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.
PR Stack (Nav3 SerialNameAndProperties Mapper)
This stack follows the
SerialNamestack (#6780) and is based on its last PR, #6783.📜 Description
PR provides infrastructure for serializing back stack entry properties as nav arguments, subject to size and structural limits. It also applies Sentry's sensitive denylist to back stack properties, as described in the "Callouts" below.
(Note: Part 3 will introduce the
SerialNameAndPropertiesmapper that actually exposes this functionality to users; it and the updated sentry-docs are very explicit about the various issues surrounding sensitive data or PII that serializing entry properties can raise.)💡 Motivation and Context
With Nav3, host apps manage their own nav back stack, which they implement as a list of arbitrarily typed entries. In order to be displayed in Sentry, each of those entries has to be mapped to a Sentry name (e.g., ProductDetailScreen) and zero or more arguments (e.g., productId="123abc"). There are two ways for host apps to provide us with those mappings:
BackStackEntryMapper; orA new
ArgumentSinkandArgumentSourcetype create the seam that lets us support differentiated processing on the source side (the host app's logic vs built-in logic) but uniform processing on the sink side (argument pruning, protecting against constraint violation, and tree materialization).Here are the major moving parts of the new protocol:
addresses: JAVA-787 (link)
1. We filter sensitive data but not PII from back stack entry properties
This PR:
Sentry's sensitive data policy applies to "key-value data" SDKs send to Sentry on host app's behalf, including "HTTP headers, cookies, and URL query params". This PR extends the rule to "key-value data" of serialized back stack entry properties.
Note that I have not tried to filter personal data or PII. A few reasons for that:
BackStackEntryMapper, or by applying their own filters directly toSerialNameAndPropertiesBecause we don't remove any personal data or PII, the
sendDefaultPiiand data-collection options don't apply.In case you're curious, here's more info contrasting the behavior implemented here for Nav3 vs what we currently do for Nav2:
Chime in if you have thoughts.
.
⚠️ ⚠️ ⚠️ DEAR READER: YOU CAN SKIP THE REMAINDER OF THIS PR DESCRIPTION. IT ADDRESSES THE ISSUES WE DISCUSSED IN OUR CONVO ABOUT USING KOTLINX.SERIALIZATION WITH NAV3. ⚠️ ⚠️ ⚠️
(Some of the claims that follow are out-of-date, eg, this PR stack no longer introduces a weekly CI check. But they're minor, so I haven't bothered to update them.)
.
2. We use an experimental kotlinx.serialization API
We need to run the app’s serializers in order to extract nav data from back stack entries. We use an experimental kotlinx.serialization API to do so (
AbstractEncoder). AbstractEncoder lets us turn serializer output directly into Sentry arguments, filter sensitive keys before retaining their values, and stop encoding when an argument limit is exceeded. It also provides the common scalar-handling behavior that we would otherwise have to implement ourselves.There are, however, alternatives to AbstractEncoder. See the deep dive section below for more details.
🤿 Implementation Deep Dive (and Alternatives)
Setting up the problem
Kotlin serialization works by having a compiler plugin generate byte code for
Serializableclasses. That generated byte code calls into kotlinx-serialization-core APIs at runtime, some of which are internal. Host apps determine the version of kotlinx-serialization-core that’s used (as the Sentry SDK declares a compileOnly dep).So we have to worry about two issues:
This PR raises both possibilities.
Fwiw, my clanker isn’t worried about (1). The module ships no
@Serializableclasses of its own, so the only plugin-generated code that runs is the host app's, which the app compiles against the -core version it ships.W/r/t (2), both built-in mappers invoke kotlinx-serialization-core APIs in order to generate nav data based on the host app’s back stack. The APIs called by the simpler map (SerialName) are stable and non-problematic. The APIs called by the more complicated one (SerialNameAndProperties) are experimental.
The current approach: Extend AbstractEncoder
Reading properties from a
@Serializableclass is tricker than accessing that class's serial name, which is what makes the SerialNameAndProperties mapper more involved than SerialName.In order to read property values, kotlinx.serialization requires the use of an
Encoder. kotlinx-serialization-core doesn’t supply its own encoder, so I've introduced an AbstractEncoder implementation. That API is experimental, but our use is similar to what androidx does in its SavedStateEncoder. SerialNameAndProperties gives the host app our AbstractEncoder implementation and has the host app’s own serializer walk each nav back stack entry. We then generate Sentry data from each of the reported entries.To ensure our use of the experimental AbstractEncoder is safe, the
SerialNameAndPropertiesmapper (Part 3) checks the encoder when it's created: it encodes a known value with kotlinx.serialization's built-in serializers and compares the output with its known encoding. If the check fails or the output doesn't match, entries keep their names, but every entry's arguments are dropped withencoding_failed, since recording wrong arguments is worse than recording none.The big win in the current approach is the ability to support built-in maps for both SAGP use (forthcoming) and manually. The latter matters because back stack entries can contain sensitive data, and manual support means host apps can special-case sensitive entries via a custom
BackStackEntryMapperand fall back for everything else toSerialNameAndProperties. The performance of the current approach is also on the better side of our available options.The downsides are that we have to depend on an experimental API, guard against drift, and drop every entry's arguments (while keeping names) if the host app's version of kotlinx-serialization-core isn't compatible. There are also some downsides w/r/t our current Kotlin dependency management, discussed in the next section.
Impacts on our Kotlin dependency management
[1] The weekly CI job ties our SDK-wide Kotlin version to kotlinx.serialization.
Our test fixtures and the R8 check app are compiled by our compiler against the latest kotlinx.serialization. The plugin checks the runtime jar's Require-Kotlin-Version, and a compiler can only read metadata from its own version and the next one.
If kotlinx.serialization moves more than one Kotlin version ahead of us, the weekly bump PR stops compiling. We'd then have to upgrade Kotlin repo-wide or pause the bumps. This affects CI only, not what we ship, but it sets a minimum pace for the repo's Kotlin upgrades.
[2] Newer kotlinx-serialization-core versions may require updating our SerialNameAndProperties implementation
We should make sure we always support AbstractEncoder APIs from whatever our current kotinx-serialization-core floor is up to the latest -core version, including implementing against multiple versions' APIs. Otherwise, apps that use unsupported -core versions would get no arguments for any destination.
Note: Nav3 upgrades actually help us here. If a newer version of Nav3 requires a newer kotlinx-serialization-core version, then our practical minimum in apps rises, which makes it easier to raise our floor -core version.
Alternatives
Some other options we could consider if we don't like the downsides of the
AbstractEncoderapproach.SerialName• No dependency on an experimental API.
implementationdependency (bad) orcompileOnly(good). WithcompileOnly, apps without JSON still get destination names, but their entries won't record any arguments.AbstractEncoderand the encoder compatibility check, and capture properties via JSON's stable public API instead.• Numbers round-trip through strings, which costs extra parsing and can lose fidelity for some numeric types.
• Size limits are checked too late: oversized entries are fully encoded before being rejected, and cyclic entries cause a stack overflow that crashes the app.
• Higher class-loading cost on first use if the app doesn't already use JSON.
• Like all Encoder approaches, can only support
@Serializableback stack entries.Any option that uses an Encoder (including our current approach) requires the following, although the details of what each involves differ based on the option:
What differs among the Encoder-based options is whether we need an encoder compatibility check and whether we make use of an experimental API (AbstractEncoder). There are also options that don't involve an Encoder...
• Drops the use of
AbstractEncoder, the encoder compatibility check, and reliance on kotlinx.serialization's consumer rules.• Could cover back stack entries that aren't
@Serializable.• Without those rules, sensitive-data filtering breaks (e.g.,
authTokenbecomesa), so secrets could be recorded.• Wouldn't match serialization semantics out of the box (e.g., kotlinx's
@Transient,@SerialNameon properties, delegated/synthetic fields, value classes).• We'd have to figure out how to follow only relevant references in our property walk.
• Worse performance than serializers.
• Drops the use of
AbstractEncoder, the encoder compatibility check, and reliance on kotlinx.serialization's consumer rules.• Compiled by the app's own toolchain; survives R8 like any other code.
• Fast, and avoids reflection.
• Sensitive-data filtering can use real property names.
• Could cover back stack entries that aren't
@Serializable.• Unclear whether apps can still special-case sensitive back stack entries and fall back to generated mapping for the rest (e.g., via source generation, or an SDK shim that discovers the generated mapper at runtime).
• Significant new tooling. Needs to: (i) find entry classes across modules; (ii) read Kotlin property metadata in the plugin; (iii) access private properties, probably by injecting a method into each back stack entry class; (iv) support incremental builds.
• Adds build-time cost.
• The sentry-java Kotlin upgrade concerns listed above go away, but are replaced by whatever concerns SAGP's version matrix creates (Kotlin x AGP x SAGP)
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Continue with Part 2: Add a lazily encoding argument source.
#skip-changelog