Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ internal class BackStackConverter<T : Any>(
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
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Any, Any>(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)
}
}
Loading