Strapi JWT refresh tokens and session management

Strapi offers long-lived JWTs and a refresh-token mode for end-user sessions. This page explains the trade-offs, the front-end changes, and what to verify in your Strapi version before choosing.

On this page

When Strapi JWT refresh tokens are worth the change

Your front end calls Strapi with a JWT issued by the Users and Permissions plugin, and you must decide how long that token lives and how a session ends. Refresh mode trades a more involved front end for shorter-lived access tokens and server-side control of sessions. The legacy setup issues one long-lived token, so revoking access before it expires is hard. Refresh mode gives you a short access token that the client renews through a separate refresh credential, which Strapi can list, rotate and revoke. The change is worth it when your client can hold a refresh credential safely and your security review expects sessions that end on demand.

The choice depends on the client type. A server-rendered or backend-for-frontend app can keep the refresh credential in an HTTP-only cookie that scripts cannot read, which suits most browser-based products. A single-page app or mobile client needs a more deliberate design, because the front end must handle expiry, retries and sign-out across tabs. Admin sign-in through an identity provider is a separate path covered in the admin SSO topics. Changing end-user token settings does not change how editors sign into the admin panel, and the reverse is also true.

Confirm every setting against the Strapi version you run before you commit to a design. Ask your team to check the Users and Permissions documentation for the JWT and refresh options, the exact configuration keys, the default lifetimes and the endpoints for listing and revoking sessions, since these differ between releases. Then record the decision with your security reviewers, including who can revoke a session, how long a stolen access token stays usable, and what your front end does when a refresh fails. Those answers determine whether the migration is a configuration change or a front-end rebuild.

Refresh tokens split the access token from a revocable session record

The diagram starts at sign-in, when Strapi Users and Permissions issues a short-lived access token in the response and stores a session record in the database. The refresh credential goes to the browser as an HTTP-only cookie, so front-end code cannot read it. When the access token expires, the front end calls for a new one, the browser sends the cookie, and Strapi checks the session record before issuing a new token. Logout revokes that record. Check that revocation happens on the server side, because a cleared cookie alone does not stop a stolen refresh credential from being replayed.

Access token and refresh cookie as separate artifacts, with server-side revocation.

Legacy JWT and refresh mode options and when each fits

This table compares legacy long-lived JWTs with refresh mode across token lifetime, storage, logout, session control, cookie settings and front-end effort. Read each row against your front end's hosting, your browser targets and your tolerance for a stolen token staying valid. Exact option names and defaults must be confirmed in the Users and Permissions documentation for your installed Strapi version.

Decision pointLegacy long-lived JWTRefresh mode
Token lifetimeOne token issued at login, valid until its configured expiryShort-lived access token plus a longer-lived refresh token; confirm both lifetimes in your version
Where the token is storedUsually in app memory, local storage or a client-managed cookieRefresh token can sit in an HTTP-only cookie; access token kept in app memory
LogoutClient deletes its copy, but the token stays valid until expiryLogout ends the session on the server, so the refresh token stops working
Session listing and revocationNo per-session view; revoking access broadly means changing the signing secretSessions can be listed and revoked individually; confirm the endpoints in your version
Front-end effortSmallest change: store the token and send it in the Authorization headerClient must refresh on expiry, retry after 401 responses and avoid storing the access token
Cookie settings (SameSite, Secure, domain, path)Usually not needed because the token travels in a headerSet SameSite, Secure, domain and path so the browser sends the cookie only where intended
Cross-origin deploymentsNeeds CORS for the front-end origin; credentialed requests need explicit allowanceCross-site cookies need browser-accepted SameSite and Secure values; test each target browser
Best fitInternal tools or low-risk clients where token exposure is acceptedPublic front ends with user accounts, personal data or a cross-site setup

What changes in the front end under each mode

A single-page app on its own domain calls Strapi directly from the browser, so it cannot rely on a server to hold credentials. In refresh mode, the access token should stay in memory only, while the refresh token travels in an HTTP-only cookie that the page script cannot read. After a page reload, the app asks Strapi for a new access token using that cookie rather than reading storage. The app must also coordinate concurrent requests so that only one refresh call runs at a time.

  • Token location: keep the access token in application memory, not in localStorage, and never write the refresh token into script-readable storage.
  • Refresh scheduling: start a refresh a little before the access token expires, based on the expiry time returned by Strapi, and queue requests that arrive during the refresh.
  • Failed refresh: when the refresh call is rejected, clear local state and send the user to sign in again, without retry loops.
  • CORS: allow only your front-end origin, enable credentialed requests on both sides, and set the cookie attributes so the browser sends them to the Strapi domain.
  • Cookie handling: confirm that the cookie is Secure and SameSite set for your domain layout, because cross-site cookies behave differently across browsers.

