## Summary
Fixes `CSRF token validation failed` errors on non-replayed (`retry:
false`) mutations (such as clicking **Generate command** in the remote
commands dialog) after a browser session has been open for more than 4
hours.
### Root Cause
- `CSRFTokenStore` expires server-side tokens after 4 hours, while
`pulse_csrf` cookies were issued with a 24-hour (or 30-day Remember Me)
`MaxAge`.
- `GET /api/*` middleware only issued a `pulse_csrf` cookie when the
cookie was missing, never when an existing cookie was expired or
invalid.
- Because the stale cookie remained in `document.cookie`, `apiClient`
never called `ensureCSRFToken()`, and `retry: false` mutations surfaced
the 403 directly on the first attempt.
### Changes
- Added `csrfTokenTTL` (4h), `csrfCookieMaxAgeSeconds` (3h55m), and
`csrfCookieMaxAge(sessionDuration)` so every `pulse_csrf` cookie expires
slightly before the server-side token (or matches shorter session
durations).
- Updated `GET /api/*` middleware in `internal/api/router.go` to refresh
missing, empty, invalid, or expired `pulse_csrf` cookies for live
sessions, and to proactively rotate valid cookies with less than 30
minutes remaining (coalesced across a 30-second window via
`HasRecentToken` so concurrent page-load GETs mint at most one
replacement token).
- Added unit and middleware regression tests in `csrf_store_test.go`,
`security_test.go`, and `router_csrf_middleware_test.go`.
### Verification
- `go test -v -count=1 ./internal/api -run
'TestCSRF|TestCSRFCookie|TestIssueNewCSRFCookie|TestClearCSRFCookie|TestRouter.*CSRF|TestCheckCSRF'`
- `go test -race -count=1 ./internal/api -run
'TestCSRFTokenStore|TestRouter.*CSRF|TestIssueNewCSRFCookie|TestCSRFCookieMaxAge'`
- `go test -count=1 ./internal/api -run
'Test.*Login|Test.*SAML|Test.*MagicLink|Test.*CloudHandoff|Test.*BasicAuth|Test.*SecuritySetup'`
- `go vet ./internal/api/...`
Server-side CSRF tokens expire after 4 hours in CSRFTokenStore, while pulse_csrf browser cookies were issued with a 24-hour or 30-day MaxAge. On GET /api/*, the router only issued a cookie when pulse_csrf was missing and never checked whether an existing cookie had expired or become invalid.
Once a session passed the 4-hour mark, browsers kept sending the expired pulse_csrf cookie across page loads and GET requests without triggering apiClient's ensureCSRFToken fallback. Non-replayed mutations (retry: false), such as generating a host agent install command, then failed on the first click with 403 CSRF token validation failed.
Fix both halves of the lifecycle:
- Bound pulse_csrf cookie MaxAge across all session and CSRF issuance sites to 3h55m (5 minutes below the 4-hour server TTL, or the session duration when shorter) so idle tabs drop stale cookies before server expiry.
- Refresh missing, empty, or invalid/expired pulse_csrf cookies on GET /api/* for live sessions, and proactively rotate still-valid cookies within 30 minutes of expiry (coalesced over a 30-second window so parallel page-load GETs mint at most one replacement token).
Contract-Neutral: Bug fix aligning pulse_csrf cookie MaxAge with the 4-hour server CSRF token TTL and refreshing expired or near-expiry CSRF cookies on GET /api/* for live sessions, keeping all CSRF admission, 8-token bound, hash-only storage, and retry: false contracts unchanged
Document landed SSO and RBAC access-boundary behaviours from #5034
(36ff8eaa81) and #5079 (9f71173b7a) across docs/OIDC.md, docs/RBAC.md,
and their shipped mirrors in frontend-modern/public/docs/, with
source-bound regression tests in scripts/tests/test_oidc_session_docs.py:
- docs/OIDC.md (+ mirror): document required exact `openid` scope
validation on enabled OIDC provider writes, partial missing-role
replacement and fail-closed `session_failed` / `invalid_state`
callback handling, automatic withdrawal of mapping-origin roles when
Group Role Mappings are cleared (while preserving manually assigned
roles), issuer-bound SSO principals when a provider is repointed, and
exclusion of unverified OIDC emails from legacy assignment migration.
- docs/RBAC.md (+ mirror): document issuer-bound SSO principals when
repointing an existing provider, partial missing-role replacement and
`session_failed` refusal, and withdrawal of mapping-origin roles when
group mappings are cleared.
- scripts/tests/test_oidc_session_docs.py: bind each documented
behaviour directly to internal/api/identity_sso_handlers.go,
internal/api/auth_principal_identity.go,
internal/api/oidc_handlers.go, and internal/api/saml_handlers.go, and
verify the RBAC.md shipped mirror matches docs/RBAC.md.
Contract-Neutral: Documentation, mirrored in-app Help, and Python doc-regression test alignment for already-landed runtime behaviour with no runtime, API, schema, or subsystem contract changes.
Change-source: pulse-maintainer
Update docs/FAQ.md, docs/OIDC.md, and their shipped
frontend-modern/public/docs/ mirrors so administrators get accurate
guidance matching current Settings and Proxmox Ceph behaviour:
- SAML setup in FAQ.md now shows that SP Metadata and ACS URL can be
copied inside Edit while sign-in is disabled, documents metadata-first
Test precedence and certificate warnings (No signing cert read,
Expired cert found), and notes that editing a saved SAML provider
preserves an unset email attribute.
- OIDC.md now explains double-quoting exact directory group names
containing commas or = in Allowed Groups and Group Role Mappings,
local rejection of duplicate groups or incomplete pairs, intentional
blank clears, and inline retry via Edit when settings fail to open.
- Ceph FAQ now explains that clusters without a recognised health
verdict show Unknown in the table and drawer and stay out of Healthy.
Bind all added guidance to live frontend source in
scripts/tests/test_faq_deployment_docs.py and
scripts/tests/test_oidc_session_docs.py.
Contract-Neutral: Documentation and Python doc-consistency test alignment with already-landed SSO and Proxmox Ceph UI behaviour; no runtime, API, payload, route, or access contract changes.
Change-source: pulse-maintainer
Point administrators to Edit for disabled providers and let them copy
the exact saved SP Metadata and ACS addresses there. Report missing
addresses without falling back to stale inventory. Keep Test, Preview,
manual setup guidance and the editor footer in view on a phone.
Keep the card component unchanged and assert the OIDC setup guidance
in the OIDC form instead of relying on unrelated SAML copy.
Contract-Neutral: Repairs registration guidance and reuses the shared copy control with the existing selected-provider detail fields; card copy visibility, access rules, API, payloads and provider lifecycle are unchanged.
Change-source: pulse-maintainer
Check the issuer-match wording on the returned message or its default prefix, with the credential and sign-in limitation on the common return. Keep the issuer rejection checks and add a negative control for losing the complete-discovery qualifier.
Change-source: pulse-maintainer
Keep the empty-groups distinction next to Allowed Groups. Require the independent administrator login after SSO works instead of requiring the old removal suggestion. Retain the existing checks for each callback gate and exercise both misleading alternatives.
Contract-Neutral: Preserves existing sign-in restrictions and role grants in the guide and tests; no runtime, API or access changes.
Change-source: pulse-maintainer
Keep the existing warning and write interlocks while replacing only the pending inventory GET. Let the latest same-reader check settle acknowledged writes, reject displaced read results, and keep keyboard focus in the inventory without overriding deliberate focus changes.
Contract-Neutral: Recovery of an existing authorized inventory read; no change to the SSO API, permission decisions, saved-provider shape, write sequencing, or shared frontend primitives.
Change-source: pulse-maintainer
Bind the guide consistency check to the visible Check saved providers control and follow its named read callback instead of requiring the old inline spelling. Preserve inventory and detail no-write checks, and reject mutation delegates, direct API writes and duplicate reads with five negative controls. Runtime and existing browser proof are unchanged.
Contract-Neutral: Repair source-consistency verification for an existing read-only recovery control; no runtime, documentation, API or authority contract change.
Change-source: pulse-maintainer
Correct the field-lock and global-override claims, explain the managed-provider rejection and persisted legacy precedence, and document the actual legacy callback default. Keep provider identity, recovery and existing-session boundaries intact.
Contract-Neutral: Documentation and source-consistency tests only. No OIDC runtime, permissions, API or deployment contract changes.
Change-source: pulse-maintainer
Put the callback's existing intersection of email, domain and group restrictions at the setup point. Correct the claim that an empty group list admits every identity while preserving administrator mapping and recovery guidance. Bind the help to the independent callback denials and protect it against misleading bypass descriptions.
Contract-Neutral: Documentation and source-consistency coverage only. No authentication, access policy, API or session behaviour changes.
Change-source: pulse-maintainer
Read the current provider list without repeating an uncertain mutation. Preserve administrator access and stop on unexpected absence rather than recreate saved providers. A list or masked field cannot establish secret retention, working sign-in or revocation.
Contract-Neutral: Existing OIDC help and source-consistency checks only. No runtime, endpoint, permission or lifecycle contract changes.
Change-source: pulse-maintainer
Match the existing OIDC callback and RBAC guide: only successful non-empty assignments emit the assignment event, not cleared roles. Add source-consistency controls to the existing documentation suite.
Contract-Neutral: Correct documentation and drift checks only. Preserve all OIDC, role-assignment, audit, session and access-control behaviour.
Change-source: pulse-maintainer
Compose the retained stale-refresh repair with landed session-store persistence isolation. Release the authentication mutex before the synchronous save, adapt source checks and fixtures, and prove registered reads plus a newer logout while real refresh persistence is paused.
Contract-Neutral: Preserve documented session lifetimes, current-session refresh and invalidation policy, provider selection, grants, response fields and encrypted persistence formats; obsolete work cannot act on a replacement or expired session, and persistence remains outside the authentication mutex.
Change-source: pulse-maintainer
Repair the preflight source-consistency check after refresh ownership moved into SessionStore. Keep session lifetime, provider-skip, invalidation, rotation and persistence assertions, and check that seven broken ownership/persistence variants are still rejected. Runtime and user-facing documentation remain unchanged.
Contract-Neutral: Test-only source consistency repair; no runtime behavior, documented policy, routes, grants, persisted formats or frontend content changes.
Change-source: pulse-maintainer
Replace the stale success-copy literal with checks for missing and unequal issuer rejection and qualified discovery-only success. Keep every existing setup/session/access assertion, and use in-memory mutations to prove the consistency check rejects false-green regressions without changing runtime source.
Contract-Neutral: Documentation/source consistency tests only. The completed OIDC runtime, API contract, guides and browser-verified consumer remain unchanged.
Change-source: pulse-maintainer
SSO operators can hold permitted non-administrative write capabilities. The guide now checks the actual instance-administration boundary, without instructing a settings mutation or changing roles.
Change-source: pulse-maintainer
Copy generated callbacks only after provider save, align group-claim advice with provider-specific scopes, and retain administrator access until separate-session permission checks pass. Keep shipped documentation and regression checks in step without changing authentication or provider behaviour.
Change-source: pulse-maintainer
Separate browser-cookie lifetime, sliding server sessions and request-driven token refresh. Remove the false provider-change revocation promise, preserve administrator access and document the existing targeted user-removal boundary and private diagnosis.
Contract-Neutral: Documentation and source-consistency tests only; no authentication, session, authorisation or deployment contract changes.
Change-source: pulse-maintainer