moodle-tool_objectfs icon indicating copy to clipboard operation
moodle-tool_objectfs copied to clipboard

S3 pre-signed URL: error with unicode filename

Open PhucNguyen0311 opened this issue 3 years ago • 11 comments

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.

PhucNguyen0311 avatar Dec 20 '21 01:12 PhucNguyen0311

@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.

marxjohnson avatar Dec 22 '21 09:12 marxjohnson

@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.

PhucNguyen0311 avatar Dec 23 '21 09:12 PhucNguyen0311

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

marxjohnson avatar Dec 23 '21 14:12 marxjohnson

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

almadog avatar Jun 08 '22 15:06 almadog

@PhucNguyen0311 can you please rebase your patch

brendanheywood avatar Jun 10 '22 01:06 brendanheywood

@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 avatar Jun 15 '22 09:06 marxjohnson

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 avatar Jul 01 '22 03:07 tuanngocnguyen

Hi @marxjohnson ,

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

tuanngocnguyen avatar Jul 12 '22 01:07 tuanngocnguyen

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.

marxjohnson avatar Jul 12 '22 07:07 marxjohnson

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

tuanngocnguyen avatar Jul 13 '22 23:07 tuanngocnguyen

We did also find an issue with MySQL compatability, so I have raised another PR to fix that: https://github.com/catalyst/moodle-tool_objectfs/pull/503

marxjohnson avatar Jul 14 '22 07:07 marxjohnson