cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6479] restricting a custom separator to a single String character
Date Tue, 30 Jun 2015 12:12:10 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 21c1ff481 -> 012dc0d80


[CXF-6479] restricting a custom separator to a single String character


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/012dc0d8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/012dc0d8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/012dc0d8

Branch: refs/heads/3.0.x-fixes
Commit: 012dc0d803fb15b0e6e27ddcb1d9f2de7d7d768e
Parents: 21c1ff4
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jun 30 13:10:16 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jun 30 13:11:39 2015 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/CacheControlHeaderProvider.java |  6 +++++-
 .../org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java | 11 +++++++++--
 .../jaxrs/impl/CacheControlHeaderProviderTest.java | 13 +++++++++++++
 .../apache/cxf/jaxrs/impl/HttpHeadersImplTest.java | 17 +++++++++++++++++
 4 files changed, 44 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/012dc0d8/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
index e2f3b73..9ccc37d 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
@@ -31,6 +31,7 @@ import javax.ws.rs.core.CacheControl;
 import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
@@ -227,7 +228,10 @@ public class CacheControlHeaderProvider implements HeaderDelegate<CacheControl>
         if (message != null) {
             Object sepProperty = message.getContextualProperty(CACHE_CONTROL_SEPARATOR_PROPERTY);
             if (sepProperty != null) {
-                separator = sepProperty.toString();
+                separator = sepProperty.toString().trim();
+                if (separator.length() != 1) {
+                    throw ExceptionUtils.toInternalServerErrorException(null, null);
+                }
             }
         }
         return separator;

http://git-wip-us.apache.org/repos/asf/cxf/blob/012dc0d8/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
index bacad82..d692964 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
@@ -42,6 +42,7 @@ import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
@@ -123,8 +124,14 @@ public class HttpHeadersImpl implements HttpHeaders {
     private String getCookieSeparator() {
         Object cookiePropValue = message.getContextualProperty(COOKIE_SEPARATOR_PROPERTY);
         if (cookiePropValue != null) {
-            return COOKIE_SEPARATOR_CRLF.equals(cookiePropValue.toString()) 
-                ? "\r\n" : cookiePropValue.toString();
+            String separator = cookiePropValue.toString().trim();
+            if (COOKIE_SEPARATOR_CRLF.equals(separator)) {
+                return "\r\n";
+            }
+            if (separator.length() != 1) {
+                throw ExceptionUtils.toInternalServerErrorException(null, null);
+            }
+            return separator;
         } else {
             return DEFAULT_COOKIE_SEPARATOR;
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/012dc0d8/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
index da21b76..89966c9 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs.impl;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.core.CacheControl;
 
 import org.apache.cxf.message.Message;
@@ -83,6 +84,18 @@ public class CacheControlHeaderProviderTest extends Assert {
         
     }
     
+    @Test(expected = InternalServerErrorException.class)
+    public void testInvalidSeparator() {
+        CacheControlHeaderProvider cp = new CacheControlHeaderProvider() {
+            protected Message getCurrentMessage() {
+                Message m = new MessageImpl();
+                m.put(CacheControlHeaderProvider.CACHE_CONTROL_SEPARATOR_PROPERTY, "(e+)+");
+                return m;
+            }
+        };
+        cp.fromString("no-store");
+    }
+    
     
     @Test
     public void testToString() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/012dc0d8/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
index 491ea95..c072021 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
@@ -28,6 +28,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.TreeMap;
 
+import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -420,6 +421,7 @@ public class HttpHeadersImplTest extends Assert {
         assertEquals(1, cookie.getVersion());
     }
     
+    
     @Test
     public void testGetCookiesWithComma() throws Exception {
         
@@ -438,6 +440,21 @@ public class HttpHeadersImplTest extends Assert {
         assertEquals("d", cookies.get("c").getValue());
     }
     
+    @Test(expected = InternalServerErrorException.class)
+    public void testInvalidCookieSeparator() throws Exception {
+        
+        Message m = new MessageImpl();
+        Exchange ex = new ExchangeImpl();
+        ex.setInMessage(m);
+        ex.put("org.apache.cxf.http.cookie.separator", "(e+)+");
+        m.setExchange(ex);
+        MetadataMap<String, String> headers = createHeaders();
+        headers.putSingle(HttpHeaders.COOKIE, "a=b,c=d");
+        m.put(Message.PROTOCOL_HEADERS, headers);
+        HttpHeaders h = new HttpHeadersImpl(m);
+        h.getCookies();
+    }
+    
     @Test
     public void testMultipleAcceptableLanguages() throws Exception {
         


Mime
View raw message