Skip to content

Commit

Permalink
fix: Improve handling of broken accept headers in MediaTypeHeaderDele…
Browse files Browse the repository at this point in the history
…gate.parse(..) within resteasy-reactive

Previously, a "broken" MIME-type in an access header could trigger an StringIndexOutOfBoundsException during MediaTypeHeaderDelegate.parse(..) instead of the more suitable IllegalArgumentException.

Example: "Accept: x; /x"

This PR now throws an IllegalArgumentException in case of a broken MIME-type like in the example.

Fixes quarkusio#36159

(cherry picked from commit 84d6c5d)
  • Loading branch information
thomasdarimont authored and gsmet committed Oct 3, 2023
1 parent 3dc0261 commit edb5a19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ private static MediaType internalParse(String type) {
} else {
major = type.substring(0, typeIndex);
if (paramIndex > -1) {
if (typeIndex + 1 > paramIndex) {
throw new IllegalArgumentException("Failed to parse media type " + type);
}
subtype = type.substring(typeIndex + 1, paramIndex);
} else {
subtype = type.substring(typeIndex + 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jboss.resteasy.reactive.common.headers;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class MediaTypeHeaderDelegateTest {

public void parsingBrokenMediaTypeShouldThrowIllegalArgumentException_minimized() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
MediaTypeHeaderDelegate.parse("x; /x");
});
}

@Test
public void parsingBrokenMediaTypeShouldThrowIllegalArgumentException_actual() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
MediaTypeHeaderDelegate.parse("() { ::}; echo \"NS:\" $(/bin/sh -c \"expr 123456 - 123456\")");
});
}

}

0 comments on commit edb5a19

Please sign in to comment.