From acf15f2a8067f7e4cf5838342cecfa0b78a174fb Mon Sep 17 00:00:00 2001
From: Bartosz Spyrko-Smietanko <bspyrkos@redhat.com>
Date: Thu, 16 Apr 2020 14:01:17 +0100
Subject: [PATCH] [RESTEASY-2559] Improper validation of response header in
 MediaTypeHeaderDelegate.java class

---
 .../plugins/delegates/MediaTypeHeaderDelegate.java |  1 +
 .../test/mediatype/MediaTypeHeaderTest.java        | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/mediatype/MediaTypeHeaderTest.java

diff --git a/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/delegates/MediaTypeHeaderDelegate.java b/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/delegates/MediaTypeHeaderDelegate.java
index ccf08a4622..4e48e622b1 100644
--- a/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/delegates/MediaTypeHeaderDelegate.java
+++ b/jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/delegates/MediaTypeHeaderDelegate.java
@@ -49,6 +49,7 @@ protected static boolean isValid(String str)
             case '[':
             case ']':
             case '=':
+            case '\n':
                return false;
             default:
                break;
diff --git a/testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/mediatype/MediaTypeHeaderTest.java b/testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/mediatype/MediaTypeHeaderTest.java
new file mode 100644
index 0000000000..e46f018f7f
--- /dev/null
+++ b/testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/mediatype/MediaTypeHeaderTest.java
@@ -0,0 +1,14 @@
+package org.jboss.resteasy.test.mediatype;
+
+import org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate;
+import org.junit.Test;
+
+public class MediaTypeHeaderTest {
+
+   @Test(expected = IllegalArgumentException.class)
+   public void testNewLineInHeaderValueIsRejected() {
+      MediaTypeHeaderDelegate delegate = new MediaTypeHeaderDelegate();
+
+      delegate.fromString("foo/bar\n");
+   }
+}
