aws-samples / image-optimization

Simple, performant and cost efficient solution for optimizing images using Amazon CloudFront, Amazon S3 and AWS Lambda
MIT No Attribution
172 stars 106 forks source link

Special characters in URL file name causing signature mismatch #44

Closed sixides closed 6 days ago

sixides commented 1 month ago

Hope you can help advice as we have images that has + and even spaces (which URL would encode it as %20), when this happens the error below is shown. Any other images works fine. Been researching all over and checking but couldn't find a solution other than having to rename all the files in the origin bucket.

{ "message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details." }

achrafsouk commented 1 month ago

Hey,

it seems that this not working when CloudFront is signing the request to S3 with the OAC feature. Until, we figure out the reason, what you can do is encode the url in the CloudFront Function, then decode it in the Lambda function when retrieving the object from S3

sixides commented 1 month ago

Hi thanks for replying. I actually did try manually replacing the space with %20 like this 2577575540143-Green%20Firm.png in the URL and it also causes the same error. If getting this exact filename directly S3 link its perfectly fine.

https://d1ypz6uabe5poc.cloudfront.net/uploads/2577575540143-Green%20Firm.png (fails) https://sixides.s3.ap-southeast-1.amazonaws.com/uploads/2577575540143-Green%20Firm.png (ok)

achrafsouk commented 1 month ago

I have dived into it. It's related to a bug under investigation / fix in OAC with Lambda. Until we have a permanent fix you can:

sixides commented 1 month ago

Hi thanks for the feedback. Will try to do the workaround. It also doesn't work with other languages (non english letters). Hope the bug gets squashed soon. :)

achrafsouk commented 2 weeks ago

The fix is being deployed, should be done in a week or so

achrafsouk commented 1 week ago

seems to be fixed now, can you test again?

sixides commented 6 days ago

@achrafsouk Hi there, yes have tested with %20, Chinese characters and other Unicode characters in the filename and it all works. Thank you so much.