Because they can contain enough identity material to bootstrap a new secret. Once JavaScript can read tokens or session state, it can often turn that access into API key creation, which gives attackers or rogue tools a persistent credential that survives the original session.
Why This Matters for Security Teams
Browser-readable cookies and local storage turn a front-end convenience into an identity problem. If JavaScript can read session state, refresh tokens, or bootstrap material, then any cross-site scripting flaw, malicious browser extension, or compromised third-party script can pivot from user context into NHI creation or API access. That is why this issue sits squarely in the same risk category as secret exposure, not just web hygiene.
The practical failure is that teams often secure the backend while leaving browser-accessible identity artifacts in place. Current guidance from NIST Cybersecurity Framework 2.0 still points teams toward protecting credentials at rest and in transit, but browser storage adds a third trust boundary: the runtime itself. NHIMG research on Ultimate Guide to NHIs shows how quickly exposed secrets become durable compromise, especially when they are not rotated or revoked quickly. In practice, many security teams discover this only after a token has already been exchanged for a persistent API key, rather than through intentional design review.
How It Works in Practice
The risk emerges when the browser can access anything that functions like a secret. Cookies marked without proper protections, tokens stored in local storage, and session metadata in JavaScript-readable state can all be harvested by code running in the page context. If the application or agent then uses that material to call identity or admin APIs, the browser becomes an identity broker instead of a presentation layer.
That is especially dangerous in agentic workflows. A user-facing assistant, embedded copilot, or multi-step automation flow may be authorized to complete a task, but not to retain credentials afterward. Best practice is evolving toward short-lived, task-scoped identity with runtime checks, not reusable browser-held secrets. For agentic systems, OWASP guidance for LLM and agentic risks and SPIFFE workload identity both reflect the same pattern: prove what the workload is, then issue narrow, ephemeral access only for the current action.
- Keep long-lived credentials out of browser-readable storage.
- Use httpOnly, secure, same-site cookies where browser session state is unavoidable.
- Exchange front-end session proof for short-lived backend tokens instead of storing reusable secrets in JavaScript.
- Use policy-as-code at request time so identity decisions reflect context, not just static role membership.
- Revoke or expire credentials immediately after the task completes.
NHIMG’s Top 10 NHI Issues research also shows why this matters operationally: once a secret is exposed in a reachable location, downstream abuse is usually faster than review and rotation. These controls tend to break down in single-page applications and embedded agent UIs because client-side code, third-party scripts, and token exchange flows all share the same runtime trust boundary.
Common Variations and Edge Cases
Tighter browser-side controls often increase engineering overhead, requiring organisations to balance usability against containment. Not every cookie is unsafe, and not every local storage use is a breach condition, but the current consensus is clear that anything readable by JavaScript should be treated as recoverable by an attacker with script execution.
The edge cases appear in federated login, micro-frontend architectures, and agent dashboards that chain multiple tools. In those environments, teams sometimes keep a browser-visible token because it simplifies refresh, cross-tab session continuity, or extension integration. That tradeoff is real, but it should be explicit: if the browser can read it, then XSS, malicious extensions, supply-chain script compromise, and prompt-injection-assisted actions all become identity threats. NHIMG’s 52 NHI Breaches Analysis shows that exposure often becomes persistence after the first foothold, not before it.
For autonomous agents, the safer pattern is context-aware authorization, ephemeral credentials, and workload identity verification at runtime. There is no universal standard for this yet, but the direction of travel across NIST Cybersecurity Framework 2.0 and emerging agent guidance is consistent: browser-readable identity material should be minimized, time-bounded, and treated as already exposed if the page can execute arbitrary script.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10, OWASP Agentic AI Top 10 and CSA MAESTRO address the attack and risk surface, while NIST AI RMF and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-01 | Browser-readable secrets are exposed identity material that should not be stored client-side. |
| OWASP Agentic AI Top 10 | A1 | Agentic apps should not rely on static browser-held credentials for runtime actions. |
| CSA MAESTRO | GI-2 | MAESTRO addresses secure agent identity and constrained tool access in dynamic workflows. |
| NIST AI RMF | AI RMF governance applies to runtime identity risks in autonomous and semi-autonomous systems. | |
| NIST CSF 2.0 | PR.AC-1 | Identity and access control must prevent unnecessary exposure of browser-readable credentials. |
Move secrets out of browser storage and treat any client-readable token as recoverable by attackers.