Repository navigation
Sanitize download attribute file names in DownloadingAttachmentHandler - #1184
Merged
rbri merged 1 commit intoNov 2, 2026
Merged
Conversation
The file name of a download started by an anchor with a download attribute is passed to the AttachmentHandler as it is; only names from the Content-Disposition header are sanitized. DownloadingAttachmentHandler resolved this name against the download folder, so a page could use download="../x" or an absolute path to create a file anywhere outside of it. Sanitize the name the same way as the header name before resolving it.
|
Member
|
great - thanks |
Contributor
Author
|
Thanks for merging this, glad it went in cleanly. |
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.



Repro: set
webClient.setAttachmentHandler(new DownloadingAttachmentHandler(dir))and load a page whose script doesa.download = '../evil.txt'; a.click();, or sets an absolute path such as/home/user/.config/autostart/x.desktop. The response of the link is written to the path the page chose, outside ofdir, and nothing is saved indir. Only new files are created (an existing name gets the(1)suffix), but anywhere the JVM user can write.Cause: for a
downloadattribute,WebClient.loadWebResponseInto()passes the attribute value to theAttachmentHandlerunchanged; only names from the Content-Disposition header go throughAttachment.getSuggestedFilename().DownloadingAttachmentHandler.determineDestionationFile()then callsdownloadFolder_.resolve(fileName), which follows..and returns an absolute name as it is.Fix: run the name through the existing
Attachment.sanitizeFilename()(now package private) inDownloadingAttachmentHandlerbefore resolving it.../../evil.txtbecomes_.._evil.txt, the name the header path already produces (AttachmentSuggestedFilename2Test.pathTraversal); browsers do not let the download attribute pick a directory either. Doing it in the handler covers every source of the name, not only the anchor.DownloadingAttachmentHandlerTest.fileNameFromDownloadAttributeIsSanitizedcovers a relative and an absolute name and fails without the change. The attachment, anchor and area tests andCodeStyleTestpass.