Check that a hard reload, a second tab and an expired session each land in the correct state.

How to set up refresh mode and verify it

This sequence takes a Strapi project from legacy long-lived JWTs to refresh mode with short-lived access tokens and HTTP-only refresh cookies, and ends with tested evidence that expiry, logout and revocation behave as designed.

  1. Confirm version and runtime support

    Check the Strapi version in the project's package.json against the current release line, then confirm the Node.js version is Active or Maintenance LTS and that the database is PostgreSQL 14 or later, MySQL 8.0 or later, MariaDB 10.3 or later, or SQLite 3. Strapi 5 does not support MongoDB or other NoSQL databases. Record the versions in the change ticket. The step is done when the team has a written compatibility note that the staging environment matches production. Ask your Strapi contact to confirm any version gap before you change configuration.

  2. Back up the Users and Permissions configuration

    Export the current database and copy the project's config files, including the Users and Permissions plugin settings and any custom auth controllers or policies, into version control or a protected backup location. Note the current JWT secret handling and the lifetime values in use. The step is done when a restore has been tested against a non-production copy and the team can roll back the configuration in one change. Keep a record of which front-end clients currently depend on the old token format.

  3. Enable refresh mode and set lifetimes

    In the Users and Permissions plugin configuration, turn on refresh mode and set the access token lifetime and the refresh token lifetime. Keep the access token short and the refresh lifetime bounded by your session policy, and agree these values with the security owner in writing. Store the signing secrets in environment variables, not in committed files. The step is done when a fresh login returns an access token and a refresh credential with the expected expiry, verified by decoding the token claims in staging.

  4. Configure cookie attributes and allowed origins

    Set the refresh cookie to HTTP-only and Secure, choose a SameSite value that fits how the front end and the API are hosted, and restrict the allowed front-end origins in the CORS settings to the exact domains that need credentials. Confirm the cookie path covers only the refresh endpoint. The step is done when the browser developer tools show the cookie with HTTP-only and Secure flags, and a request from an origin not on the list is refused.

  5. Update login and refresh calls in the front end

    Change the login call so the front end stores the access token only in memory and relies on the cookie for renewal. Add a refresh call that the client makes when the access token expires, and a logout call that asks the server to end the session and clears the in-memory token. Handle a failed refresh by sending the user back to sign-in. The step is done when a test user can sign in, remain signed in across an access token expiry, and sign out without the old token still working.

  6. Test expiry, refresh, logout and revocation

    In staging, run scripted scenarios: let the access token expire and confirm the client renews it, call logout and confirm the refresh credential is no longer accepted, and revoke a session from the server side and confirm the next API call is rejected. Repeat with a second browser profile to check that sessions are isolated. Record each result with the request, response and timestamp. The step is done when every scenario passes and the results are saved as evidence for the security review. Only then plan the production cutover.

Security risks to design for in token and session handling

Moving from long-lived JWTs to refresh tokens changes where secrets live, how long they stay valid and how a session ends. The cards below cover the failure modes that tend to appear in that change, with the design control for each and what to test before go-live. Confirm every default against the current Strapi documentation for your version, since token behavior is set in your own configuration.

Cross-site request forgery on refresh

The refresh endpoint is the one call that issues new access tokens, so a page on another site that triggers a request with the browser's cookies could try to obtain them. Design the refresh cookie with a restrictive SameSite setting, require a custom header or anti-CSRF token on the refresh call, and check which origins the front end actually calls from. Test a cross-origin request with the refresh cookie present and confirm it is rejected.

Strapi SSO docs

XSS exposure of stored tokens

A token kept in localStorage or sessionStorage can be read by any script that runs on the page, including injected third-party scripts. Keep the refresh token in an HTTP-only cookie that JavaScript cannot read, and keep access tokens in memory where the lifetime is short. Test by injecting a script into a page that uses the front end and confirming it cannot read the refresh credential.

Delay between revocation and expiry

A revoked session keeps working until its access token expires, unless your API checks session state on each request. Pick an access token lifetime that your security team accepts for that window, and decide whether sensitive endpoints need a server-side session check. Ask your engineers to confirm how Strapi validates tokens in your version. Test by revoking a session and calling a protected endpoint with the old access token.

Session fixation and reuse after logout

If a session identifier or refresh token survives login or logout, an attacker who obtained it can keep acting after the user has left. Issue a new refresh credential at each sign-in, invalidate the old one at logout, and avoid accepting a token that was issued before the user signed out. Test by reusing a refresh token after logout and after a second login from another browser.

Tokens leaking into logs

Reverse proxies, load balancers, APM agents and application logs can record Authorization headers, cookies or full request URLs. A leaked refresh token gives the same access as the user until it is revoked. Configure log filters to redact the Authorization and Cookie headers and any token query parameters, and confirm your retention policy covers those logs. Test by sending a login and refresh flow and searching every log sink for token strings.

