Skip to content

Commit

Permalink
When running under a security manager and using sendfile, validate se…
Browse files Browse the repository at this point in the history
…ndfile attributes to prevent sendfile being used to bypass the security manager.

Part of the fix for CVE-2011-2526

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1146005 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jul 13, 2011
1 parent 787a164 commit 2e69497
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions java/org/apache/catalina/connector/LocalStrings.properties
Expand Up @@ -66,6 +66,7 @@ coyoteRequest.noLoginConfig=No authentication mechanism has been configured for
coyoteRequest.authenticate.ise=Cannot call authenticate() after the reponse has been committed
coyoteRequest.uploadLocationInvalid=The temporary upload location [{0}] is not valid
coyoteRequest.sessionEndAccessFail=Exception triggered ending access to session while recycling request
coyoteRequest.sendfileNotCanonical=Unable to determine canonical name of file [{0}] specified for use with sendfile

requestFacade.nullRequest=The request object has been recycled and is no longer associated with this facade

Expand Down
20 changes: 20 additions & 0 deletions java/org/apache/catalina/connector/Request.java
Expand Up @@ -1525,6 +1525,26 @@ public void setAttribute(String name, Object value) {
return;
}

// Do the security check before any updates are made
if (Globals.IS_SECURITY_ENABLED &&
name.equals("org.apache.tomcat.sendfile.filename")) {
// Use the canonical file name to avoid any possible symlink and
// relative path issues
String canonicalPath;
try {
canonicalPath = new File(value.toString()).getCanonicalPath();
} catch (IOException e) {
throw new SecurityException(sm.getString(
"coyoteRequest.sendfileNotCanonical", value), e);
}
// Sendfile is performed in Tomcat's security context so need to
// check if the web app is permitted to access the file while still
// in the web app's security context
System.getSecurityManager().checkRead(canonicalPath);
// Update the value so the canonical path is used
value = canonicalPath;
}

oldValue = attributes.put(name, value);
if (oldValue != null) {
replaced = true;
Expand Down

0 comments on commit 2e69497

Please sign in to comment.