Skip to content
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

S3 pre-signed URL: error with unicode filename #455

Open
PhucNguyen0311 opened this issue Dec 20, 2021 · 11 comments
Open

S3 pre-signed URL: error with unicode filename #455

PhucNguyen0311 opened this issue Dec 20, 2021 · 11 comments

Comments

@PhucNguyen0311
Copy link
Contributor

Hi, I got an issue relative to S3 storage with Unicode filename.
image

Currently, the CloudFront pre-signed method (generate_presigned_url_cloudfront) uses a function to get a nice filename but S3 isn't. So, I think it would be good if S3 pre-signed function (generate_presigned_url_s3) has the same method.

@marxjohnson
Copy link
Contributor

@PhucNguyen0311 This looks like the right approach to me, however it introduces some duplicated logic. As you say, the cloudfront and s3 signing methods should do the same thing, so it would be good if they both did this by calling get_nice_filename(). Perhaps you could refactor that function slightly so that it returns the data in a format that can be used by both functions? This may require a small change to the cloudfront method too. For example, get_nice_filename() could return an array of content-disposition, filename and content-type, then generate_presigned_url_cloudfront() could use that to construct its query string while generate_presigned_url_s3() could use to it to construct its parameters.

PhucNguyen0311 added a commit to PhucNguyen0311/moodle-tool_objectfs that referenced this issue Dec 23, 2021
@PhucNguyen0311
Copy link
Contributor Author

@marxjohnson Thank you for your advice.
I updated the code for this fix. Please help me to review and let me know if you have any concerns.

@marxjohnson
Copy link
Contributor

@PhucNguyen0311 This fix looks good to me, @brendanheywood what do you think?

@almadog
Copy link

almadog commented Jun 8, 2022

Bumping this up - have been experiencing the same issue since we enabled s3 pre-signed urls.

@brendanheywood
Copy link
Contributor

@PhucNguyen0311 can you please rebase your patch

marxjohnson pushed a commit to marxjohnson/moodle-tool_objectfs that referenced this issue Jun 15, 2022
@marxjohnson
Copy link
Contributor

@brendanheywood I tried to contact @PhucNguyen0311 but didn't get a response, so I have done the rebase and created a new PR: #493

marxjohnson pushed a commit to marxjohnson/moodle-tool_objectfs that referenced this issue Jun 24, 2022
marxjohnson pushed a commit to marxjohnson/moodle-tool_objectfs that referenced this issue Jun 24, 2022
marxjohnson pushed a commit to marxjohnson/moodle-tool_objectfs that referenced this issue Jun 27, 2022
brendanheywood added a commit that referenced this issue Jun 27, 2022
S3 pre-signed URL: error with unicode filename #455
@tuanngocnguyen
Copy link
Contributor

Hi @marxjohnson

FYI, the commit "Set utf-8 encoding in signed URL filename header" is causing 403 error, so I create MRs to revert the commit.

@tuanngocnguyen
Copy link
Contributor

Hi @marxjohnson ,

I assume you are working on this, please let me know if it is not the case.
Thanks

@marxjohnson
Copy link
Contributor

Hi @tuanngocnguyen,
Thanks for addressing that, I have been on holiday so not had time to look at this further.
That commit was just an attempt to tidy things up, if it was causing problems I believe the original issue should still be resolved without it. I'm not sure that the utf8_encode() that was originally there is correct (we are starting with a UTF-8 string, so why encode it as UTF-8 again?) but in my testing it seemed to work as expected whether the filename was ISO-8859-1 only or UTF-8.

If we are happy that the original issue is resolved by Phuc's commit, then I would suggest we leave it there for now, if necessary we could open a separate issue for tidying up the Content-Disposition header and test it more thoroughly.

@tuanngocnguyen
Copy link
Contributor

Thanks @marxjohnson, let's wait for Brendan to review the issue.

@marxjohnson
Copy link
Contributor

We did also find an issue with MySQL compatability, so I have raised another PR to fix that: #503

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants