From d27f833009d73a7055f8512584d00b20bf9ebfbc Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 20 Nov 2026 15:41:01 +0100 Subject: [PATCH 1/2] fix(nav3): Reject colliding navigation argument keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop an entry’s arguments when distinct map keys stringify identically, rather than silently reporting an incomplete map. Refs JAVA-787 --- .../compose/navigation3/BackStackConverter.kt | 7 ++++++ .../navigation3/BackStackEntryMapper.kt | 7 +++--- .../navigation3/ArgumentDuplicateKeysTest.kt | 25 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt diff --git a/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackConverter.kt b/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackConverter.kt index 4bd0bd24e57..9a082771c20 100644 --- a/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackConverter.kt +++ b/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackConverter.kt @@ -179,6 +179,12 @@ internal class BackStackConverter( for ((key, childValue) in value) { val keyString = key.toString() consumeCharacters(keyString.length) + if (sanitized.containsKey(keyString)) { + throw DropSubtree( + "Nav3 map keys stringify to the same string. Dropping this entry's arguments.", + ArgumentDropReason.DUPLICATE_KEY, + ) + } sanitized[keyString] = sanitizeValue(childValue, depth + 1) } return sanitized @@ -457,6 +463,7 @@ internal enum class ArgumentDropReason( ) { CHARACTER_LIMIT("max_character_limit_exceeded", exhaustsUpdateBudget = true), + DUPLICATE_KEY("duplicate_key"), INVALID_STRUCTURE("invalid_structure"), MAPPING_FAILED("mapping_failed"), MAX_COUNT("max_argument_count_exceeded", exhaustsUpdateBudget = true), diff --git a/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackEntryMapper.kt b/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackEntryMapper.kt index 924f8c49728..8f8f37398a6 100644 --- a/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackEntryMapper.kt +++ b/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackEntryMapper.kt @@ -107,11 +107,12 @@ public class SentryBackStackEntry( * * **Arguments fall back to `toString()` or nothing** * - * All non-supported argument types are stringified via `toString()`. + * All non-supported argument types are stringified via `toString()`, as are map keys. * * No arguments will be recorded for a back stack entry if [map] throws or returns `null`, or if its - * arguments are cyclic, too deeply nested, or too large. If the SDK drops an entry's arguments, it - * adds a `dropped_by_sentry` field and corresponding reason in the Sentry UI. + * arguments are cyclic, too deeply nested, too large, or contain map keys that stringify to the + * same string. If the SDK drops an entry's arguments, it adds a `dropped_by_sentry` field and + * corresponding reason (e.g., `duplicate_key`) in the Sentry UI. * * **Using kotlinx.serialization** * diff --git a/sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt b/sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt new file mode 100644 index 00000000000..51ba8fca50c --- /dev/null +++ b/sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt @@ -0,0 +1,25 @@ +package io.sentry.compose.navigation3 + +import com.google.common.truth.Truth.assertThat +import io.sentry.NoOpLogger +import org.junit.Test + +class ArgumentDuplicateKeysTest { + @Test + fun `stringified key collisions drop only that entry`() { + val sanitizer = + BackStackConverter.ArgumentSanitizer( + NoOpLogger.getInstance(), + BackStackConverter.WarningState(), + ) + val result = + sanitizer.sanitizeEntry( + mapOf("nested" to linkedMapOf(1 to "first", "1" to "second")), + ) + assertThat(result.values).isEmpty() + assertThat(result.dropReason).isEqualTo(ArgumentDropReason.DUPLICATE_KEY) + val next = sanitizer.sanitizeEntry(mapOf("id" to 123)) + assertThat(next.dropReason).isNull() + assertThat(next.values).containsExactly("id", 123) + } +} From 043d7190688eb6c39ac137dfcdcc04c1f307078c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 20 Nov 2026 15:41:45 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + .../io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9472ec4027c..2275799340e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes +- Nav3: Drop an entry’s arguments with `duplicate_key` when distinct map keys stringify to the same key, instead of silently overwriting a value ([#6714](https://github.com/getsentry/sentry-java/pull/6714)) - Kotlin now sees `Attachment.getBytes()`, `Device.getArchs()`, `Spring.getActiveProfiles()` and `JsonSerializationUtils.bytesFrom(...)` as nullable, because `@Nullable` now annotates the returned array instead of its elements ([#6558](https://github.com/getsentry/sentry-java/pull/6558)) - Shake-to-report no longer leaks the first Activity that resumes after `Sentry.init` ([#6686](https://github.com/getsentry/sentry-java/pull/6686)) diff --git a/sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt b/sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt index 51ba8fca50c..c54490bbf99 100644 --- a/sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt +++ b/sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt @@ -5,6 +5,7 @@ import io.sentry.NoOpLogger import org.junit.Test class ArgumentDuplicateKeysTest { + @Test fun `stringified key collisions drop only that entry`() { val sanitizer = @@ -12,12 +13,14 @@ class ArgumentDuplicateKeysTest { NoOpLogger.getInstance(), BackStackConverter.WarningState(), ) + val result = sanitizer.sanitizeEntry( mapOf("nested" to linkedMapOf(1 to "first", "1" to "second")), ) assertThat(result.values).isEmpty() assertThat(result.dropReason).isEqualTo(ArgumentDropReason.DUPLICATE_KEY) + val next = sanitizer.sanitizeEntry(mapOf("id" to 123)) assertThat(next.dropReason).isNull() assertThat(next.values).containsExactly("id", 123)