Skip to content

Conversation

@dekobon
Copy link
Collaborator

@dekobon dekobon commented Nov 29, 2022

Fixes #62

Add support for CORS response headers.

This commit adds support for CORS response headers.

Signed-off-by: Elijah Zupancic <e.zupancic@f5.com>
Copy link
Collaborator

@4141done 4141done left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did see an issue that would lead to "if inside location block" in the cors.conf I think we should discuss before merging.

else
export LIMIT_METHODS_TO="GET HEAD"
export LIMIT_METHODS_TO_CSV="GET, HEAD"
fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(posting for visibility, not a change request) I had questions about whether it was necessary to fork the logic here just to exclude OPTIONS since it has general usage outside the context of CORS. However it seems that for S3 it's only really applicable to the CORS case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems unnecessary because this approach is stemming from my security paranoia. I don't want to provide any paths to allow for proxying requests to the underlying S3 bucket beyond the narrow operations defined. As such, I'm going out of my way here to lock down the HTTP verbs to only GET/HEAD or in the case of CORS GET/HEAD/OPTIONS.

add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is included in a location block, could/should this be rewritten using map to avoid the "if is evil in a location block" issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the OPTIONS if, it seems to fall under the category of "good ifs":

There are cases where you simply cannot avoid using an if, for example, if you need to test a variable which has no equivalent directive.

As for the other ifs, I believe they are ok due to there being no ifs after them. However, I have no idea how you would be able to do the same operation with map. Ideally, I wanted to conditionally template in the cors.conf include, but that seemed a bit too clunky. I guess I could conditional set an env var with the whole include statement in docker-entrypoint.sh.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this certainly is the best for understandibility. I wouldn't add more moving parts if it's testing ok. I'm going to play around with making it work with map because I'm curious now but let's not let it hold up the PR.

add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why Access-Control-Expose-Headers is not sent in the OPTIONS response?

Copy link
Collaborator

@4141done 4141done left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🐳 👍
This one looks good to me - I have one outstanding question around a header included for all methods except OPTIONS but if that's not a big deal let's merge it 🐎

@dekobon dekobon requested a review from worace December 1, 2022 00:19
@dekobon
Copy link
Collaborator Author

dekobon commented Dec 3, 2022

@worace I'll be waiting a week for your review/test and then we will merge

@dekobon dekobon merged commit 1828f68 into master Dec 14, 2022
@dekobon dekobon deleted the issue/62 branch December 14, 2022 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible to support OPTIONS requests for CORS?

3 participants