Skip to content

Adding Support for AWS Presigned URLs

Latest

Choose a tag to compare

@copiri-six copiri-six released this 30 Oct 14:21

AWS Presigned URLs (PSUs) add a significant amount of data to the end of a file name. For example, this is a valid AWS PSU:

image.png?x-amz-content-sha256=unsigned-payload&x-amz-algorithm=aws4-hmac-sha256&x-amz-credential=akiar3l4y7y1mkgb6aw4%2f20220131%2fus-west-1%2fs3%2faws4_request&x-amz-date=20220131t120000z&x-amz-signedheaders=host&x-amz-expires=3600&x-amz-signature=df9632469e18117a08c1977e24b4f8692705c9fdd57429eb57c2bf9386

Because the Image() function attempts to determine the image type (when not provided) by simply checking the value of everything to the right of the last period (.), this means that the entire set of AWS PSU data is attempted to be matched against values like "png", "jpg", etc. Of course, this will not match.

This update cleans up the code in the Image() function to make it more readable, and also checks for a question mark (?) in the provided file name. If one is found, it and everything after the question mark are removed.

Note that while it is possible that this adjustment might inadvertently cut off a part of the file name -- if it contains a question mark but is not an AWS PSU -- this is seen as an acceptable risk since web-based filenames should not use the reserved question mark character (instead, they should be URL-encoded).