I am pretty sure that the answer to my question is no, but I have been have a hard time finding an answer through official documentation or other posts here. Here is simple use case for some context:
- Python backend web application (api.domain.com)
- Frontend JavaScript SPA (app.domain.com)
- post requests to
api.domain.com/api/auth/login/
made fromapp.domain.com
using axios with the correctusername
andpassword
return a response with anaccess
JWT token in the body and the response sets arefresh
cookie with an HttpOnly flag [should fail, since I believe that the cookie cannot be set onapp.domain.com
from an API request toapi.domain.com
? -- this is my question] - the
access
token is stored in memory and passed with each API request - requests made to
api.domain.com/api/auth/refresh/
are sent on a schedule to refresh the short-livedaccess
token.
I typically host the frontend app and backend app on the same subdomain (app.domain.com
) and do path-based routing with something like CloudFront or nginx, and this works well. For example, all requests starting with /api/*
are sent to the backend, and all other requests are sent to the frontend app. Trying to use a separate subdomain for the API seems to fail no matter what options I use for setting the cookie on the server.
Can someone help me confirm that it is in fact not possible to set an HttpOnly cookie on a subdomain like app.domain.com
from an API request hosted on api.domain.com
? It would be great if anyone can also help me find where this could possibly be found in official documentation.
Searching for set httpOnly cookie across subdomains
, I haven't found anything directly relevant. I also didn't find anything in these resources that directly answers my question:
https://owasp.org/www-community/HttpOnly
https://docs.microsoft.com/en-us/previous-versions//ms533046(v=vs.85)?redirectedfrom=MSDN