---
title: "Keep secrets out of the browser · Agent Wranglers"
url: https://agentwranglers.se/playbook/application-security/secrets-and-configuration/secrets-out-of-browser
id: APS-61
level: Required
risk: takeover
updated: 2026-10-27
build: a2a6bdfed830
tokens: 839
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Keep secrets out of the browser

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Secrets and configuration](https://agentwranglers.se/playbook/application-security/secrets-and-configuration.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: APS-61
- Level: Required
- Chapter: [Secrets and configuration](https://agentwranglers.se/playbook/application-security/secrets-and-configuration.md)
- Rule: Send no private key to the browser. Anything in a page, script or source map can be read by anyone.
- Check: The agent downloads every script and source map from the site and searches them for key patterns, such as `sb_secret_`, `sk_live_` and `sk-`. It decodes each token that starts with `eyJ` and finds none with the role `service_role`. It finds only public keys.
- Risk: An account or system taken over
- How: Call paid or private services from the server, and let the browser call your server. Only public keys belong in the browser, and only ones the provider marks as safe to publish. Build tools copy some environment variables into the bundle, such as those starting `VITE_`, `NEXT_PUBLIC_` or `REACT_APP_`. Never give a secret such a name. AI app builders sometimes put database service keys, payment secrets or AI provider keys in front-end code to make a feature work. Move each such call into a server or edge function, and rotate any key that has ever reached the browser. Don't publish source maps to production, or keep them private.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Shell example

```sh
curl -s https://staging.example.com/assets/app.js | grep -Eo '(sk_live|AKIA|ghp_|xox[bp]-)[A-Za-z0-9_-]{10,}'
```

## Sources

- [CWE-540 Inclusion of Sensitive Information in Source Code](https://cwe.mitre.org/data/definitions/540.html)

## Related rules

- MOB-20 [Ship no secrets in the app package](https://agentwranglers.se/playbook/mobile-apps/data-on-the-device/no-secrets-in-app.md) in Mobile apps
- TKO-7 [Fix in risk order](https://agentwranglers.se/playbook/codebase-takeover/triage/fix-in-risk-order.md) in Codebase takeover
- TDD-11 [Test the access rules on the running product](https://agentwranglers.se/playbook/due-diligence/security-data-and-law/test-access-rules.md) in Technical due diligence

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/application-security/secrets-and-configuration/secrets-out-of-browser">Agent Wranglers application security playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Keep secrets out of code](https://agentwranglers.se/playbook/application-security/secrets-and-configuration/secrets-out-of-code.md)
- Next: [Give each key the least power](https://agentwranglers.se/playbook/application-security/secrets-and-configuration/least-privilege-keys.md)
- [Secrets and configuration](https://agentwranglers.se/playbook/application-security/secrets-and-configuration.md)
