# Storing access tokens in HttpOnly Secure SameSite=Strict cookie?

**URL:** <https://community.auth0.com/t/storing-access-tokens-in-httponly-secure-samesite-strict-cookie/132422>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [April 19, 2024, 8:10pm UTC](https://community.auth0.com/t/storing-access-tokens-in-httponly-secure-samesite-strict-cookie/132422 "2024-04-19T20:10:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam2099](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sam2099/32/49800_2.png) [@sam2099](https://community.auth0.com/u/sam2099)\
**Post date:** [April 19, 2024, 8:10pm UTC](https://community.auth0.com/t/storing-access-tokens-in-httponly-secure-samesite-strict-cookie/132422/1 "2024-04-19T20:10:58Z")

</div>

Setup:

Proxy Server

- handles domain and routes requests

Micro Frontends

- domain/app1, domain/app2, etc.

Distributed APIs

- domain/api/app1, domain/api/app2, etc.

Proposed Flow:

1. Auth flow started by user using auth code grant
2. Backend receives auth code grant, exchanges for access token, and sets the token as a cookie w/ HttpOnly Secure SameSite=Strict
3. One of the micro front-ends tries to make a request to an API
4. The proxy server receives the request and moves the cookie value to the Authorization header as a Bearer token before sending the request to the respective API service

I felt the following configuration on the cookie would make this a reasonable approach:

- HttpOnly protects against XSS attacks and prevents JS code for reading the cookie
- SameSite=Strict protects agains CSRF

Would this be considered good/safe practice? I have been told storing access tokens in the browser anywhere is not safe/encouraged.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [April 30, 2025, 4:51pm UTC](https://community.auth0.com/t/storing-access-tokens-in-httponly-secure-samesite-strict-cookie/132422/2 "2025-04-30T16:51:21Z")

</div>

Hi @sam2099,

Welcome to the Auth0 Community! Answering this since it might help others as well.

Your understanding is very on point! Generally storing access tokens in the browser directly is not recommended, but Auth0 recommends storing tokens in browser memory as the most secure option. Using [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) to handle the transmission and storage of tokens is the best way to protect them, mentioned in our [documentation](https://auth0.com/docs/secure/security-guidance/data-security/token-storage#browser-in-memory-scenarios) as well.

However your approach is quite solid as well, since sending an encrypted cookie mitigates risks against XSS or CSRF attacks . This blog post on [Secure Browser Storage](https://auth0.com/blog/secure-browser-storage-the-facts/#Browser-Security-Basics--The-Same-Origin-Policy) provides a detailed information on the matter.

Thanks,  
Remus

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 14, 2025, 4:51pm UTC](https://community.auth0.com/t/storing-access-tokens-in-httponly-secure-samesite-strict-cookie/132422/3 "2025-05-14T16:51:41Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
