Skip to content
All work

Security audit · A client application review

Client-side credential exposure across identity platforms

Client-side credential exposure is rarely a single bad line of code. It is a missing projection boundary between the API and the client store, reproduced across Firebase, Cognito, Entra, Auth0 and Supabase clients. This case study describes the class and the review method; the specific client finding stays private.

insufficiently protected credentials
CWE-522
insufficiently protected credentials
OWASP broken object property level authz
API3:2023
OWASP broken object property level authz
identity platforms covered by the comparison
6
identity platforms covered by the comparison

01

The pattern

The recurring pattern is an API returning a full record, a client store hydrating it, and persistence middleware serialising the whole store. The sensitive fields were never intentionally placed in storage; they arrived because no layer asked which fields the client actually needed.

02

Where it surfaces

  • localStorage and sessionStorage, readable by any script in the origin.
  • IndexedDB and Cache Storage, which hold larger objects and survive longer than a tab.
  • Mobile stores: SharedPreferences, UserDefaults and WebView localStorage.
  • Debug logs, crash reports and device backups that copy the same values off-browser.
  • Server-rendered hydration payloads that embed the full record for the client to pick up.

03

Why this is a class of bug, not a one-off

Any stack that combines an ORM returning full models, an API without response shaping, and a persisted client store has the same exposure latent in it. The same shape appears in Redux Persist, Zustand persist, Pinia, NgRx, React Query persist and hand-rolled localStorage caches. It also appears in mobile apps that mirror API responses into SharedPreferences, UserDefaults or a WebView store. The state library is not at fault. The absence of a projection boundary is.

04

Storage is the symptom; trust boundaries are the bug

  • localStorage and sessionStorage are readable by any script in the origin. An XSS is a full credential compromise, not a defacement.
  • IndexedDB and Cache Storage hold larger objects and survive far longer than a tab; a service worker can cache responses containing secrets.
  • Client-side encryption does not fix this when the key ships to the client. It changes the encoding, not the trust boundary.
  • Mobile backups, debug logs, crash reports and WebView storage extend the same exposure off-browser.
  • The only durable rule: if the client never receives the secret, no client-side store can leak it.

05

The same exposure across identity platforms

  • Firebase: ID and refresh tokens persist by default; custom claims are authorization data and must be set server-side; App Check attests the app, not the user; API keys are public identifiers whose safety depends entirely on rules.
  • AWS Cognito and Amplify: the default token cache is browser storage; identity pools can mint AWS credentials for unauthenticated users; unauthenticated roles must be scoped to almost nothing; server-rendered apps should prefer cookie storage or a backend-for-frontend.
  • Microsoft Entra ID and MSAL: cacheLocation decides whether tokens live in memory, sessionStorage or localStorage; refresh tokens and scopes need explicit review; conditional access does not compensate for a token that XSS can read.
  • Auth0 and generic OIDC: SPA SDKs store tokens in the browser unless you adopt the BFF pattern; PKCE protects the code exchange, not the token after issuance; refresh-token rotation limits the blast radius but does not remove it.
  • Supabase: the anon key is designed to be public; Row Level Security is the actual boundary; the service_role key must never ship to a client; JWT expiry and refresh policy decide how long a leaked token survives.
  • Custom JWT: localStorage is XSS-readable; httpOnly Secure SameSite cookies are not script-readable but need CSRF care; in-memory access tokens with a refresh cookie are a reasonable middle ground.
  • Mobile: Keychain and Keystore are the right home for refresh tokens; SharedPreferences, UserDefaults, WebView localStorage, logs and device backups are where they usually end up instead.

06

Response shaping and serverless backends

  • Serverless removes the application server but not the need for a serialization boundary. API Gateway mappings, Lambda handlers, Cloud Functions callables, Azure Functions and Supabase RPC all return whatever you let them return.
  • Return a DTO with an allowlist, not an ORM model. Field-level authorization belongs next to the query, not in the component that happens to render it.
  • GraphQL needs field-level checks and query-cost limits; a single resolver returning a full user object defeats the schema's apparent safety.
  • Tenant isolation belongs in the data layer: Firestore rules, DynamoDB leading keys and condition expressions, Cosmos DB partition keys plus RBAC, Postgres RLS, or D1 queries scoped by tenant.
  • Never return secrets, internal identifiers, password hashes or provider credentials, even to an authenticated administrator. Admin is a role, not a licence to leak.

07

Third-party credentials are the worst offenders

  • Mobile money, SMS, email, maps and payment integrations usually ship a key to the client because it is the fastest path to a demo. The same key then sits in a bundle anyone can download.
  • Separate publishable keys from secret keys. A publishable key identifies a project; a secret key authorises spending, messaging or data access.
  • Proxy privileged third-party calls through a backend or serverless function, with per-user rate limits, scoped tokens and rotation.
  • Rotate anything that has ever been in a client bundle. Removing it from the next release does not remove it from the old one.

08

Detection: assume the bundle is public

  • Read the production bundle and source maps; search for token patterns, provider key prefixes, internal hostnames and mobile money identifiers.
  • Inspect localStorage, sessionStorage, IndexedDB, Cache Storage and cookies after a normal login, not only after an attack.
  • Add secret scanning to CI and pre-commit hooks, plus dependency review so a new SDK does not silently add a persisted token cache.
  • Use CSP and Trusted Types to reduce XSS reach, and monitor token use for anomalous geography, velocity or scope.
  • Plant canary credentials in client-accessible configuration and alert on their use. A canary that fires is a detection win; one that never fires costs nothing.

09

Remediation that removes the class

  • Introduce projection at the API boundary and delete sensitive fields before they reach the store.
  • Stop persisting whole stores; persist only non-sensitive UI state, with an explicit allowlist.
  • Move refresh tokens to httpOnly Secure SameSite cookies or a BFF; keep access tokens short-lived and in memory where possible.
  • Revoke and rotate every credential that was exposed, then shorten TTLs and scope keys to the minimum.
  • Add contract tests that fail when a response gains an unexpected sensitive field, and lint rules that block persistence of auth slices.
  • Treat mobile storage as a separate surface: Keychain or Keystore for tokens, no secrets in logs, backups excluded where appropriate.

10

Checklist across platforms

  • Firebase: rules tested with the emulator; App Check enforced; custom claims set only by trusted code.
  • AWS: Cognito unauthenticated roles empty; API Gateway authorizers on every route; Lambda roles scoped per function.
  • Azure: Entra token audience and tenant validated; Functions auth level not anonymous by accident; managed identities for service calls.
  • Supabase: RLS enabled on every table; service_role absent from client bundles; storage policies match table policies.
  • Cloudflare and edge platforms: secrets bound per environment; preview deployments protected; JWTs verified at the edge, not just decoded.
  • Mobile: Keychain or Keystore, no secrets in logs, backup rules reviewed.

Tools and platforms

  • Firebase
  • JWT
  • Redux-style persistence
  • OWASP API Top 10
  • AWS Cognito
  • Azure Entra / MSAL
  • Auth0 / OIDC
  • Supabase RLS
  • Browser storage APIs

Next

Serverless security beyond Firestore rules