fix CORS issue for CreateBucket and ListBuckets#7961
Merged
Conversation
3f7c850 to
c5e1d2c
Compare
thrau
approved these changes
Mar 25, 2023
Member
thrau
left a comment
There was a problem hiding this comment.
as discussed, i think this is a reasonable solution for now! getting CORS right with s3 in combination with localhost:4566 and other routes is tricky in our handler chain, so having a bit of workarounds in s3 seems fine to me!
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.
It seems we missed a scenario when creating the new CORS handling for S3:
If we do a
CreateBucketrequest not targeting the S3 specific endpoint (like we do from the web app), we cannot know for sure that the request is targeting S3 (it is a simplePUTrequest with a path, nothing else), because the bucket does not exist yet. So, the pre-process handler does not add any headers, and the request is seen as "self-managed" by the default CORS enforcer / enricher because it targets S3, so nobody adds the right headers in the end.The solution for now is to let the handler chain execute before handing the request to the skeleton, and if the request is
CreateBucketorListBuckets, we will use the default LocalStack CORS handling to enrich the response with the right headers, only of the origin is allowed. Otherwise, we will reject the request. At least we won't get any side effect directly in the provider.\cc @lukqw, thanks for finding and helping in reproducing the issue!