Hasura doesn't forward Set-Cookie headers set by remote schemas
See original GitHub issueHasura should forward Set-Cookie
headers back to the client that are set in Remote Schemas, so that the consumer of the GraphQL API receives them.
- In order to use cookie-based authentication with Hasura, we need to make sure
Cookie:
headers are successfully passed to the GraphQL endpoint, so our auth webhook can extract useful information and pass inX-Hasura-*
headers back to Hasura. - One of the primary reasons to use cookies is the
HttpOnly
flag, which prevents against vendor javascript running on the same page from stealing our sessions. - If
Set-Cookie:
headers don’t come from the same origin as Hasura, something likecredentials: 'include'
is necessary for cookies to actually be included in GraphQL requests, at least over HTTP (Queries and Mutations). - Unfortunately, WebSockets don’t seem to have any ability to
credentials: 'include'
and simply will not pass cookies from different origins no matter what, which means that there is currently no way to use http-only cookie-based authentication and subscriptions at the same time with Hasura. - Manually adding the
Cookie:
header to the WebSocket client could be an option, but we lose the ability to useHttpOnly
cookies as client-side javascript would be required to parse them to build this header. - This also allows a cleaner front-end coding experience; all calls can be done via GraphQL.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:23 (12 by maintainers)
Top Results From Across the Web
Forwarding auth context to/from remote schemas - Hasura
Hasura will forward the resolved x-hasura-* values as headers to your remote schema. You can use this information to apply authorization rules in...
Read more >How to send cookies using Hasura - Stack Overflow
The Set Cookie header has to be the response from the Django authentication service, if both services are running in localhost, the Browser...
Read more >Rust Server That Functions As A Remote Schema for Hasura - Morioh
This is an example of a Rust server that functions as a remote schema for Hasura. User login + signup, JWT authorization w/...
Read more >Source - GitHub
Hasura GraphQL Engine Changelog :warning: This file is deprecated and ... same URL path but different method - server: forward Set-Cookie headers from...
Read more >Configuring CORS - Apollo GraphQL Docs
Any request that sets the Content-Type header to application/json (or anything other than a list of three particular values) cannot be a simple...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@campie I was wondering if you have an example of cookie auth via auth webhook like you described?
Gotcha. Here’s some thoughts:
Your second point is interesting. Multiple
Set-Cookie
headers are absolutely fine in an HTTP response; however, there may be clashes if they share the same cookie name. RFC 6265 says:The suggested client behaviour can be found in Section 5.3. My interpretation of the algorithm in this section is that later
Set-Cookie
headers with the same cookie-name should override earlier ones in the client’s cookie store. My suggestion is that the headers should be returned in the same order as the client sent them in, in order to allow developers to express ordering via the mutation / query they send to Hasura. Given the different specs for different headers, a whitelist of proxy-able headers probably makes sense to make sure Hasura can properly merge / overwrite depending on whether multiple versions of the same response header are allowed in the spec.So in your example, both
Set-Cookie
headers would be passed back to the GraphQL client; this behaviour is consistent with theSet-Cookie
RFC.