Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…malization check) to trunk

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@680759 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jul 29, 2008
1 parent 9d3cad7 commit c55ad56
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions java/org/apache/catalina/connector/CoyoteAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ protected boolean postParseRequest(org.apache.coyote.Request req,
}
// Character decoding
convertURI(decodedURI, request);
// Check that the URI is still normalized
if (!checkNormalize(req.decodedURI())) {
res.setStatus(400);
res.setMessage("Invalid URI character encoding");
return false;
}
} else {
// The URL is chars or String, and has been sent using an in-memory
// protocol handler, we have to assume the URL has been properly
Expand Down Expand Up @@ -787,6 +793,67 @@ public static boolean normalize(MessageBytes uriMB) {
}


/**
* Check that the URI is normalized following character decoding.
* <p>
* This method checks for "\", 0, "//", "/./" and "/../". This method will
* return false if sequences that are supposed to be normalized are still
* present in the URI.
*
* @param uriMB URI to be checked (should be chars)
*/
public static boolean checkNormalize(MessageBytes uriMB) {

CharChunk uriCC = uriMB.getCharChunk();
char[] c = uriCC.getChars();
int start = uriCC.getStart();
int end = uriCC.getEnd();

int pos = 0;

// Check for '\' and 0
for (pos = start; pos < end; pos++) {
if (c[pos] == '\\') {
return false;
}
if (c[pos] == 0) {
return false;
}
}

// Check for "//"
for (pos = start; pos < (end - 1); pos++) {
if (c[pos] == '/') {
if (c[pos + 1] == '/') {
return false;
}
}
}

// Check for ending with "/." or "/.."
if (((end - start) >= 2) && (c[end - 1] == '.')) {
if ((c[end - 2] == '/')
|| ((c[end - 2] == '.')
&& (c[end - 3] == '/'))) {
return false;
}
}

// Check for "/./"
if (uriCC.indexOf("/./", 0, 3, 0) >= 0) {
return false;
}

// Check for "/../"
if (uriCC.indexOf("/../", 0, 4, 0) >= 0) {
return false;
}

return true;

}


// ------------------------------------------------------ Protected Methods


Expand Down

0 comments on commit c55ad56

Please # to comment.