‹ Back to Analyzer

Public Keys vs Secret Keys in Frontend Code

Seeing a key in your JavaScript does not always mean a breach. What matters is what the key can do, and who can use it.

Browser code is downloadable by design. Some services therefore give you an identifier made for browsers. Others give you a credential that must stay on a server. Confusing the two is the root of most frontend key mistakes.

Usually safe to be public (with restrictions)

  • Firebase web config: identifies your project. Protection comes from security rules, authentication and App Check.
  • Google Maps browser keys: should be limited to your domains and specific APIs, with quota alerts.
  • Publishable payment keys (for example ones that start with pk_): designed for the browser and limited to creating payment sessions.
  • Analytics measurement IDs: not secret, though others can send fake events to them.

Never put these in frontend code

  • Secret or admin keys (for example ones that start with sk_), service-account JSON files and private signing keys.
  • Database connection strings and passwords.
  • Tokens that grant write access to user data or billing.
  • Any value your provider says must be kept confidential.

A quick decision test

  1. Read the provider’s documentation: does it say the key is safe for browsers?
  2. Ask what an attacker could do with it. Read only public data, or spend money and change records?
  3. Check restrictions: domain limits, scopes, quotas, rules.
  4. If in doubt, treat it as private and move the call to your server.
If a secret was exposedRotate it at the provider first, then remove it from the code and redeploy. Follow the remediation workflow and re-scan with CodBy.

Related reading: the frontend security checklist.

Open CodBy Analyzer