Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach request body for application/x-www-form-urlencoded requests in Spring #3731

Merged
merged 3 commits into from
Oct 4, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
- You may now set `forceInit=true` (`force-init` for `.properties` files) to ensure a call to Sentry.init / SentryAndroid.init takes effect
- Add force init option to Android Manifest ([#3675](https://github.com/getsentry/sentry-java/pull/3675))
- Use `<meta-data android:name="io.sentry.force-init" android:value="true" />` to ensure Sentry Android auto init is not easily overwritten
- Attach request body for `application/x-www-form-urlencoded` requests in Spring ([#3731](https://github.com/getsentry/sentry-java/pull/3731))
- Previously request body was only attached for `application/json` requests

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class io/sentry/spring/boot/jakarta/SentryLogbackAppenderAutoConfiguratio
public fun sentryLogbackInitializer (Lio/sentry/spring/boot/jakarta/SentryProperties;)Lio/sentry/spring/boot/jakarta/SentryLogbackInitializer;
}

public class io/sentry/spring/boot/jakarta/SentryLogbackInitializer : org/springframework/context/event/GenericApplicationListener {
public fun <init> (Lio/sentry/spring/boot/jakarta/SentryProperties;)V
public fun onApplicationEvent (Lorg/springframework/context/ApplicationEvent;)V
public fun supportsEventType (Lorg/springframework/core/ResolvableType;)Z
}

public class io/sentry/spring/boot/jakarta/SentryProperties : io/sentry/SentryOptions {
public fun <init> ()V
public fun getExceptionResolverOrder ()I
Expand Down
6 changes: 6 additions & 0 deletions sentry-spring-boot/api/sentry-spring-boot.api
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class io/sentry/spring/boot/SentryLogbackAppenderAutoConfiguration {
public fun sentryLogbackInitializer (Lio/sentry/spring/boot/SentryProperties;)Lio/sentry/spring/boot/SentryLogbackInitializer;
}

public class io/sentry/spring/boot/SentryLogbackInitializer : org/springframework/context/event/GenericApplicationListener {
public fun <init> (Lio/sentry/spring/boot/SentryProperties;)V
public fun onApplicationEvent (Lorg/springframework/context/ApplicationEvent;)V
public fun supportsEventType (Lorg/springframework/core/ResolvableType;)Z
}

public class io/sentry/spring/boot/SentryProperties : io/sentry/SentryOptions {
public fun <init> ()V
public fun getExceptionResolverOrder ()I
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ private boolean qualifiesForCaching(
return maxRequestBodySize != RequestSize.NONE
&& contentLength != -1
&& contentType != null
&& MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_JSON)
&& shouldCacheMimeType(contentType)
&& ((maxRequestBodySize == SMALL && contentLength < 1000)
|| (maxRequestBodySize == MEDIUM && contentLength < 10000)
|| maxRequestBodySize == ALWAYS);
}

private static boolean shouldCacheMimeType(String contentType) {
return MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_JSON)
|| MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED);
}

static final class RequestBodyExtractingEventProcessor implements EventProcessor {
private final @NotNull RequestPayloadExtractor requestPayloadExtractor =
new RequestPayloadExtractor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class SentrySpringFilterTest {
TestParams(maxRequestBodySize = SMALL, body = "x".repeat(1001), expectedToBeCached = false),
TestParams(maxRequestBodySize = MEDIUM, body = "x".repeat(1001), expectedToBeCached = true),
TestParams(maxRequestBodySize = MEDIUM, body = "x".repeat(10001), expectedToBeCached = false),
TestParams(maxRequestBodySize = ALWAYS, body = "x".repeat(10001), expectedToBeCached = true)
TestParams(maxRequestBodySize = ALWAYS, body = "x".repeat(10001), expectedToBeCached = true),
TestParams(maxRequestBodySize = SMALL, body = "xxx", contentType = "application/x-www-form-urlencoded", expectedToBeCached = true)
)

params.forEach { param ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ private boolean qualifiesForCaching(
return maxRequestBodySize != RequestSize.NONE
&& contentLength != -1
&& contentType != null
&& MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_JSON)
&& shouldCacheMimeType(contentType)
&& ((maxRequestBodySize == SMALL && contentLength < 1000)
|| (maxRequestBodySize == MEDIUM && contentLength < 10000)
|| maxRequestBodySize == ALWAYS);
}

private static boolean shouldCacheMimeType(String contentType) {
return MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_JSON)
|| MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED);
}

static final class RequestBodyExtractingEventProcessor implements EventProcessor {
private final @NotNull RequestPayloadExtractor requestPayloadExtractor =
new RequestPayloadExtractor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class SentrySpringFilterTest {
TestParams(maxRequestBodySize = SMALL, body = "x".repeat(1001), expectedToBeCached = false),
TestParams(maxRequestBodySize = MEDIUM, body = "x".repeat(1001), expectedToBeCached = true),
TestParams(maxRequestBodySize = MEDIUM, body = "x".repeat(10001), expectedToBeCached = false),
TestParams(maxRequestBodySize = ALWAYS, body = "x".repeat(10001), expectedToBeCached = true)
TestParams(maxRequestBodySize = ALWAYS, body = "x".repeat(10001), expectedToBeCached = true),
TestParams(maxRequestBodySize = SMALL, body = "xxx", contentType = "application/x-www-form-urlencoded", expectedToBeCached = true)
)

params.forEach { param ->
Expand Down
Loading