-
Notifications
You must be signed in to change notification settings - Fork 37
Fix: Improve sanitization of folder and file names #209
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
Fix: Improve sanitization of folder and file names #209
Conversation
df70c23 to
af30a92
Compare
|
Could I get approval for workflows? |
af30a92 to
c6aff2f
Compare
|
I’ve tested the code with a couple of scenarios and it works perfectly:
However, I think I may have found a potential design issue: The code is inconsistent on how file names are sanitised |
c6aff2f to
a95301e
Compare
|
Updated the code be consistent and match the sanitation in nextcloud/server#27891 |
Signed-off-by: Ahsan Ahmed <ahmedah05@outlook.com>
a95301e to
d3a81f2
Compare
|
Hello @AhsanIsEpic |
544017f to
ab78970
Compare
…and Photos services using IFilenameValidator Signed-off-by: Ahsan Ahmed <ahmedah05@outlook.com>
ab78970 to
a44e74f
Compare
I ended up creating a shared utility function to handle all the possible errors that can be thrown from IFilenameValidator. I could of just replaced the filename with the file ID however, I wanted to keep the filename intact as much as possible. Introduction of Utility Function:
Integration of Utility Function:
|
lib/Service/Utils/FileUtils.php
Outdated
| default: | ||
| $logger->error('Unknown exception encountered during filename sanitization: ' . $filename); | ||
| $filename = 'Untitled'; | ||
| break; |
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.
Wow, this is a really elaborate. Thank you for the effort you put into this! I was actually thinking more of something like this: https://github.com/nextcloud/server/pull/51608/files#diff-911ea9939fad17c78ada50c38706874091e2478e37a2ef5a155481c0c4a81a98R144-R165 But it turns out the methods used there are not in OCP :(
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.
I'm inquiring now if we can get a proper sanitization method in OCP to avoid parsing error messages from the validator, which seems a bit brittle
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.
Here we go: nextcloud/server#52688
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.
Nextcloud 32 will have that method in OCP
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
|
Are you still interested in finishing this PR? |
I'm still interested in finishing this PR, however I'm unsure if I should be waiting for nextcloud 32 to be released before completing this MR or would it be fine to use the development version? |
|
We can implement this against nextcloud 32 and release it when nextcloud 32 is released, excluding support for nextcloud < 32 |
|
Optionally, we can also check if the method exists in the class and only use it if it exists. That would allow to support versions < 32 |
…on handling and use built in validator for nextcloud 32+ Signed-off-by: Ahsan Ahmed <ahmedah05@outlook.com>
57fddfc to
19afaf5
Compare
I've added a few lines to check if the OCP version is 32 or higher, and use the built-in validator in that case (still need to run some tests on it). Would you prefer that I remove the sanitation logic I previously added and revert to the way they were originally for older versions, or should we keep it? |
|
Looks good! |
…anIsEpic/integration_google into AhsanIsEpic-fix/improve-folder-creation-handling
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
a06d173 to
d33630a
Compare
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
d33630a to
4b4d171
Compare
|
Thank you so much for your contribution @AhsanIsEpic |
|
Hi @AhsanIsEpic ! Cheers |
|
Sent an email across @marcelklehr |
This pull request fixes #208, where folders with a space at the end of their name cause the Google Drive import to fail.
I’m not very experienced with PHP, please review thoroughly