Stale sessions after password change

When a user changes a password or an administrator disables an account, sessions issued earlier may remain valid. Decide how password change and account disablement end existing sessions, and whether that happens immediately or at the next refresh. Confirm the behavior with your identity provider when login is federated. Test by changing the password, then using the old refresh token and an old access token to call the API.

What buyers ask before changing Strapi session handling

How much effort does moving from legacy JWTs to refresh mode take?

The effort depends mostly on how many clients consume your Strapi API and how each one stores and renews tokens today. A single web front end with a standard login flow is a bounded change. Several apps, including mobile clients and server-to-server callers, each need their own token handling, testing and release. Custom authentication overrides in your Users & Permissions setup add review time because the token issuing logic has to be checked against the new lifetimes and refresh behavior. Ask any partner to break the estimate down by client and by override, and to state which items are one-time work and which add ongoing maintenance.

Can our own team change Strapi session handling without outside help?

Yes, if your team has engineers who know the Strapi authentication layer, your front-end frameworks and your reverse proxy configuration. The work spans server settings, cookie handling in every client and a rollout plan, so it touches more than one team. Teams that have not built HTTP-only cookie flows before often find the cross-origin and cookie scope details take the longest. Outside help makes most sense when the team lacks that experience, needs an independent test plan, or cannot free engineers for the change window. DeployOpen plans, implements and tests this work in your infrastructure under a written scope.

What does our side need to provide for a session migration?

You need a staging environment that matches production closely enough to test cookies, domains and proxy behavior, plus a named owner for each client application. A test plan should cover sign-in, silent refresh, expiry, logout, revocation and behavior when a refresh fails. Your team also needs to confirm the Strapi version and Node.js version in use, because those set which features and settings are available. Access to your identity provider and to your deployment pipeline is required so changes can be tested end to end before release.

Does refresh mode require a paid Strapi plan?

Confirm this on the pricing page before you decide, because the supplied pricing information does not say which session features sit in which plan. The self-hosted plans list SSO as an add-on for Growth and included in Enterprise, and audit logs as an Enterprise feature. Those items are about admin sign-in and logging, not end-user token lifetimes, so they should not be assumed to answer your question. Check the Strapi self-hosted pricing page and ask Strapi directly whether refresh mode for end-user sessions is available on your planned plan. Get the answer in writing before finalizing the design.

How do support teams use session listing and revocation?

Support teams use session listing to see which devices or browsers hold an active session for a user, and revocation to end those sessions after a lost device, a role change or a suspected compromise. Revocation only works if the server checks session state on refresh, so the design must decide how quickly a revoked session stops working. Support staff also need a documented procedure and access controls, so that only authorized people can revoke sessions and every action is recorded. Agree on these procedures with your security and support leads before build starts.

What happens to existing users during the rollout?

Existing users with long-lived legacy tokens will need to sign in again or receive a new session when the change goes live, unless the rollout keeps both modes running for a period. Plan the cutover window with support in mind, and tell users what to expect before it happens. Decide whether old tokens are rejected immediately or allowed to expire, because that choice affects both user experience and security exposure. Test the cutover in staging with real account states, including users who are mid-session, so the expected behavior is confirmed before production.

Which questions should we ask a partner before signing a scope?

Ask which clients and overrides are in scope, how the test plan covers refresh failures and revocation, and who owns each client after release. Ask what is delivered as documentation, what the rollback plan looks like, and whether the work includes a staging rehearsal. Ask how the work is priced and what recurs after launch, such as client updates or retesting after Strapi upgrades. A written scope should name these items so you can compare proposals on the same basis.

Operating sessions and revocation after launch

After go-live, the operations team owns session state, and the first decision is who can end a session and how quickly. Confirm which session views and revocation actions your Strapi version exposes in the admin panel for end-user accounts, and which ones need a call from your own tooling against the API. Then write a revocation runbook before launch. It should name who receives a report of a compromised account, who disables the user in the Users & Permissions plugin, how outstanding refresh sessions are invalidated, and how long an access token that was already issued stays usable under the lifetime you chose. Test each step in staging with a real end-user account so the runbook reflects what your version actually does.

When an account is compromised, the order of actions matters. Block sign-in first, revoke the account's sessions, rotate any secret the attacker could have reached, and only then review what the account read or changed. For monitoring, log token issuance, refresh and expiry events with the user ID, timestamp, outcome and client, but never the token values or the refresh cookie. Confirm whether your reverse proxy and application logs capture Authorization headers or cookies by default, and configure redaction if they do. Set an alert on unusual bursts of refresh failures, since they often show a stolen or replayed credential being tested.

