fix(s3-presigned-post): use starts-with condition for fields containing ${filename}#7771
Open
TrevorBurnham wants to merge 1 commit intoaws:mainfrom
Open
Conversation
…ng ${filename}
When a field value (e.g. success_action_redirect) contains the
${filename} variable, S3 substitutes it with the actual uploaded
filename at upload time. The SDK was generating an exact-match
policy condition for these fields, which caused a policy mismatch
and AccessDenied error because the substituted value no longer
matched the literal ${filename} string.
This extends the existing ${filename} handling (which already
worked for the Key field) to all user-provided Fields. Any field
value containing ${filename} now gets a starts-with condition
instead of an exact match, allowing S3's variable substitution
to work correctly.
Fixes aws#7191
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7191
Problem
When using
createPresignedPost()with${filename}in a field value (e.g.success_action_redirect), S3 rejects the upload withAccessDenied.S3 supports
${filename}variable substitution in POST uploads — at upload time, S3 replaces${filename}with the actual uploaded filename. However, the SDK generates an exact-match policy condition for all fields:{"success_action_redirect": "https://example.com/success?file=${filename}"}When S3 substitutes
${filename}with the real filename (e.g.test.txt), the field value becomeshttps://example.com/success?file=test.txt, which no longer matches the exact condition, causing a policy violation.The SDK already handles this correctly for the
Keyfield (line 82), but not for other fields.Solution
Extend the existing
${filename}detection to all user-providedFields. When a field value contains${filename}, generate astarts-withcondition instead of an exact match:This allows S3 to substitute
${filename}freely while still enforcing that the field value starts with the expected prefix.Changes
packages/s3-presigned-post/src/createPresignedPost.ts— check field values for${filename}and emitstarts-withconditionspackages/s3-presigned-post/src/createPresignedPost.spec.ts— add test for${filename}in field valuesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.