-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-30956: Added raw URL encoding of download file name #2771
Conversation
c5d4c11
to
bdf8afd
Compare
Outside scope of possible BC breaks, is there any reason for this being static function? And should it not target 7.5? |
@ViniTou Static: Why not? |
Well, for me it should be other way around - why static. And, yeah, |
Made non-static and rebased on 6.7. Also expanded the PR description. |
7851e2d
to
8491055
Compare
Ensure the filename filtering can't result in an empty string, which would break the route generator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay.
-
Please add test coverage for the use case (unit test case for this listener already exists).
-
Please change your PR title & commit messages to reflect what changed in the codebase (past simple), not what the bug is.
-
Do we need to filter anything else? I have included ( at the beginning of names, and / anywhere, since that won't work either unless we specifically configure the route to accept it.
Definitely. See the diff comment.
eZ/Bundle/EzPublishCoreBundle/EventListener/ContentDownloadRouteReferenceListener.php
Outdated
Show resolved
Hide resolved
694ba4f
to
fe67d74
Compare
20c12af
to
c5dfe55
Compare
c5dfe55
to
2ff34bf
Compare
@alongosz @ViniTou Ready for re-review. Switched to doing rawurlencode. Added tests, which pass. Updated PR/commit messages. NB: Download using the redirect route (ez_content_download_field_id) works with this patch. This redirects to ez_content_download. However, calling ez_content_download directly still does not work with such filenames in my test, and leads to the same error as before the patch. So the fix is incomplete, if we intend for direct use to be possible. |
How can I reproduce locally this issue? |
|
I think this fix will work better #2899 |
Hi @ITernovtsiy, and thanks! I like your fix, it looks like a good addition, but it does not replace the url encoding fix, I think. We may need both. Url encoding is the "proper" way to fix the download problem, but more robust view parameter code would also be good. |
@glye are you sure we actually need to do the encoding? I'm able to download |
@ITernovtsiy Yes, it works, but this relies on the happy coincidence that the filename is the last parameter of the route. If it wasn't, then a file named |
@glye if it will be the case, I would change the named parameter check to handle it properly. IMHO, double encoding here looks like a dirty hack over the actual problem with false-positive named parameter detection. |
The point here is to serve the file using the name it was uploaded as. So I agree with @glye that we may need both. |
@alongosz maybe I'm missing something (and sorry for being so protective). In case if for some reason
|
In what case can this happen? To be clear, what I really want is to remove the filename parameter from the route, and download the file using the name it was originally uploaded with. We already have this information. But the problem there is backwards compatibility. |
There is no such use case, it was just an example of the fact the URL will not represent original file name after this change. |
Both examples represent the original file name, while neither is equal to it. The important thing is that the file is correctly saved. So long as named parameters are not defined/implemented in an unambiguous way (there seems to be no strict specification for them), I think it's too fragile to merge only one of these two PRs. I want both a fix for the current bug, and future stability. But @ezsystems/engineering-team decides. |
@glye In
It is correctly saved without
Completely agree here, and that is the main reason why I don't think it's a good idea to have Yes, let's @ezsystems/engineering-team decide :) |
I don't want to have a further semantic discussion about what we mean by "represent"... The important thing is that the file is correctly saved, which afaik it is with or without rawurlencode. So both are "correct". The encoding makes the whole concept less fragile, avoiding any ambiguity with named parameters. I'm open for other ways of achieving that goal. |
Closing PR as obsolete. eZ Platform 2.5 has reached EOM, so please reopen PR in ezsystems/ezplatform-kernel (bug fixes) or ibexa/core (features/improvements) if issue is still valid for v3.3 / v4.x and you are willing to work on it. |
6.x
/7.x
If you have uploaded a file with a name beginning with a left parenthesis
(
character, trying to download it with the route ez_content_download:/content/download/{contentId}/{fieldIdentifier}/{filename}
...means the filename gets interpreted as a view parameter. So the router thinks there are only 4 parameters, and it will actually match the route ez_content_download_field_id:
/content/download/{contentId}/{fieldId}
...which fails since the field identifier isn't a valid field id. This happens regardless of whether the filename is url encoded or not in the request.
Fixing it by
rawurlencode()
of the filename in theContentDownloadRouteReferenceListener
. Download using the redirect route (ez_content_download_field_id) works with this patch. This redirects to ez_content_download. However, calling ez_content_download directly still does not work with such filenames, and leads to the same error as before the patch. So the fix is incomplete, if we intend for direct use to be possible.TODO:
$ composer fix-cs
).