downloads.download throws if the folder name contains a dot and a space
Categories
(WebExtensions :: General, defect, P3)
Tracking
(firefox-esr115 verified, firefox-esr128 verified, firefox127 wontfix, firefox128 wontfix, firefox129 wontfix, firefox130 verified, firefox131 verified)
People
(Reporter: eight04, Assigned: robwu)
References
Details
(Keywords: regression, Whiteboard: [addons-jira])
Attachments
(6 files)
1.06 MB,
video/x-matroska
|
Details | |
29.69 KB,
image/png
|
Details | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
phab-bot
:
approval-mozilla-esr128+
|
Details | Review |
48 bytes,
text/x-phabricator-request
|
phab-bot
:
approval-mozilla-esr115+
|
Details | Review |
48 bytes,
text/x-phabricator-request
|
phab-bot
:
approval-mozilla-beta+
|
Details | Review |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0
Steps to reproduce:
- Download and install the extension: https://github.com/eight04/webextension-test/archive/refs/heads/illegal-filename-2.zip
- Click the extension button to trigger browserAction.
- Inspect the background page and open the console.
Actual results:
Two errors are thrown:
Error: filename must not contain illegal characters
Expected results:
Two files are downloaded correctly with FF126 and Edge.
Reported by https://github.com/eight04/image-picka/issues/347#issuecomment-2173368486
Comment 1•5 months ago
|
||
The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•5 months ago
|
||
I guess this is because we're intending to replace the space with _
in the file extension after bug 1891234. Neil, does that sound right? Can we refine the replacement so it doesn't affect the case reported here? (looks like it's a filename that contains .
followed by somewhere, before the final
.jpg
)
I am not able to see any errors in consoles in FF 127 and 129, but also the files expected to be downloaded are not present.
Can you please attach a video or a screenshot with the errors?
I started the browser via web-ext
. Does it affect logging?
Comment 5•5 months ago
|
||
Hello,
I reproduced the issue on the latest Nightly (129.0a1/20240625213230), Beta (128.0b7/20240624113619) and Release (127.0.2/20240624183754) under Windows 10 x64 and Ubuntu 22.04 LTS.
Clicking the extension button will throw two errors as mentioned in Comment 0 and the files are not downloaded. See the attached screenshots for more details.
Comment 6•5 months ago
|
||
Assignee | ||
Updated•5 months ago
|
Updated•5 months ago
|
Updated•5 months ago
|
Comment 8•5 months ago
|
||
:robwu do you plan on making a similar fix as in Bug 1898498?
:zombie could this be triaged for severity?
Assignee | ||
Comment 9•5 months ago
|
||
I'm not planning to do the same fix as bug 1898498, because I don't think that we should disallow directories in the format blabla<dot><space>something
.
I think that we need to use a different mechanism to verify whether an input is an acceptable directory name, because DownloadPaths.sanitize
is now too strict.
Comment 10•5 months ago
|
||
(In reply to :Gijs (he/him) from comment #2)
I guess this is because we're intending to replace the space with
_
in the file extension after bug 1891234. Neil, does that sound right? Can we refine the replacement so it doesn't affect the case reported here? (looks like it's a filename that contains.
followed bysomewhere, before the final
.jpg
)
Are you thinking of this change for all downloads, not just for webextension specific ones? In other words, this change could be instead of Rob's suggestions?
Comment 11•5 months ago
|
||
Actually, I'm a bit confused re-reading this bug and particularly comment #9. How would a user download a directory? :-\
(it was not clear to me from comment 0 that there was an issue with a directory, I assumed there was an issue with files and their names. I'm not aware of any way a website can download a directory directly - only files (which may be archives, which when un-archived can result in directories... but that's not really the same thing.)
I don't know that the existing checks are set up to check directory names (where extensions aren't meaningful). And if there is some non-download mechanism that allows an extension to create a folder then I don't know why that is passing through the download filename sanitizer...
Updated•5 months ago
|
Comment 13•5 months ago
|
||
I guess you're right, I was thinking that the directory was not the relevant part, that it would drop the space even if example was 1.1 A.1.jpg
, but that's not the issue. It is indeed how we use the sanitizer, splitting up directory names and sanitizing each separately, which makes 1.1 A
as not a valid directory name.
Comment 14•5 months ago
|
||
Hi
I was the user who found the specific problem with the addon I'm using.
Let me explain.
I use 2 addons. Both use the pagetitle to name things.
As I download content from an app site, page title is usually as follow : "appname - version xx.xx.xx from xxxxx"
So as you can see, I have spaces, dots and dashes.
The first addon creates a text file, named "pagetitle.txt". I have no problems with that one.
The second one downloads images and put them in a directory, of course the directory doesn't exist at the time. So let's say if I have 3 images, I will have these :
"pagetitle/1.jpg"
"pagetitle/2.jpg"
"pagetitle/3.jpg"
That allows me to have the images of the apps, in the same directory named "pagetitle"
Comment 15•5 months ago
|
||
I have been facing this bug through an extension, Image Picka, with the following use case:
The extension allows batch downloading of images sourced from a single tab or multiple tabs.
It puts the files inside a folder. It can be multi-level.
The folder is named by the title of the tab from where the operation was initiated.
A directory is not being downloaded but files are being downloaded to a directory created by the extension at the configured Firefox download location.
Assignee | ||
Comment 16•5 months ago
|
||
(In reply to :Gijs (he/him) from comment #11)
Actually, I'm a bit confused re-reading this bug and particularly comment #9. How would a user download a directory? :-\
The downloads.download
extension API accepts a path separator in the filename
option, which instructs the browser to save to that directory (within the default downloads directory). In the extension API implementation, we are currently relying on DownloadPaths.sanitize
to not only verify that the leaf (file name) is valid, but using the same for the directory name: https://searchfox.org/mozilla-central/rev/b368ed8b48c0ea8ed2f1948e4776a6fbb5976dff/toolkit/components/extensions/parent/ext-downloads.js#674-677,691-713
It looks like the DownloadPaths.sanitize
method has diverged from the original implementation, to the point that it is overcautious and sanitizes file names that are not unsafe.
Would it be feasible to change the underlying implementation of DownloadPaths.sanitize
to NOT strip whitespace when compressWhitespaces: false
is used? Alternatively, a new option to stop stripping whitespace after a dot.
Comment 17•4 months ago
|
||
(In reply to Rob Wu [:robwu] from comment #16)
(In reply to :Gijs (he/him) from comment #11)
Actually, I'm a bit confused re-reading this bug and particularly comment #9. How would a user download a directory? :-\
The
downloads.download
extension API accepts a path separator in thefilename
option, which instructs the browser to save to that directory (within the default downloads directory). In the extension API implementation, we are currently relying onDownloadPaths.sanitize
to not only verify that the leaf (file name) is valid, but using the same for the directory name: https://searchfox.org/mozilla-central/rev/b368ed8b48c0ea8ed2f1948e4776a6fbb5976dff/toolkit/components/extensions/parent/ext-downloads.js#674-677,691-713
OK. Yeah, the intent of that function was never to validate directory names - it's just a wrapper around the mime service's functions to validate filenames for saving, which have explicit flags to even modify the extensions based on the mimetype, which make it (IMO) clear that it wasn't intended for use on directories.
It looks like the
DownloadPaths.sanitize
method has diverged from the original implementation, to the point that it is overcautious and sanitizes file names that are not unsafe.
I've CC'd you on the security bug. Off-hand, "overcautious" seems incorrect, but if you think there is some middle ground in the original implementation that would fix that security bug without causing this issue then please elaborate.
Would it be feasible to change the underlying implementation of
DownloadPaths.sanitize
to NOT strip whitespace whencompressWhitespaces: false
is used? Alternatively, a new option to stop stripping whitespace after a dot.
It sounds like the webextensions implementation needs this API to have an option that ignores all the file extension logic and only validates the directory name - although "what's left" at that point, I'm not sure. If there is some logic left then yes, I expect adding a flag to the mime service and calling that would be OK.
Assignee | ||
Comment 18•4 months ago
|
||
Needinfo-ing myself - I need to figure out a better validation mechanism for directories that is not as strict as the file name validator. If needed I'll set up a meeting with Gijs, Neil and :pbz to discuss this.
Comment 19•4 months ago
|
||
I think for directories you just want to use sanitizeFileName() but with a flag to not do the extension truncation that happens mostly at the end of that function.
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Assignee | ||
Comment 20•4 months ago
|
||
I'm going to add a patch. I'm thinking of a generic "allow directory names" function. For now I'm focusing on solving the regression, but I can imagine the flag being expanded in the future to cover more cases.
Assignee | ||
Comment 21•4 months ago
|
||
Updated•4 months ago
|
Comment 22•3 months ago
|
||
Comment 23•3 months ago
|
||
bugherder |
Assignee | ||
Comment 24•3 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D218719
Updated•3 months ago
|
Assignee | ||
Comment 25•3 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D218719
Updated•3 months ago
|
Comment 26•3 months ago
|
||
esr128 Uplift Approval Request
- User impact if declined: Extensions fail to save files to directories with spaces after the last dot. This was a regression in 128 (uplifted to 127).
- Code covered by automated testing: yes
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: QA not needed, but if desired STR are in the report.
- Risk associated with taking this patch: Low
- Explanation of risk level: The patch adds an option to opt in to exactly the desired behavior and uses that option in extension code only. There is also extensive test coverage for this option.
- String changes made/needed: No
- Is Android affected?: no
Comment 27•3 months ago
|
||
esr115 Uplift Approval Request
- User impact if declined: Extensions fail to save files to directories with spaces after the last dot. This was a regression on the ESR115 due to an uplift.
- Code covered by automated testing: yes
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: QA not needed, but if desired STR are in the report.
- Risk associated with taking this patch: Low
- Explanation of risk level: The patch adds an option to opt in to exactly the desired behavior and uses that option in extension code only. There is also extensive test coverage for this option.
- String changes made/needed: No
- Is Android affected?: no
Comment 28•3 months ago
|
||
The patch landed in nightly and beta is affected.
:robwu, is this bug important enough to require an uplift?
- If yes, please nominate the patch for beta approval.
- If no, please set
status-firefox130
towontfix
.
For more information, please visit BugBot documentation.
Updated•3 months ago
|
Updated•3 months ago
|
Comment 29•3 months ago
|
||
uplift |
Updated•3 months ago
|
Comment 30•3 months ago
|
||
uplift |
Updated•3 months ago
|
Updated•3 months ago
|
Assignee | ||
Comment 31•3 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D218719
Updated•3 months ago
|
Comment 32•3 months ago
|
||
beta Uplift Approval Request
- User impact if declined: Extensions fail to save files to directories with spaces after the last dot. This was a regression in 128 (uplifted to 127).
- Code covered by automated testing: yes
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: QA not needed, but if desired STR are in the report.
- Risk associated with taking this patch: Low
- Explanation of risk level: The patch adds an option to opt in to exactly the desired behavior and uses that option in extension code only. There is also extensive test coverage for this option.
- String changes made/needed: None
- Is Android affected?: no
Assignee | ||
Updated•3 months ago
|
Updated•3 months ago
|
Updated•3 months ago
|
Updated•3 months ago
|
Comment 33•3 months ago
|
||
uplift |
Comment 34•3 months ago
|
||
Verified as Fixed. Tested on the latest Nightly (131.0a1/20240821160637), Beta (130.0b9/20240821170443 from https://treeherder.mozilla.org/jobs?repo=mozilla-beta&revision=05050104ec0cb90fa4bebc6fdb01ee6bd7075b72), ESR 115 (115.15.0esr/20240821131223 from https://treeherder.mozilla.org/jobs?repo=mozilla-esr115&revision=79e9d3eb5b1a9ac9562c4f13f5194598f285e3c7) and ESR 128 (128.2.0esr/20240821131032 from https://treeherder.mozilla.org/jobs?repo=mozilla-esr128&revision=f3bf1705bfa0f923e4541e6cc9f9aada80b733d9) under Windows 10 x64 and Ubuntu 22.04 LTS.
Using the example extension linked in Comment 0, clicking the extension button will download two html files in two folders - 1. foo
and 1.foo bar
.
The Error: filename must not contain illegal characters
error is no longer thrown.
Considering the above, the issue is fixed.
Description
•