Repository navigation
fix(frontend): add explicit domain to cookies to fix iOS Safari auth persistence - #8454
Prospector wants to merge 1 commit into
Conversation
…persistence iOS Safari's Intelligent Tracking Prevention (ITP) can be aggressive with cookies that don't have an explicit domain attribute. This was causing users to be logged out every time they opened the site on mobile Safari. Changes: - Created shared getCookieDomain() utility that sets domain to .modrinth.com (or appropriate domain) for all production cookies - Updated all cookie declarations to include the domain attribute: - auth-token (main authentication cookie) - auth-stored-accounts-v2 (account switching) - auth-session-created (session tracking) - cosmetics (UI preferences) - color-mode (theme settings) - feature flags - moderation settings - CDN download context This ensures cookies work consistently across www.modrinth.com and modrinth.com, and are more resistant to iOS Safari's tracking prevention. Co-authored-by: Prospector <Prospector@users.noreply.github.com>
Pull request changelogAppAddedChangedDeprecatedRemovedFixedSecurityWebsiteAddedChangedDeprecatedRemovedFixedSecurityHostingAddedChangedDeprecatedRemovedFixedSecurity |
|
This pull request is closed, so it cannot be queued. Reopen it to get the box back. |
|
man i just asked it a question and it went and made a whole slop PR 😭 |
[High impact] The change reaches sign-in and preference cookies across the frontend's matching subdomains. Fix cookie migration and domain selection before merging.
|
| return useCookie<string | null>(AUTH_COOKIE_NAME, { | ||
| ...AUTH_COOKIE_OPTIONS, | ||
| secure: config.public.cookieSecure, | ||
| domain: getCookieDomain(), |
There was a problem hiding this comment.
Old cookies survive session clearing
For someone already signed in on www.modrinth.com or staging.modrinth.com, clearing auth-token now deletes only the .modrinth.com cookie. The old host-only cookie remains valid, so browseSignedOut() reloads the page and signs them back in. Move the old value and expire its host-only copy before using the new scope. Apply the same migration to the changed preference cookies.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/frontend/src/composables/auth-cookie.ts
Line: 20
Comment:
**Old cookies survive session clearing**
For someone already signed in on `www.modrinth.com` or `staging.modrinth.com`, clearing `auth-token` now deletes only the `.modrinth.com` cookie. The old host-only cookie remains valid, so `browseSignedOut()` reloads the page and signs them back in. Move the old value and expire its host-only copy before using the new scope. Apply the same migration to the changed preference cookies.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const parts = hostname.split('.') | ||
| if (parts.length >= 2) { | ||
| return `.${parts.slice(-2).join('.')}` |
There was a problem hiding this comment.
Sites overwrite each other's sessions
getCookieDomain() returns .modrinth.com for both production and staging.modrinth.com, although staging uses a different API. It also returns .rinth.dev for every production and staging preview. These sites now overwrite the same auth-token and preference cookies. Signing in or clearing a session on one site changes the session used by the others. Keep separate environments and previews in separate cookie scopes.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/frontend/src/composables/cookie-domain.ts
Line: 17-19
Comment:
**Sites overwrite each other's sessions**
`getCookieDomain()` returns `.modrinth.com` for both production and `staging.modrinth.com`, although staging uses a different API. It also returns `.rinth.dev` for every production and staging preview. These sites now overwrite the same `auth-token` and preference cookies. Signing in or clearing a session on one site changes the session used by the others. Keep separate environments and previews in separate cookie scopes.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const parts = hostname.split('.') | ||
| if (parts.length >= 2) { | ||
| return `.${parts.slice(-2).join('.')}` |
There was a problem hiding this comment.
Hosted deployments cannot save cookies
If the site runs on a Heroku or Vercel hostname supported by getDomain(), taking the final two labels produces .herokuapp.com or .vercel.app. Browsers reject cookies scoped to these shared hosting suffixes, so all updated cookies—including auth-token—stop saving. Return undefined for shared hosting domains, or choose a domain that the deployment actually owns.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/frontend/src/composables/cookie-domain.ts
Line: 35-37
Comment:
**Hosted deployments cannot save cookies**
If the site runs on a Heroku or Vercel hostname supported by `getDomain()`, taking the final two labels produces `.herokuapp.com` or `.vercel.app`. Browsers reject cookies scoped to these shared hosting suffixes, so all updated cookies—including `auth-token`—stop saving. Return `undefined` for shared hosting domains, or choose a domain that the deployment actually owns.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Frontend previewsLast deployed commit is 3301c253a07f8c9f4e75e244ff5ff3a217625688 Persistent
Latest commit
|
Problem
Users on iOS Safari were being logged out every time they opened the site. This didn't happen on desktop browsers.
Root Cause
The authentication and other cookies lacked an explicit
domainattribute. iOS Safari's Intelligent Tracking Prevention (ITP) is particularly aggressive with cookies that don't have proper domain configuration, which was causing cookies to be treated inconsistently or cleared.Additionally, without an explicit domain attribute, cookies are bound to the exact hostname, which can cause issues if users navigate between
modrinth.comandwww.modrinth.com(or other subdomain variations).Solution
Created a shared
getCookieDomain()utility function that:.modrinth.com(or the appropriate base domain) in productionundefinedfor localhost/IP addresses (to allow local development)Updated all cookie declarations throughout the frontend to include the
domainattribute:auth-token- Main authentication cookieauth-stored-accounts-v2- Account switching dataauth-session-created- Session creation timestampscosmetics- UI preferencescolor-mode- Theme settingsBenefits
modrinth.comandwww.modrinth.comTesting
To test this fix:
Note: Existing users may need to sign in once more after this change deploys for the new cookies to take effect.
Files Changed
apps/frontend/src/composables/cookie-domain.ts(new) - Shared domain utilityapps/frontend/src/composables/auth-cookie.ts- Updated auth cookieapps/frontend/src/composables/accounts.ts- Updated account cookiesapps/frontend/src/composables/featureFlags.ts- Updated feature flag cookiesapps/frontend/src/composables/moderation.ts- Updated moderation cookiesapps/frontend/src/composables/useCdnDownloadContext.ts- Updated CDN cookiesapps/frontend/src/plugins/cosmetics.ts- Updated cosmetics cookieapps/frontend/src/plugins/theme/theme-settings.ts- Updated theme cookie