Skip to content

[codex] Handle stale auth cookies on public requests#8216

Merged
sneridagh merged 5 commits into
sevenfrom
codex-stale-auth-cookie-fallback
May 15, 2026
Merged

[codex] Handle stale auth cookies on public requests#8216
sneridagh merged 5 commits into
sevenfrom
codex-stale-auth-cookie-fallback

Conversation

@sneridagh
Copy link
Copy Markdown
Member

Summary

This PR fixes Seven's behavior when the auth_seven cookie contains a stale or invalid token and the user requests public content.

Previously, Seven initialized the Plone client with whatever token was present in the cookie and sent it as Authorization: Bearer <token> on content and asset requests. When that token was no longer valid, the backend returned 401, and Seven surfaced that failure through the root ErrorBoundary even for public pages.

This change makes Seven recover gracefully instead of failing hard.

What changed

  • Added anonymous fallback behavior in apps/seven/app/middleware.server.ts.
  • When a token-authenticated content or site request returns 401, Seven now reinitializes the client without the token, retries the request anonymously, and continues rendering if anonymous access succeeds.
  • When a stale cookie is detected and anonymous fallback succeeds, Seven now clears the auth_seven cookie on the final page response.
  • Added the same stale-cookie recovery for proxied asset requests (@@images, @@download, @@site-logo, @portrait) so public assets still resolve when the cookie is invalid.
  • Avoided sending Authorization: Bearer undefined on anonymous proxied asset requests.
  • Decoupled getUser() lookup from the main content/site fetch so user lookup failures do not break otherwise public rendering.
  • Centralized cookie-clearing helpers in @plone/react-router with shared helpers for clearing the auth cookie on a response or generating the clearing Set-Cookie header.
  • Added regression tests for the anonymous retry flow, cookie clearing behavior, and the updated loader response shape.
  • Added towncrier news entries for apps/seven and packages/react-router.

Impact

  • Public pages keep rendering even when the user's auth cookie has expired or become invalid.
  • The stale auth cookie is removed automatically once Seven confirms anonymous access works.
  • Shared auth-cookie cleanup behavior is available centrally from @plone/react-router.

Validation

  • pnpm exec vitest run app/root.test.tsx app/middleware.server.test.ts
  • pnpm --filter seven typecheck
  • pnpm --filter @plone/react-router build

@sneridagh sneridagh requested a review from pnicolli May 14, 2026 18:37
@sneridagh sneridagh marked this pull request as ready for review May 14, 2026 18:37
Comment thread packages/react-router/src/index.ts Outdated
Comment thread packages/react-router/src/index.ts Outdated
Comment thread apps/seven/app/middleware.server.ts Outdated
Comment thread apps/seven/app/middleware.server.ts Outdated
@sneridagh sneridagh merged commit e4ddd59 into seven May 15, 2026
31 checks passed
@sneridagh sneridagh deleted the codex-stale-auth-cookie-fallback branch May 15, 2026 14:39
sneridagh added a commit that referenced this pull request May 17, 2026
* seven: (43 commits)
  [codex] Handle stale auth cookies on public requests (#8216)
  Release Seven 1.0.0-alpha.4
  Release @plone/layout 1.0.0-alpha.8
  Release @plone/blocks 1.0.0-alpha.10
  Release @plone/plate 1.0.0-alpha.8
  Release @plone/helpers 2.0.0-alpha.6
  Make the import for the styleFields helper resilient and Volto-compatible (#8206)
  [Seven] Make style fields first-class and preserve block width fallback (#8204)
  Release @plone/plate 1.0.0-alpha.7
  Fixed toolbar button if a single option is shown (#8186)
  Release @plone/layout 1.0.0-alpha.7
  Release @plone/blocks 1.0.0-alpha.9
  Release @plone/plate 1.0.0-alpha.6
  Release @plone/helpers 2.0.0-alpha.5
  Release @plone/types 3.0.0-alpha.1
  [Seven] Style fields (#8175)
  Release @plone/plate 1.0.0-alpha.5
  Fixed import from repo in @plone/plate (#8183)
  Improved prereleaser script
  Release Seven 1.0.0-alpha.3
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants