Skip to content

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
feat/nav3-serial-name-mappers-7from
feat/nav3-serial-name-mappers-8
Open

0xadam-brown wants to merge 1 commit into
feat/nav3-serial-name-mappers-7from
feat/nav3-serial-name-mappers-8

Conversation

@0xadam-brown

@0xadam-brown 0xadam-brown commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

PR Stack (Nav3 Serial Name Mappers)

Former parts 1–3 merged into main as #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)

⚠️ Callouts

We filter sensitive data but not PII from back stack entry properties

This PR:

  1. continues to pass along custom mapper output as-is to the Sentry backend, but
  2. filters built-in mapper properties through Sentry's sensitive denylist.

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:

  • we don't do so for Nav2 (in fact, Nav2 doesn't filter sensitive data either, which is likely an oversight)
  • other SDKs don't do so
  • our coverage would be patchy / we'd have to figure out a policy for which keys we'd filter and which not
  • the number of false positives could be large
  • host apps are able to filter via a custom BackStackEntryMapper, or by applying their own filters directly to SerialNameAndProperties

Because we don't remove any personal data or PII, the sendDefaultPii and 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:

nav2 vs nav3 sensitive data and PII treatment

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 Serializable classes. 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:

  1. Plugin-generated byte code calling kotlinx-serialization-core APIs that are missing or have changed semantics.
  2. SDK code calling the same.

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 @Serializable classes, 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 @Serializable class 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 BackStackEntryMapper and fall back for everything else to SerialNameAndProperties. 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 AbstractEncoder approach.

Options that use an Encoder Pros Cons
1. Only support SerialName • Lets us remove both probes and the serialization Gradle plugin from the module's main build. We'd no longer ship any plugin-generated code in our AAR.
• No dependency on an experimental API.
• No property capture: apps that want arguments must write a custom mapper for all of their back stack entries.
2. Use kotlinx-serialization-json, either as an implementation dependency (bad) or compileOnly (good). With compileOnly, apps without JSON still get destination names, but their entries won't record any arguments. • We could drop AbstractEncoder and both probes, and capture properties via JSON's stable public API instead. • Roughly double the allocations of the current approach: JSON builds its own tree, then we convert it to ours.
• 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 @Serializable back 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:

  • R8 emulator matrix tests
  • A weekly CI check against the latest kotlinx-serialization-core version

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

Options that don't use an Encoder Pros Cons
3. Use reflection: (more pain than it's worth). • No dependency on kotlinx.serialization.
• Drops the use of AbstractEncoder, the probes, and reliance on kotlinx.serialization's consumer rules.
• Could cover back stack entries that aren't @Serializable.
• We'd need consumer rules that keep property/field names for all apps using our built-in mappers; otherwise R8 obfuscates them.
• Without those rules, sensitive-data filtering breaks (e.g., authToken becomes a), so secrets could be recorded.
• Wouldn't match serialization semantics out of the box (e.g., kotlinx's @Transient, @SerialName on 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.
4. Have SAGP do the mapping: SAGP reads properties by their real names at compile time. • No runtime dependency on kotlinx.serialization.
• 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.
• Only available to apps that use SAGP.
• 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?

  • Unit tests
  • R8 tests
  • New sample app facilities + manual clanker tests

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Continue with Part 4: Add a lazily encoding argument source.

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

#skip-changelog

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against f4a7b52

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit f4a7b52.

Main concerns: public contract, data sent to Sentry, reach.

Rules that block low also fired:

  • R4: a public API record changed: sentry/api/sentry.api

This label is a hint for reviewers, not an approval.

@sentry

sentry Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.65.1 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 20, 2026
@0xadam-brown 0xadam-brown changed the title feat(nav3): [Nav3 Mappers 8] Define bounded property encoding feat(nav3): [Part 8] Define bounded property encoding Nov 20, 2026
@0xadam-brown 0xadam-brown changed the title feat(nav3): [Part 8] Define bounded property encoding feat(nav3): [Part 8] Define size and sensitive-data policies used when converting back stack entry properties into Sentry arguments Nov 20, 2026
@0xadam-brown
0xadam-brown marked this pull request as ready for review November 20, 2026 15:43
@0xadam-brown
0xadam-brown requested review from a team and adinauer as code owners November 20, 2026 15:43
@0xadam-brown
0xadam-brown requested review from markushi and romtsn and removed request for a team November 20, 2026 15:43
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 20, 2026
@0xadam-brown 0xadam-brown added the sanity-check PR needs a lightweight review for obvious issues label Nov 20, 2026
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-8 branch from 546f3b8 to d2d0c6e Compare November 23, 2026 13:11
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-7 branch from 8e69a38 to 3aa6d86 Compare November 23, 2026 13:11
@github-actions github-actions Bot removed the risk: medium PR risk score: medium label Nov 23, 2026
@0xadam-brown 0xadam-brown changed the title feat(nav3): [Part 8] Define size and sensitive-data policies used when converting back stack entry properties into Sentry arguments feat(nav3): [Part 6] Define size and sensitive-data policies used when converting back stack entry properties into Sentry arguments Nov 23, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-8 branch from d2d0c6e to 782f546 Compare November 23, 2026 14:28
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-7 branch from 3aa6d86 to a145470 Compare November 23, 2026 14:28
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-7 branch from a145470 to 37d6b32 Compare November 23, 2026 15:34
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-8 branch from 782f546 to 122ad95 Compare November 23, 2026 15:34
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-7 branch from 37d6b32 to 801de33 Compare November 24, 2026 10:21
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-8 branch from 122ad95 to f4a7b52 Compare November 24, 2026 10:21
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 24, 2026
@0xadam-brown 0xadam-brown changed the title feat(nav3): [Part 6] Define size and sensitive-data policies used when converting back stack entry properties into Sentry arguments feat(nav3): [Part 3] Define size and sensitive-data policies used when converting back stack entry properties into Sentry arguments Nov 24, 2026

This branch has not been deployed

No deployments
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 sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant