Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51698
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 29 Aug 2011 19:44:53 +0000 (19:44 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 29 Aug 2011 19:44:53 +0000 (19:44 +0000)
Fix CVE-2011-3190
Prevent AJP request forgery via unread request body packet

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1162957 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/ajp/AbstractAjpProcessor.java
java/org/apache/coyote/ajp/AjpAprProcessor.java
java/org/apache/coyote/ajp/AjpNioProcessor.java
java/org/apache/coyote/ajp/AjpProcessor.java

index 39fb0b6..fceefdd 100644 (file)
@@ -985,6 +985,11 @@ public abstract class AbstractAjpProcessor<S> extends AbstractProcessor<S> {
 
         finished = true;
 
+        // Swallow the unread body packet if present
+        if (first && request.getContentLengthLong() > 0) {
+            receive();
+        }
+
         // Add the end message
         if (error) {
             output(endAndCloseMessageArray, 0, endAndCloseMessageArray.length);
index 078f2b6..d6b0b56 100644 (file)
@@ -140,11 +140,13 @@ public class AjpAprProcessor extends AbstractAjpProcessor<Long> {
                     }
                     continue;
                 } else if(type != Constants.JK_AJP13_FORWARD_REQUEST) {
-                    // Usually the servlet didn't read the previous request body
-                    if(log.isDebugEnabled()) {
-                        log.debug("Unexpected message: "+type);
+                    // Unexpected packet type. Unread body packets should have
+                    // been swallowed in finish().
+                    if (log.isDebugEnabled()) {
+                        log.debug("Unexpected message: " + type);
                     }
-                    continue;
+                    error = true;
+                    break;
                 }
 
                 keptAlive = true;
index f1669dd..bd53f13 100644 (file)
@@ -126,12 +126,14 @@ public class AjpNioProcessor extends AbstractAjpProcessor<NioChannel> {
                     recycle(false);
                     continue;
                 } else if(type != Constants.JK_AJP13_FORWARD_REQUEST) {
-                    // Usually the servlet didn't read the previous request body
-                    if(log.isDebugEnabled()) {
-                        log.debug("Unexpected message: "+type);
+                    // Unexpected packet type. Unread body packets should have
+                    // been swallowed in finish().
+                    if (log.isDebugEnabled()) {
+                        log.debug("Unexpected message: " + type);
                     }
+                    error = true;
                     recycle(true);
-                    continue;
+                    break;
                 }
                 request.setStartTime(System.currentTimeMillis());
             } catch (IOException e) {
index 376327c..cdebea6 100644 (file)
@@ -143,13 +143,14 @@ public class AjpProcessor extends AbstractAjpProcessor<Socket> {
                     }
                     continue;
                 } else if(type != Constants.JK_AJP13_FORWARD_REQUEST) {
-                    // Usually the servlet didn't read the previous request body
-                    if(log.isDebugEnabled()) {
-                        log.debug("Unexpected message: "+type);
+                    // Unexpected packet type. Unread body packets should have
+                    // been swallowed in finish().
+                    if (log.isDebugEnabled()) {
+                        log.debug("Unexpected message: " + type);
                     }
-                    continue;
+                    error = true;
+                    break;
                 }
-
                 request.setStartTime(System.currentTimeMillis());
             } catch (IOException e) {
                 error = true;