Getting sameSite cookie warning from auth0.is.authenticated
Description
Firefox console reports that
"Cookie “auth0.is.authenticated” will be soon rejected because it has the “sameSite” attribute set to “none” or an invalid value, without the “secure” attribute.
Checking node_modules/@auth0/auth0-spa-js/src/storage.ts shows that the cookie is being created with secure: true, sameSite: 'none', as well as the actual cookie: set-cookie: auth0=... Path=/; Expires=Mon, 10 Aug 2020 23:33:29 GMT; HttpOnly; Secure; SameSite=None.
This is an issue when using Brave with default settings, or if a user has crossSite cookies disabled because it doesn't save the user login session.
Reproduction
Followed the most recent React SDK blog post creating an SPA.
Environment
- Version of this library used: "^1.0.0"
- Other relevant versions: Arch Linux using Firefox/Brave Browsers
Hi @chefinDan - this is expected at the moment, we're currently looking at options in auth0-spa-js for how to resolve this warning before it turns into an error.
@adamjmcgrath, it seems that Chrome has started to roll out this kind of cookie rejection to 100% of users since Aug. 11 (source: https://www.chromium.org/updates/same-site?pli=1#20200811). Due to this change, I believe Chrome is preventing getAccessTokenSilently() from being used with dynamically changing scopes. I plan on opening a separate issue for this once I can confirm it's an SDK bug.
Hi @rpaulucci3 thanks for your input
it seems that Chrome has started to roll out this kind of cookie rejection to 100% of users since Aug. 11
Chrome is rolling out 2 things:
SameSite=None-requires-Secure Any cookie that requests SameSite=None but is not marked Secure will be rejected.
SameSite-by-default Treat cookies as SameSite=Lax by default if no SameSite attribute is specified.
So, with the "SameSite=None-requires-Secure" changes, Chrome will reject cookies if they explicitly are set to SameSite=None but not marked as secure. We use [email protected] which does not set SameSite=None for its cookies (https://github.com/auth0/auth0-spa-js/blob/v1.9.0/src/storage.ts#L21-L23) so will not be affected by this change.
Since we're not setting a value for SameSite we will be affected by "SameSite-by-default" - the default value of the cookie's SameSite will go from None to Lax. This will affect cookies that are required in a cross-origin context (such as HTTP Form Post, embedding an iframe) - for SPAs this essentially means you're affected if you're setting a cookie on a domain that doesn't match the one in the address bar. Therefore if your SPA is served in an iframe those cookies will be blocked as a result of this change. We strongly recommend you don't serve your app and login flow in an iframe, so we don't expect this to cause problems.
Due to this change, I believe Chrome is preventing getAccessTokenSilently() from being used with dynamically changing scopes.
getAccessTokenSilently() does rely on third-party cookies, those of your tenant's on auth0.com. Be assured that the cookies on auth0.com have been updated to accommodate this change, so will not be affected, more details here https://auth0.com/docs/sessions-and-cookies/samesite-cookie-attribute-changes#browser-cookie-changes
dynamically changing scopes
If you're calling getAccessTokenSilently() with different scopes and it's not working. Especially if you're on localhost, It may be rejected because of user consent issues. If that's the case have a look at https://auth0.com/docs/authorization/user-consent-and-third-party-applications#skip-consent-for-first-party-applications and our example that shows how to handle consent_required errors https://github.com/auth0/auth0-react/blob/master/EXAMPLES.md#4-create-a-useapi-hook-for-accessing-protected-apis-with-an-access-token
@adamjmcgrath getAccessTokenSilently() does rely on third-party cookies, those of your tenant's on auth0.com. Is there any plan to move away from this? It prevents this functionality from working in contexts where 3rd party cookies are blocked, such as Incognito Mode, or whole browsers such as Safari and Brave.
@charliemic Yes - we implemented the option to use rotating Refresh Tokens for exactly this reason, but it's not the default.
This is implemented in the underlying SDK - Auth0 SPA SDK, which accepts the useRefreshTokens option, and you are able to configure that using auth0-react in the provider:
ReactDOM.render(
<Auth0Provider
domain="YOUR_AUTH0_DOMAIN"
clientId="YOUR_AUTH0_CLIENT_ID"
redirectUri={window.location.origin}
useRefreshTokens={true}
>
<App />
</Auth0Provider>,
document.getElementById('app')
);
You also need to configure Refresh Token Rotation in your Auth0 Client app for this to work.
Ah, it was the token rotation we're missing - thanks for the help! 👍
@stevehobbsdev I have set useRefreshTokens to true and enabled Refresh Token Rotation in my client app settings but isAuthenticated is still false after page reload when using incognito mode or Safari for instance.
Any idea on what could be missing here? Thanks in advance!
UPDATE: Nevermind, setting cacheLocation to localstorage solved the issue!
How interesting - I'm still getting this issue despite setting cacheLocation and useRefreshTokens. Any idea what else I could try?