-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix duplicate conditions in S3 presigned POST policy generation #8541
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
base: preview
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,21 +62,16 @@ def generate_presigned_post(self, object_name, file_type, file_size, expiration= | |
| """Generate a presigned URL to upload an S3 object""" | ||
| if expiration is None: | ||
| expiration = self.signed_url_expiration | ||
| fields = {"Content-Type": file_type} | ||
| fields = { | ||
| "Content-Type": file_type, | ||
| "bucket": self.aws_storage_bucket_name, | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bucket incorrectly added to fields instead of being removedHigh Severity The PR description states the intent is to remove manually-set
Comment on lines
+65
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for generate_presigned_post usage and tests in the codebase
rg -n 'generate_presigned_post' --type=py -A 10 -B 2Repository: makeplane/plane Length of output: 17121 🌐 Web query:
💡 Result: Short answer: The boto3 S3 client method generate_presigned_post(Bucket, Key, Fields=None, Conditions=None, ExpiresIn=3600) requires Bucket and Key. The Fields parameter is a dict of pre-filled form fields you want included in the POST (examples accepted: acl, Cache-Control, Content-Type, Content-Disposition, Content-Encoding, Expires, success_action_redirect / success_action_status, and x-amz-meta-*). Bucket- and Key-related conditions/fields are handled for you and should not be included in Fields or in Conditions; if you include an element in Fields you must also include a matching Condition. See the official docs. [1][2] Sources
Remove Per AWS boto3 documentation, bucket and key are handled automatically by boto3 and should not be included in the 🤖 Prompt for AI Agents |
||
|
|
||
| conditions = [ | ||
| {"bucket": self.aws_storage_bucket_name}, | ||
| ["content-length-range", 1, file_size], | ||
| {"Content-Type": file_type}, | ||
| ] | ||
|
|
||
| # Add condition for the object name (key) | ||
| if object_name.startswith("${filename}"): | ||
| conditions.append(["starts-with", "$key", object_name[: -len("${filename}")]]) | ||
| else: | ||
| fields["key"] = object_name | ||
| conditions.append({"key": object_name}) | ||
|
|
||
| # Generate the presigned POST URL | ||
| try: | ||
| # Generate a presigned URL for the S3 object | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the boto3 documentation and the PR description, bucket should not be included in the Fields parameter. The boto3 library automatically handles the bucket when it's passed as the Bucket parameter to generate_presigned_post(). Including it in fields will still cause duplicate bucket conditions in the generated policy. This line should be removed, leaving only the Content-Type field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation only mentions
conditionsand notfieldsfor bucket.