Files
Pulse/scripts/tests
rcourtman 1b405c35d6 Refresh expired CSRF cookies on GET and cap cookie MaxAge
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
2026-11-28 14:12:31 +00:00
..