fix(security): sanitize filename in Content-Disposition response header #85
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Security Issue — MEDIUM
Found in:
backend/src/main/java/org/raddatz/familienarchiv/controller/DocumentController.java(line ~73)The vulnerable pattern
The original filename comes from the client at upload time and is stored in the database verbatim. When it is later embedded into the
Content-Dispositionheader without sanitization, a filename containing a double-quote character (") breaks the header syntax. A filename with a newline (\n) can inject an entirely new HTTP response header.Example:
photo".jpg→ header becomesinline; filename="photo".jpg"— malformedphoto\r\nX-Injected: evil→ splits the HTTP header → header injectionThe fix
Strip or encode characters that are unsafe in HTTP header values before embedding them. The simplest safe approach: remove everything except word characters, spaces, dots, and hyphens, then trim to a reasonable length.
For full RFC 5987 compliance with non-ASCII filenames (German umlauts are common in this archive):
Why
HTTP headers are line-based text. Injecting a newline into a header value lets an attacker append arbitrary headers to the response — including
Set-Cookie,Content-Type, or cache-poisoning headers. This is called HTTP header injection (a subset of CRLF injection).Priority
MEDIUM — requires a malicious filename to be stored first (needs WRITE_ALL permission), but the impact is header injection on any user who downloads the file.