Make calculation of session storage location more robust · apache/tomcat@094800b · GitHub
Skip to content

Commit

Permalink
Make calculation of session storage location more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jan 12, 2022
1 parent 4719c4c commit 094800b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions java/org/apache/catalina/session/FileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,14 @@ private File file(String id) throws IOException {

String filename = id + FILE_EXT;
File file = new File(storageDir, filename);
File canonicalFile = file.getCanonicalFile();

// Check the file is within the storage directory
if (!file.getCanonicalFile().toPath().startsWith(storageDir.getCanonicalFile().toPath())) {
if (!canonicalFile.toPath().startsWith(storageDir.getCanonicalFile().toPath())) {
log.warn(sm.getString("fileStore.invalid", file.getPath(), id));
return null;
}

return file;
return canonicalFile;
}
}
4 changes: 4 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
Add recycling check in the input and output stream isReady to try to
give a more informative ISE when the facade has been recycled. (remm)
</fix>
<fix>
Make the calculation of the session storage location more robust when
using file based persistent storage. (markt)
</fix>
</changelog>
</subsection>
<subsection name="Coyote">
Expand Down

0 comments on commit 094800b

Please sign in to comment.