Open TeoTN opened 2 years ago
@TeoTN We run into an intermittent issue with our site that uses Cloudflare pages calling Hasura and getting CORs issues. You ever find a solution for this? What's weird is most of the time it works but then gets into a weird state where every request ends us a 403 with xxx has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
Server Version: v2.31.0-cloud.1
Environment: Cloud
Also running into the same issue, with given configuration
HASURA_GRAPHQL_CORS_DOMAIN="https://*.example.com"
an OPTIONS
request with origin https.example.com
does not return any CORS headers but a request with origin https://*.example.com
returns the correct CORS headers.
Could it be that the code handling the CORS header matching is doing exact matches instead of treating wildcards properly?
This is the command I'm using to replicate
httpie \
OPTIONS \
https://{{my-hasura-cloud-instance}}.hasura.app/v1/graphql \
Access-Control-Request-Headers:authorization,content-type \
Access-Control-Request-Method:POST \
Cache-Control:no-cache \
Origin:https://*.example.com \
--pretty=all \
--print hH
@TeoTN can you trying changing the value for the env to:
HASURA_GRAPHQL_CORS_DOMAIN="https://*.example.pages.dev,https://hasura.example.com,http://localhost:3000"
(removed the trailing slash from https://*.example.pages.dev/
)
Hasura does support wildcards in CORS policy, so it should work.
@zqureshi I am not sure why you were not able get it working. I tried it on one of my hasura cloud project () and it worked as expected. I used curl for this:
curl -verbose --location --request OPTIONS 'https://<my-cloud-subdomain>.hasura.app/v1/graphql' \
--header 'Content-Type: application/json' \
--header 'x-hasura-admin-secret: <my-super-secret>' \
--header 'Origin: https://*.example.com' \
--data '{"query":"query MyQuery {\n author {\n name\n }\n}\n","variables":{}}'
I got the following response (which had the CORS headers):
* Trying <hasura-cloud-ip>...
* Connected to <my-cloud-subdomain>.hasura.app (<hasura-cloud-ip>) port <<hasura-cloud-port> (#0)
....
< access-control-allow-origin: https://*.example.com
< access-control-allow-credentials: true
< access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
< access-control-expose-headers: X-Hasura-Query-Cache-Key,X-Hasura-Query-Family-Cache-Key,Warning
< cf-cache-status: DYNAMIC
< content-security-policy: upgrade-insecure-requests
< referrer-policy: strict-origin-when-cross-origin
...
* Connection #0 to host <my-cloud-subdomain>.hasura.app left intact
@johnkoehn, Can you please give me more information about the state when the requests fail? Please get some traces of the request sent to the graphql-engine.
I'm experiencing the same issue. For some reason it doesn't work when there is a -
or _
in the URL. I'm using the Cloud environment as well:
Config:
HASURA_GRAPHQL_CORS_DOMAIN=https://*.foobar.pages.dev,https://*.foo-bar.pages.dev
No hyphen:
curl -verbose --location --request OPTIONS 'https://heimdall.hasura.app/v1/graphql' \
--header 'Content-Type: application/json' \
--header 'Origin: https://foo.foobar.pages.dev'
< HTTP/2 404
...
< access-control-max-age: 1728000
< access-control-allow-headers:
< access-control-allow-origin: https://foo.foobar.pages.dev
< access-control-allow-credentials: true
< access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
< access-control-expose-headers: X-Hasura-Query-Cache-Key,X-Hasura-Query-Family-Cache-Key,Warning
With hyphen:
curl -verbose --location --request OPTIONS 'https://<my-cloud-subdomain>.hasura.app/v1/graphql' \
--header 'Content-Type: application/json' \
--header 'Origin: https://foo.foo-bar.pages.dev'
...
< HTTP/2 404
...
< content-security-policy: upgrade-insecure-requests
< referrer-policy: strict-origin-when-cross-origin
<
...
Not Found%
Version Information
Server Version:
2.1.1
Environment
OSS
What is the expected behaviour?
Based on the example described in docs I would expect that providing wildcard for subdomain in
HASURA_GRAPHQL_CORS_DOMAIN
would work.Keywords
HASURA_GRAPHQL_CORS_DOMAIN
What is the current behaviour?
When I deploy Hasura with following values:
And load frontend making requests to the hasura instance from
https://subdomain.example.pages.dev
, then CORS error is thrown:However, deploying Hasura with concrete values will resolve the issue:
It would be nice if Hasura handled setup with wildcards, since CloudFlare Pages makes preview deployments of frontend available at various subdomains.
How to reproduce the issue?
See above for reproduction steps