Join our Newsletter — 33% off our NHI Course
Home› FAQ› Authentication, Authorisation & Trust› How should SaaS teams implement token-based authentication without…
Authentication, Authorisation & Trust

How should SaaS teams implement token-based authentication without exposing sensitive data to the browser?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 31, 2026 Domain: Authentication, Authorisation & Trust

Use short-lived access tokens for API calls, keep the authorization code flow for server-side apps, and avoid sending ID tokens or refresh tokens to places that do not need them. Minimise claims in the token payload, store only what is necessary, and rely on server-side session handling where possible. That reduces exposure while preserving user experience and control over delegated access.

Keep browser-exposed tokens as small and short-lived as possible

The browser should only see the minimum token material needed for the current user action. In practice, that means short-lived access tokens for API calls, no refresh tokens in browser storage, and no ID token unless the client truly needs identity claims for UI behaviour. The safest pattern is to keep durable session state and higher-privilege exchanges on the server side.

This is less about token format and more about blast radius. If a browser token is stolen through XSS, malicious extensions, or leaked client-side storage, the damage should be limited to a narrow audience, a short lifetime, and a small set of scopes. The more claims and long-lived credentials you place in the browser, the more useful that theft becomes.

For teams formalising browser-based OAuth patterns, the OAuth for Browser-Based Applications and the BFF Pattern Guide is the natural implementation companion because it explains why token-mediating backends reduce exposure in SPAs and browser clients.

Use the right OAuth flow for the app architecture

Server-side web apps should keep the authorization code flow on the backend, where secrets, refresh tokens, and session cookies can be handled away from the browser. Browser-based apps can still use OAuth safely, but they need stronger boundaries around storage, token refresh, and token audience. The wrong choice is usually not the token itself, but where the trust boundary is placed.

That distinction matters because browser code is a hostile execution environment from a security perspective. Any token that a browser can read is exposed to JavaScript, browser plugins, debug tooling, and accidental logging paths. A backend-for-frontend or token-mediating layer lets you preserve user experience while keeping higher-value credentials off the client.

The practical design target is to keep the browser as a presentation layer, not a token vault. If you need long-lived access, delegated refresh, or broader downstream reach, move that responsibility behind a server-side component and let the browser interact with a narrow session abstraction instead of raw bearer credentials.

Where you need a standards reference for browser-based OAuth design, NIST SP 800-63 Digital Identity Guidelines is useful for assurance thinking around authenticators, session handling, and reducing unnecessary exposure of sensitive credentials to the client.

Minimise claims, audience, and downstream token value

A token should carry only the claims and scopes required for the next API call. Extra profile data, embedded entitlements, or broad audience scopes increase privacy exposure and make stolen tokens more useful. Keep the token narrow, and move any rich user or policy data into server-side lookup or introspection where possible.

That also means separating identification from authorisation. Teams often put user profile data into the browser because it is convenient for rendering, but convenience is not a safe reason to duplicate sensitive data into a place that is harder to control. If a claim does not need to be in the browser, it should stay out of the browser.

When the token must cross service boundaries, constrain where it can be used and how long it remains valid. Audience restriction, short lifetimes, and sender-constrained designs all reduce the value of intercepted tokens because they make reuse harder and limit the number of systems that trust the token.

For a control-oriented mapping, the RFC 8707: Resource Indicators for OAuth 2.0 and RFC 9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) both support the same core objective: make tokens harder to replay and less broadly reusable if they are exposed.

Risk and Threat Considerations

Browser exposure turns token theft into a realistic compromise path, especially when tokens are long-lived, broadly scoped, or reusable across multiple services. The main threat is not just account access, but downstream misuse of the same token to pivot into APIs, export data, or impersonate the user in ways the browser user never intended.

Failure mechanism: Sensitive material is placed in client-side storage or returned to the browser when it is not needed there, then exfiltrated through XSS, injected scripts, browser extensions, or accidental disclosure in logs and telemetry. Once stolen, a bearer token often works exactly as designed, which is why exposure is so dangerous.

Impact: The attacker can act with the user's delegated authority until the token expires or is revoked, and in some architectures can also infer identity or access patterns from embedded claims. That can create data exposure, session hijacking, and a wider incident response burden than the original feature warranted.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST SP 800-63 and OWASP ASVS set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.

FrameworkControl / ReferenceRelevance
NIST SP 800-63Digital Identity GuidelinesBrowser token handling directly affects authenticator exposure and session assurance.
Recommendation — Apply the digital identity guidance to keep high-value credentials off the client and limit browser-exposed session risk.
OWASP ASVSV10 — OAuth and OIDCOAuth/OIDC browser flows require careful handling of tokens, claims, and session boundaries.
Recommendation — Verify browser OAuth/OIDC flows keep sensitive tokens out of client storage and limit exposed claims.
ISO/IEC 27001:2022A.8.5 — Secure authenticationToken handling is an authentication control issue when credentials reach the browser.
Recommendation — Define authentication handling so browsers never receive credentials beyond what the session truly needs.

Practitioner Guidance

What to verify: Check whether the browser ever receives refresh tokens, ID tokens, or claims that are only needed for server-side decisions. If it does, treat that as an architecture issue, not a minor implementation detail.

Decision rule: If a value can be verified or exchanged on the server, do not send it to the browser just because the front end would find it convenient. Use the browser only for the minimum session context needed to render and call the next API.

Common mistake: Treating “token-based” as synonymous with “client-visible.” The safer pattern is usually token-based authentication with server-side mediation, narrow scopes, and short-lived credentials, not raw token storage in local browser state.

Practitioner takeaway: The security goal is not to eliminate tokens from the browser entirely, but to ensure the browser only handles tokens whose loss would be tolerable, bounded, and quickly recoverable.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 31, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org