diff --git a/CHANGELOG.md b/CHANGELOG.md index 9472ec4027..2275799340 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/main/kotlin/io/sentry/compose/navigation3/BackStackConverter.kt b/sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackConverter.kt index 4bd0bd24e5..9a082771c2 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 924f8c4972..8f8f37398a 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 0000000000..c54490bbf9 --- /dev/null +++ b/sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/ArgumentDuplicateKeysTest.kt @@ -0,0 +1,28 @@ +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) + } +}