Skip to content

Commit 6fab6c4

Browse files
authored
Merge pull request #6065 from getsentry/ref/data-collection-narrow-catches
fix(core): [Data Collection 24] Narrow utility exception handling
2 parents 48709b5 + f366516 commit 6fab6c4

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎sentry/src/main/java/io/sentry/util/GraphqlUtils.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.sentry.JsonObjectReader;
55
import io.sentry.SentryLevel;
66
import io.sentry.SentryOptions;
7+
import java.io.IOException;
78
import java.io.StringReader;
89
import java.io.StringWriter;
910
import java.util.ArrayList;
@@ -56,7 +57,7 @@ private GraphqlUtils() {}
5657
final @NotNull StringWriter writer = new StringWriter();
5758
options.getSerializer().serialize(filtered, writer);
5859
return writer.toString();
59-
} catch (Throwable e) {
60+
} catch (IOException | NumberFormatException e) {
6061
options.getLogger().log(SentryLevel.ERROR, "Failed to filter GraphQL request body.", e);
6162
return null;
6263
}

‎sentry/src/main/java/io/sentry/util/HttpUtils.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io.sentry.HttpStatusCodeRange;
66
import io.sentry.KeyValueCollectionBehavior;
7+
import java.io.UnsupportedEncodingException;
78
import java.net.URLDecoder;
89
import java.util.Arrays;
910
import java.util.LinkedHashMap;
@@ -127,7 +128,7 @@ public static boolean containsSensitiveHeader(final @NotNull String header) {
127128
private static @NotNull String decodeQueryParamName(final @NotNull String name) {
128129
try {
129130
return URLDecoder.decode(name, "UTF-8");
130-
} catch (Throwable ignored) {
131+
} catch (IllegalArgumentException | UnsupportedEncodingException ignored) {
131132
return name;
132133
}
133134
}

‎sentry/src/test/java/io/sentry/util/GraphqlUtilsTest.kt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ class GraphqlUtilsTest {
8282
assertThat(result).isNull()
8383
}
8484

85+
@Test
86+
fun `returns null for a GraphQL request body containing a malformed unicode escape`() {
87+
val options = SentryOptions().also { it.dataCollection.graphql.setDocument(false) }
88+
89+
val result = GraphqlUtils.filterRequestBody("""{"query":"\u12G4"}""", options)
90+
91+
assertThat(result).isNull()
92+
}
93+
8594
private companion object {
8695
const val REQUEST_BODY =
8796
"""{"operationName":"GetUser","variables":{"id":"123"},"query":"query { viewer { name } }"}"""

0 commit comments

Comments
 (0)