Skip to content
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

enable simple cors on all chainweb endpoints #79

Merged
merged 6 commits into from
Mar 28, 2019

Conversation

larskuhtz
Copy link
Contributor

No description provided.

@eskimor
Copy link
Contributor

eskimor commented Mar 27, 2019

It builds now - I have not yet checked whether it actually works. That part is not straight forward without an actual deployment. @larskuhtz - I will try to check locally with an http build, do you have the means to deploy this to some server for testing?

@eskimor
Copy link
Contributor

eskimor commented Mar 27, 2019

@larskuhtz I was able to test and what I was afraid of, we need to add header "content-type" to the list of allowed headers.

@eskimor
Copy link
Contributor

eskimor commented Mar 27, 2019

Actually 'content-type' is in simpleHeaders, but simpleHeaders is not included in simpleCorsResourcePolicy which seems incorrect.

@larskuhtz
Copy link
Contributor Author

If I remember correctly not all headers and in particular content types are allowed in simple cors. So we may need a non-simple cors policy in that case.

@eskimor
Copy link
Contributor

eskimor commented Mar 27, 2019

I dug a little deeper. simpleHeaders include content-type - but the simple policy does not include simpleHeaders, but none - relying on a default that is simple headers excluding content-type.

I still haven't read the standard yet, so there might be a reason for this unintuitive implementation.

@larskuhtz
Copy link
Contributor Author

Simple CORS requests are subject to the following constraint:

If the request is a POST request the content type is constraint to simple content types (application/x-www-form-urlencoded, multipart/form-data, text/plain),

CORS is weird. In the standard they try to not break existing common HTTP scenarios, so their are a lot of special cases.

The complete list of constraints is in the documentation of wai-cors:

http://hackage.haskell.org/package/wai-cors-0.2.6/docs/Network-Wai-Middleware-Cors.html#v:simpleCorsResourcePolicy

@larskuhtz
Copy link
Contributor Author

This is the haddock documentation for cors headers:

corsRequestHeaders :: ![HeaderName]
Field names of HTTP request headers that are allowed in CORS requests. Header names that are included in simpleHeaders, except for content-type, are implicitly included and thus optional in this list.

I didn't make that stuff up. It's actually in the standard. :-)

@larskuhtz
Copy link
Contributor Author

I think the easiest is if you take look at the documentation here http://hackage.haskell.org/package/wai-cors-0.2.6/docs/Network-Wai-Middleware-Cors.html#v:CorsResourcePolicy and define a CORS policy that meets your needs.

Once we know what we need I can either update the PR or you can push directly to it.

@mightybyte mightybyte merged commit bebc128 into master Mar 28, 2019
@mightybyte mightybyte deleted the lars/add-simple-cors branch March 28, 2019 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants