Repository navigation
Do not follow a symbolic link when reading a cache file - #3341
arturobernalg wants to merge 1 commit into
Conversation
|
@arturobernalg Could you please re-apply your commit on top of the latest master. Sorry about extra work. |
|
If an attacker has control of your file system, you've got bigger problems. Do we really define the file system as UNTRUSTED in our security model? Another thing to think about is what the JRE does by default which is to follow links. Are we going to change our whole code base to never follow links? What about symlinks vs. hardlinks vs. junctions? Once you open that can of worms... This might type of change might bite al lot of folks. OTHO, if you just say the file system is trusted, you're done. If you just use the JRE default, you're done. We could also add the option to provide an array of link options which is really surfacing the JRE options. |
@garydgregory I fully agree. If one can put symlinks in the file cache or even just has access to the host, the HTTP response cache should likely be the least of the concerns. But I also see no harm in adding some extra protection even if to reduce the volume of silly security reports. |
|
Hi @ok2c I've been seeing a few of these "your project uses the default JRE behavior, therefore it's a security issue" in the FOSS world. So far I've rejected those (in other projects). We should think hard on this because it will break some apps or cause subtle bugs. The first task is to update the security model. Everything should follow from there. |
@garydgregory It looks like there is just nothing in this world we can agree upon.
|
|
What i am really asking for is consensus on the security model: is the file system trusted or untrusted? Changes (or not) follow from there. |
4296869 to
0db22c6
Compare
@garydgregory File system resources accessible to the JRE process should be considered trusted. |
0db22c6 to
a51c106
Compare
FileResource read the cache file with a plain FileInputStream, which follows a symlink at that path. An attacker able to write to the cache directory after a file was already cached, not just before, could swap it for a symlink to an arbitrary file and have the next read return that file's content as the response body. Open with NOFOLLOW_LINKS instead. On the fresh-hit path a rejected read is caught by the cache lookup and falls back to the origin. Covers a symlink at the cache file's own path; a hard link to another file, or a symlink earlier in the path, are not addressed here.
a51c106 to
2120d82
Compare
FileResource read the cache file with a plain FileInputStream, which follows a symlink at that path. An attacker able to write to the cache directory after a file was already cached, not just before, could swap it for a symlink to an arbitrary file and have the next read return that file's content as the response body.
Open with NOFOLLOW_LINKS instead. On the fresh-hit path a rejected read is caught by the cache lookup and falls back to the origin.
Covers a symlink at the cache file's own path; a hard link to another file, or a symlink earlier in the path, are not addressed here.