This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit f1e1847ae923c436dcffba0470c8068e2da3d490
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Mon Nov 23 11:39:42 2026 +0000

    Allow the _type and _ctype query overrides to be disabled (#3761)
    
    (cherry picked from commit d96d7840dd4267768aceba72e17310f6a3812523)
---
 .../apache/cxf/jaxrs/impl/RequestPreprocessor.java  | 12 ++++++++++--
 .../cxf/jaxrs/impl/RequestPreprocessorTest.java     | 21 +++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
index 6d52c85e157..935f77050c6 100644
--- 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
+++ 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
@@ -43,6 +43,12 @@ public class RequestPreprocessor {
      */
     private static final String ALLOW_HTTP_METHOD_OVERRIDE = 
"org.apache.cxf.jaxrs.allow.http.method.override";
 
+    /**
+     * Whether to allow the client to override the Accept and Content-Type 
headers via the ACCEPT_QUERY
+     * and CTYPE_QUERY query parameters. The default is true.
+     */
+    private static final String ALLOW_QUERY_TYPE_OVERRIDE = 
"org.apache.cxf.jaxrs.allow.query.type.override";
+
     private static final String ACCEPT_QUERY = "_type";
     private static final String CTYPE_QUERY = "_ctype";
     private static final String METHOD_QUERY = "_method";
@@ -87,8 +93,10 @@ public class RequestPreprocessor {
         handleLanguageMappings(m, u);
 
         MultivaluedMap<String, String> queries = u.getQueryParameters();
-        handleTypeQuery(m, queries);
-        handleCType(m, queries);
+        if (MessageUtils.getContextualBoolean(m, ALLOW_QUERY_TYPE_OVERRIDE, 
true)) {
+            handleTypeQuery(m, queries);
+            handleCType(m, queries);
+        }
         handleMethod(m, queries, new HttpHeadersImpl(m));
         return new UriInfoImpl(m, null).getPath();
     }
diff --git 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
index 50a4ad2f131..0e9298a8de7 100644
--- 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
+++ 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
@@ -37,6 +37,7 @@ import org.apache.cxf.transport.servlet.ServletDestination;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -80,6 +81,26 @@ public class RequestPreprocessorTest {
         assertEquals("application/xml", m.get(Message.ACCEPT_CONTENT_TYPE));
     }
 
+    @Test
+    public void testCTypeQuery() {
+        Message m = mockMessage("http://localhost:8080";, "/bar", 
"_ctype=json", "POST");
+        m.put(Message.CONTENT_TYPE, "text/plain");
+        RequestPreprocessor sqh = new RequestPreprocessor();
+        sqh.preprocess(m, new UriInfoImpl(m, null));
+        assertEquals("application/json", m.get(Message.CONTENT_TYPE));
+    }
+
+    @Test
+    public void testTypeQueriesDisabled() {
+        Message m = mockMessage("http://localhost:8080";, "/bar", 
"_type=xml&_ctype=json", "POST");
+        m.put(Message.CONTENT_TYPE, "text/plain");
+        m.put("org.apache.cxf.jaxrs.allow.query.type.override", false);
+        RequestPreprocessor sqh = new RequestPreprocessor();
+        sqh.preprocess(m, new UriInfoImpl(m, null));
+        assertEquals("text/plain", m.get(Message.CONTENT_TYPE));
+        assertNull(m.get(Message.ACCEPT_CONTENT_TYPE));
+    }
+
     private Message mockMessage(String baseAddress,
                                 String pathInfo,
                                 String query,

Reply via email to