[java-plugin-shibd] branch main updated: JSHIBD-30 - Invalid charset parameter to Content-Type header rejected

Codeberg noreply at shibboleth.net
Mon Nov 9 16:26:08 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch main
in repository java-plugin-shibd.

View the commit online:
https://codeberg.org/Shibboleth/java-plugin-shibd/commit/e91c11e7f8cc086a1844de30809b21045230f5c3

The following commit(s) were added to refs/heads/main by this push:
     new e91c11e  JSHIBD-30 - Invalid charset parameter to Content-Type header rejected
e91c11e is described below

commit e91c11e7f8cc086a1844de30809b21045230f5c3
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Mon Nov 9 11:25:22 2026 -0500

    JSHIBD-30 - Invalid charset parameter to Content-Type header rejected
    
    https://shibboleth.atlassian.net/browse/JSHIBD-30
    
    Use our MediaType support routine.
---
 .../shibboleth/sp/messaging/RemotedHttpServletRequest.java  | 11 +++++++++--
 .../net/shibboleth/sp/profile/impl/PreservePostData.java    | 13 +++++++++++--
 .../shibboleth/sp/profile/impl/PreservePostDataTest.java    | 13 +++++++++++--
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java b/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
index 1f81bfe..23c3970 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
@@ -38,6 +38,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 import java.util.TimeZone;
 
 import javax.annotation.Nonnull;
@@ -65,10 +66,12 @@ import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.collection.Pair;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.net.URISupport;
+import net.shibboleth.shared.servlet.HttpServletSupport;
 import net.shibboleth.sp.ddf.DDF;
 
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Multimap;
+import com.google.common.net.MediaType;
 
 
 /**
@@ -136,6 +139,10 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
                 .onMalformedInput(CodingErrorAction.REPORT)
                 .onUnmappableCharacter(CodingErrorAction.REPORT);
 
+    /** Form encoding media type. */
+    @Nonnull private static final Set<MediaType> formMediaType =
+            CollectionSupport.singleton(MediaType.parse("application/x-www-form-urlencoded"));
+    
     /** Underlying object containing remoted data. */
     @Nonnull private final DDF obj;
     
@@ -144,7 +151,7 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
     
     /** Decoder to apply to byte array data. */
     @Nonnull private CharsetDecoder decoder;
-    
+        
     /** Cookie array. */
     @NonnullElements private List<Cookie> cookies;
     
@@ -266,7 +273,7 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
                 }
             }
             
-            if ("application/x-www-form-urlencoded".equals(getContentType())) {
+            if (HttpServletSupport.validateContentType(this, formMediaType, false, false)) {
                 final byte[] body = obj.getmember("body").unsafe_string();
                 if (body != null) {
                     final List<Pair<String,String>> qparams =
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PreservePostData.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PreservePostData.java
index ef90e40..e0b7d41 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PreservePostData.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PreservePostData.java
@@ -18,6 +18,7 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.time.Duration;
 import java.time.Instant;
+import java.util.Set;
 import java.util.function.Function;
 
 import javax.annotation.Nonnull;
@@ -31,19 +32,23 @@ import org.opensaml.storage.StorageRecord;
 import org.opensaml.storage.StorageService;
 import org.slf4j.Logger;
 
+import com.google.common.net.MediaType;
 import com.google.common.net.UrlEscapers;
 
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.annotation.constraint.Positive;
+import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.net.CookieManager;
+import net.shibboleth.shared.net.MediaTypeSupport;
 import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.security.IdentifierGenerationStrategy;
 import net.shibboleth.shared.security.IdentifierGenerationStrategy.ProviderType;
+import net.shibboleth.shared.servlet.HttpServletSupport;
 import net.shibboleth.sp.context.AgentRequestContext;
 import net.shibboleth.sp.context.StateDataContext;
 import net.shibboleth.sp.ddf.DDF;
@@ -72,6 +77,10 @@ public class PreservePostData extends AbstractApplicationAction {
     /** Default cookie prefix. */
     @Nonnull @NotEmpty static public String DEFAULT_COOKIE_PREFIX = "_shibsp_post";
     
+    /** Form encoding media type. */
+    @Nonnull private static final Set<MediaType> formMediaType =
+            CollectionSupport.singleton(MediaType.parse("application/x-www-form-urlencoded"));
+    
     /** Class logger. */
     @Nonnull private Logger log = LoggerFactory.getLogger(PreservePostData.class);
     
@@ -312,7 +321,7 @@ public class PreservePostData extends AbstractApplicationAction {
      * @return submitted data or null
      */
     @Nullable private String getSubmittedData() {
-        
+                
         // First see if anything fresh is present, indicating a POST.
         byte[] raw = null;
         
@@ -331,7 +340,7 @@ public class PreservePostData extends AbstractApplicationAction {
         final String contentType = input.getmember(RemotedHttpServletRequest.STRUCTURE_NAME)
                 .getmember(RemotedHttpServletRequest.CONTENT_TYPE)
                 .string();
-        if (!"application/x-www-form-urlencoded".equals(contentType)) {
+        if (!MediaTypeSupport.validateContentType(contentType, formMediaType, false, false)) {
             log.warn("{} Unsupported content type: {}", getLogPrefix(), contentType);
             return null;
         }
diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/PreservePostDataTest.java b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/PreservePostDataTest.java
index 8fe26af..f459a6d 100644
--- a/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/PreservePostDataTest.java
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/PreservePostDataTest.java
@@ -107,7 +107,8 @@ public class PreservePostDataTest extends BaseApplicationActionTest {
 
         input = new DDF(null).structure();
         final DDF http = input.addmember(RemotedHttpServletRequest.STRUCTURE_NAME);
-        http.addmember(RemotedHttpServletRequest.CONTENT_TYPE).string("application/x-www-form-urlencoded");
+        // Attach a charset to the MIME type to ensure it is properly ignored, as that's illegal for this type.
+        http.addmember(RemotedHttpServletRequest.CONTENT_TYPE).string("application/x-www-form-urlencoded; charset=UTF-8");
         http.addmember(RemotedHttpServletRequest.BODY).unsafe_string(TEST_DATA.getBytes());
         arc.setInput(input);
 
@@ -136,12 +137,20 @@ public class PreservePostDataTest extends BaseApplicationActionTest {
     }
 
     @Test
-    public void testWrongType() {
+    public void testNoType() {
         input.addmember(RemotedHttpServletRequest.STRUCTURE_NAME).getmember(RemotedHttpServletRequest.CONTENT_TYPE).remove();
         final Event event = action.execute(src);
         ActionTestingSupport.assertProceedEvent(event);
         Assert.assertEquals(response.getCookies().length, 0);
     }
+
+    @Test
+    public void testWrongType() {
+        input.addmember(RemotedHttpServletRequest.STRUCTURE_NAME).getmember(RemotedHttpServletRequest.CONTENT_TYPE).string("text/plain");
+        final Event event = action.execute(src);
+        ActionTestingSupport.assertProceedEvent(event);
+        Assert.assertEquals(response.getCookies().length, 0);
+    }
     
     @Test
     public void testDisallowed() {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list