Hasura(GQL) 사용시 3rd-Party 쿠키 정책 문제
Q) credentials: "include" 인데도 쿠키 자동 전송 안될 수 있는거 맞음?
제가 cookie 기반에서 httponly, secured, domain, samesite 설명을 여러가지로 변주해서 시도해봤지만 결론은 브라우저의 third-party cookie 정책으로 인해 쿠키가 자동 전송되지 않는데 이게 맞나요?(심지어 서브도메인 - api.myapp.com <> myapp.com 이더라도)
A) 맞다.
맞아요. 결론부터 말하면: 브라우저가 Hasura로 쿠키를 보내주지 못하면(3rd‑party 쿠키 차단), Remote Schema를 써도 Hasura가 JWT를 검증할 수 없고, 따라서 x-hasura-user-id 같은 세션 변수도 생성되지 않습니다. 그래서 yoga 리졸버에서 userId를 받을 수 없어요.
왜 credentials: 'include'로는 부족한가
credentials: 'include'는 “보낼 수 있는 쿠키는 보내라”는 의미일 뿐, 브라우저의 3rd‑party 쿠키 정책을 우회하지 못합니다.- 다른 도메인(혹은 크로스‑사이트로 판정되는 서브도메인)으로 요청하면 최신 브라우저는 쿠키를 기본 차단합니다. 그래서 Hasura는 쿠키(JWT)를 못 받습니다.
const authLink = new SetContextLink(async (prevContext, _operation) => {
let token: string | null | undefined;
const headers = {
...prevContext.headers,
...(token && { authorization: `Bearer ${token}` }),
"x-request-from": isServer ? "server" : "client",
};
return { headers };
});
const httpLink = new HttpLink({
uri: endpoint,
credentials: "include",
...(!!hasuraAdminSecret && {
headers: { "x-hasura-admin-secret": hasuraAdminSecret },
}),
});
한줄 요약
- Hasura Remote Schema는 “Hasura가 인증을 끝내고 나서” 우리 yoga로 세션 변수를 넘겨줍니다. 브라우저의 3rd‑party 쿠키 차단으로 Hasura가 쿠키(JWT)를 못 받으면 인증 불가이므로, 같은 사이트 프록시나 BFF로 Authorization 헤더 전달이 필요합니다.
'TIL' 카테고리의 다른 글
| [251026 TIL] 실전적 Apollo Client 구현기 (0) | 2025.10.26 |
|---|---|
| [251024 TIL] Server 용 Apollo Client 생성시 주의점! (0) | 2025.10.24 |
| [251024 TIL] GraphQL Yoga 역할(+Hasura Remote Schema) (0) | 2025.10.24 |
| [251016 TIL] 테스트 환경 구축(vitest, rtl, msw, playwright) (0) | 2025.10.16 |
| [251015 TIL] 문자인증(알리고, with GQL) (0) | 2025.10.15 |