Repository navigation
feat(nav3): [Part 3] Define size and sensitive-data policies used when converting back stack entry properties into Sentry arguments - #6705
Open
0xadam-brown wants to merge 1 commit into
Conversation
This was referenced Nov 20, 2026
Contributor
|
5 of 9 tasks
Contributor
PR risk: mediumFor commit Main concerns: public contract, data sent to Sentry, reach. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
This was referenced Nov 20, 2026
📲 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 23, 2026 13:11
546f3b8 to
d2d0c6e
Compare
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-7
branch
from
November 23, 2026 13:11
8e69a38 to
3aa6d86
Compare
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-8
branch
from
November 23, 2026 14:28
d2d0c6e to
782f546
Compare
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-7
branch
from
November 23, 2026 14:28
3aa6d86 to
a145470
Compare
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-7
branch
from
November 23, 2026 15:34
a145470 to
37d6b32
Compare
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-8
branch
from
November 23, 2026 15:34
782f546 to
122ad95
Compare
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-7
branch
from
November 24, 2026 10:21
37d6b32 to
801de33
Compare
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
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 Serial Name Mappers)
Former parts 1–3 merged into
mainas #6697, #6698, and #6699; preparatory refactors merged in #6749. Two other former parts merged separately as #6713 and #6714.📜 Description
PR provides infrastructure for serializing back stack entry properties as nav arguments, subject to size and structural limits. Applies Sentry's sensitive denylist to back stack properties, as described below.
(Note: the next PR will introduce the mapper 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
Automatically turning route properties into navigation arguments needs a consistent policy for data, payload limits, and fields that contain secrets. The built-in path should follow the same structural rules as custom mapper output.
addresses: JAVA-787 (link)
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.
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 PR introduces two
@Serialiable“probe” classes that our own compiler plugin generates. Like all@Serializableclasses, those probes invoke internal kotlinx-serialization-core APIs. Even though we don’t control the kotlinx-serilization-core version, my clanker thinks that’s fine b/c the Kotlin folks have historically been careful to preserve compatibility across plugin <> -core versions.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, this PR uses the "probe" classes mentioned above. Upon the first attempt to serialize a back stack entry, the probes will disable the feature and return “/unknown” for all entries if they discover that the host app’s -core version is incompatible with what we compiled against.
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 fail gracefully (but utterly) 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 see "
/unknown" results for all destinations.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 both probes, 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 to include our "probe" classes 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 probes, 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 probes, 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 4: Add a lazily encoding argument source.
#skip-changelog