File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
java/org/apache/catalina/session Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 33
33
import org .apache .catalina .Globals ;
34
34
import org .apache .catalina .Session ;
35
35
import org .apache .juli .logging .Log ;
36
+ import org .apache .juli .logging .LogFactory ;
37
+ import org .apache .tomcat .util .res .StringManager ;
36
38
37
39
/**
38
40
* Concrete implementation of the <b>Store</b> interface that utilizes
43
45
*/
44
46
public final class FileStore extends StoreBase {
45
47
48
+ private static final Log log = LogFactory .getLog (FileStore .class );
49
+ private static final StringManager sm = StringManager .getManager (FileStore .class );
50
+
51
+
46
52
// ----------------------------------------------------- Constants
47
53
48
54
/**
@@ -336,11 +342,20 @@ private File directory() throws IOException {
336
342
* used in the file naming.
337
343
*/
338
344
private File file (String id ) throws IOException {
339
- if (this .directory == null ) {
345
+ File storageDir = directory ();
346
+ if (storageDir == null ) {
340
347
return null ;
341
348
}
349
+
342
350
String filename = id + FILE_EXT ;
343
- File file = new File (directory (), filename );
351
+ File file = new File (storageDir , filename );
352
+
353
+ // Check the file is within the storage directory
354
+ if (!file .getCanonicalPath ().startsWith (storageDir .getCanonicalPath ())) {
355
+ log .warn (sm .getString ("fileStore.invalid" , file .getPath (), id ));
356
+ return null ;
357
+ }
358
+
344
359
return file ;
345
360
}
346
361
}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ JDBCStore.wrongDataSource=Cannot open JNDI DataSource [{0}]
29
29
fileStore.createFailed =Unable to create directory [{0}] for the storage of session data
30
30
fileStore.deleteFailed =Unable to delete file [{0}] which is preventing the creation of the session storage location
31
31
fileStore.deleteSessionFailed =Unable to delete file [{0}] which is no longer required
32
+ fileStore.invalid =Invalid persistence file [{0}] for session ID [{1}]
32
33
fileStore.loading =Loading Session [{0}] from file [{1}]
33
34
fileStore.removing =Removing Session [{0}] at file [{1}]
34
35
fileStore.saving =Saving Session [{0}] to file [{1}]
Original file line number Diff line number Diff line change 114
114
replacement to <code >:-</code > due to possible conflicts. The
115
115
syntax is now <code >${name:-default}</code >. (remm)
116
116
</fix >
117
+ <add >
118
+ Improve validation of storage location when using FileStore. (markt)
119
+ </add >
117
120
</changelog >
118
121
</subsection >
119
122
<subsection name =" Coyote" >
You can’t perform that action at this time.
0 commit comments