Fix Content-Disposition parameter injection via download filenames#1309
Merged
Conversation
The csv and download components built the Content-Disposition header by string-interpolating the user-supplied filename. A filename containing characters such as ';', '"' or '=' could inject an additional header parameter (e.g. a second, agent-preferred filename*=...), letting an app that interpolates untrusted data into the filename smuggle a different download name past the intended one. Build the header with actix-web's structured ContentDisposition type so the filename is always a single, properly quoted/escaped value and cannot create new parameters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Content-Disposition parameter injection via download filenames
The
csvanddownloadcomponents built theContent-Dispositionheader by string-interpolating the user-supplied filename (render.rs#L304-L307 and #L348-L351). A filename containing;,"or=could inject a second header parameter that some browsers prefer over the intended one.For example:
produced two parameters, the injected one being agent-preferred:
Fix: build the header with actix-web's structured
ContentDispositiontype, so the filename is always a single, properly quoted/escaped value:A compliant parser (and actix's own
ContentDisposition::from_raw) now sees exactly one inertfilenamevalue.Both components share the new
attachment_with_filenamehelper, so the fix is in one place.Proof
New test
test_csv_filename_header_injectionparses the response header withContentDisposition::from_raw(same logic a browser uses) and asserts there is no injectedfilename*and the payload stays inside a singlefilename.Fails on
main:Passes with the fix, and the full
tests/mod.rssuite stays green (64 passed; 0 failed), including the existingtest_download_data_urlwhich still assertsattachment; filename="my text file.txt".cargo fmt --allandcargo clippy --all-targets --all-features -- -D warningsare clean.Scope / severity
The filename is normally chosen by trusted SQL, so this matters only when an app interpolates untrusted data into a `csv`/`download` `filename`. No SQL change is required by users; CHANGELOG updated.