Skip to content

Do not follow a symbolic link when reading a cache file - #3341

Open
arturobernalg wants to merge 1 commit into
apache:masterfrom
arturobernalg:fix-file-resource-symlink-read
Open

arturobernalg wants to merge 1 commit into
apache:masterfrom
arturobernalg:fix-file-resource-symlink-read

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

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.

@ok2c

ok2c commented Dec 5, 2026

Copy link
Copy Markdown
Member

@arturobernalg Could you please re-apply your commit on top of the latest master. Sorry about extra work.

@garydgregory

Copy link
Copy Markdown
Member

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.

@ok2c

ok2c commented Dec 5, 2026

Copy link
Copy Markdown
Member

Do we really define the file system as UNTRUSTED in our security model?

@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.

@garydgregory

Copy link
Copy Markdown
Member

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.

@ok2c

ok2c commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

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.

  1. There are no changes to our security model. None. It stays the same.
  2. You should have raised your objections before restrict cache file mode and reject symlinks in FileResourceFactory #3329 got merged. Now we look silly
  3. Every time we touch the code we can break something or cause subtle bugs

@garydgregory

Copy link
Copy Markdown
Member

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.

@arturobernalg
arturobernalg force-pushed the fix-file-resource-symlink-read branch from 4296869 to 0db22c6 Compare December 5, 2026 13:30
@ok2c

ok2c commented Dec 5, 2026

Copy link
Copy Markdown
Member

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.

@garydgregory File system resources accessible to the JRE process should be considered trusted.

@arturobernalg
arturobernalg force-pushed the fix-file-resource-symlink-read branch from 0db22c6 to a51c106 Compare December 5, 2026 13:49
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.
@arturobernalg
arturobernalg force-pushed the fix-file-resource-symlink-read branch from a51c106 to 2120d82 Compare December 5, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants