hasura / hasura/graphql-engine
HASURA_GRAPHQL_CORS_DOMAIN with wildcard subdomain is not working
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: `2.1.1`
### Environment
OSS
### What is the expected behaviour?
Based on the example described in [docs](https://hasura.io/docs/latest/graphql/core/deployment/graphql-engine-flags/config-examples/#configure-cors) 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:
```
HASURA_GRAPHQL_CORS_DOMAIN="https://*.example.pages.dev/,https://hasura.example.com,http://localhost:3000"
```
And load frontend making requests to the hasura instance from `https://subdomain.example.pages.dev`, then CORS error is thrown:
```
Access to fetch at 'https://hasura.example.com/v1/graphql' from origin 'https://subdomain.example.pages.dev' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
```
However, deploying Hasura with concrete values will resolve the issue:
```
HASURA_GRAPHQL_CORS_DOMAIN="https://subdomain.example.pages.dev/,https://hasura.example.com,http://localhost:3000"
```
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
Contributor guide
Research direction
Start by tracing how HASURA_GRAPHQL_CORS_DOMAIN is parsed and how origins are matched during CORS preflight requests. Reproduce the request using the wildcard and concrete-domain values shown in the issue; done means matching wildcard subdomains receive the appropriate Access-Control-Allow-Origin response without breaking explicit origins.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100