diff --git a/extensions/csrf-reactive/runtime/src/main/java/io/quarkus/csrf/reactive/runtime/CsrfRequestResponseReactiveFilter.java b/extensions/csrf-reactive/runtime/src/main/java/io/quarkus/csrf/reactive/runtime/CsrfRequestResponseReactiveFilter.java index 8fcba71e714b4..4c5eaa1517719 100644 --- a/extensions/csrf-reactive/runtime/src/main/java/io/quarkus/csrf/reactive/runtime/CsrfRequestResponseReactiveFilter.java +++ b/extensions/csrf-reactive/runtime/src/main/java/io/quarkus/csrf/reactive/runtime/CsrfRequestResponseReactiveFilter.java @@ -97,15 +97,16 @@ public void filter(ResteasyReactiveContainerRequestContext requestContext, Routi } else if (config.verifyToken) { // unsafe HTTP method, token is required - if (!isMatchingMediaType(requestContext.getMediaType(), MediaType.APPLICATION_FORM_URLENCODED_TYPE) - && !isMatchingMediaType(requestContext.getMediaType(), MediaType.MULTIPART_FORM_DATA_TYPE)) { + MediaType mediaType = requestContext.getMediaType(); + if (!isMatchingMediaType(mediaType, MediaType.APPLICATION_FORM_URLENCODED_TYPE) + && !isMatchingMediaType(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE)) { if (config.requireFormUrlEncoded) { - LOG.debugf("Request has the wrong media type: %s", requestContext.getMediaType().toString()); + LOG.debugf("Request has the wrong media type: %s", mediaType); requestContext.abortWith(badClientRequest()); return; } else { - LOG.debugf("Request has the media type: %s, skipping the token verification", - requestContext.getMediaType().toString()); + LOG.debugf("Request has the media type: %s, skipping the token verification", + mediaType); return; } } @@ -148,7 +149,16 @@ public void filter(ResteasyReactiveContainerRequestContext requestContext, Routi } } + /** + * Compares if {@link MediaType} matches the expected type. + *

+ * Note: isCompatible is taking wildcards, which is why we individually compare types and subtypes, + * so if someone sends a Content-Type: * it will be marked as compatible which is a problem + */ private static boolean isMatchingMediaType(MediaType contentType, MediaType expectedType) { + if (contentType == null) { + return (expectedType == null); + } return contentType.getType().equals(expectedType.getType()) && contentType.getSubtype().equals(expectedType.getSubtype()); }