Strapi 5 minor releases ship often, and authentication behavior can change in any of them. The Strapi GitHub releases page lists each one, so add a review step to every upgrade. Read the release notes for changes to JWT handling, refresh behavior, sessions or the Users & Permissions plugin, then repeat sign-in, token refresh, logout and revocation tests in staging before production. Record the chosen token lifetimes and refresh setting in your upgrade checklist as a named item with an owner, so a later version cannot change them without someone noticing.

Limits to confirm in your Strapi version and environment

Refresh-token behavior in Strapi depends on the exact release, how the Users and Permissions layer has been customized, and how traffic reaches the API. The cards below list the points to confirm in your own environment before you commit to a token design, because each one can change the front-end work and the operations plan.

Refresh-token options per release

Confirm which refresh-token settings exist in the Strapi 5 release you will install, and what each one does by default. Lifetimes for access and refresh tokens, rotation behavior and cookie options are the first things to check against the release you run, not against older examples. Pin the version in your build and record the settings in your configuration baseline so a minor upgrade does not silently change session length. Because Strapi 5 minor releases ship frequently, treat the release notes as part of this review.

Strapi releases

Session listing and revocation surface

Find out whether session listing and revocation are available in the admin panel or only through the API. If the admin panel does not expose them, editors and security staff will need a documented API procedure, and someone must own it. Confirm who can list sessions, who can revoke them, and whether revocation takes effect immediately for access tokens already issued or only at the next refresh. Write the answer down before design starts, because it sets the incident response steps for a stolen token.

Custom Users and Permissions controllers

Check whether any custom controller, route or policy in your project replaces the default Users and Permissions behavior for login, refresh or logout. A custom override can bypass token issuance, cookie setting or session tracking without any visible error. Review every file under your Users and Permissions extensions and compare each auth route with the default implementation for your version. Add an automated test that calls login, refresh and logout and checks the response headers, because a bypass is easy to miss in code review.

Cross-domain cookie limits

If the front end and the Strapi API run on different domains, confirm how browsers will send the HTTP-only refresh cookie. Cookie scope, the SameSite attribute, the Secure flag and the allowed origins all decide whether the refresh call succeeds. Test the exact front-end and API hostnames you plan to use, including preview and staging domains. Some sites may need a shared parent domain or a same-site proxy, and that choice changes DNS, certificate and CORS work, so decide it early.

Load balancer and proxy cookie handling

Confirm how your load balancer, ingress and reverse proxy treat the refresh cookie and the Set-Cookie header. Some proxies strip or rewrite cookies, drop headers on redirects, or terminate TLS in a way that changes whether the Secure flag and client IP are seen correctly. Check that the forwarded protocol and host headers reach Strapi as expected, and that session and rate-limit logic uses the real client address. Run the full login, refresh and logout path through the production edge before go-live.

Node.js and database support for the release

Confirm the Node.js and database versions that your chosen Strapi 5 release supports, and the versions your platform team will run. Strapi 5 runs on Active or Maintenance LTS Node.js versions and supports PostgreSQL 14 or later, MySQL 8.0 or later, MariaDB 10.3 or later and SQLite 3, without MongoDB. Session and refresh records depend on the database, so test them on the exact engine and version you will operate, and plan for the Node.js upgrade cycle that comes with it.

Latest release checked
v5.58.0
Strapi installation requirements

How DeployOpen works on this

DeployOpen plans and implements Strapi JWT refresh tokens and session management inside your own infrastructure, so token lifetimes, cookie behavior and revocation are designed with your security and compliance teams. The work is scoped in writing first, then built, tested and handed over with documentation your engineers can run.

How we scope

  • Written scope covers which Strapi auth mode, token lifetimes and cookie settings are in and out of the work
  • Inventory of front-end clients, mobile apps and integrations that call the Strapi API and need token changes
  • Agreed deliverables and timelines are fixed in writing before any build work starts, with ongoing support available as a retainer

How we build

  • Configure refresh mode, access and refresh token lifetimes and HTTP-only refresh cookies in your Strapi environment
  • Change front-end token storage, refresh calls and sign-out flows, then test expiry and revocation paths end to end
  • Review session listing and revocation behavior against your access model and logging requirements before go-live

How we hand over

  • Written configuration record covering token settings, cookie attributes, CORS dependencies and the reasoning behind each choice
  • Runbook for rotating secrets, revoking sessions and responding to a suspected token compromise
  • Walkthrough with your engineers so they can operate and change the session setup without outside help

How we support

  • Retest of session behavior after Strapi minor upgrades, since release cadence is frequent and auth behavior can shift
  • Support for front-end changes when the client framework, hosting or identity provider changes
  • Optional retainer for continuing reviews, upgrades and periodic testing of the session setup

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.