Skip to content
HARDEX

Guide

Which API keys are safe to put in a web page?

A web page is sent to every visitor, so anything written in it can be read by every visitor. Some keys are made for that, and some must never go near a page. Mixing them up is one of the easiest mistakes to make when an AI tool writes your code.

This guide explains how to tell them apart, with examples, and what to do to limit the ones that are public. You do not need to be a developer.

1Keys made to be public

Some services issue a key meant for pages. Examples are the publishable keys of payment services (Stripe's start with pk_), public map tokens (Mapbox's start with pk.), the public key that lets an app talk to a database such as Supabase, and the web settings of a Firebase project. They are safe in a page only because the service protects the data in another way, for example with access rules.

Check it yourself: For each key in your pages, look it up in the service's documentation and find the sentence that says whether it may be used in a browser.

What to do: Keep a key in the page only if the documentation says it is meant for that, and make sure the protection it relies on is switched on: access rules, allowed websites or permissions.

2Keys that must never be in a page

A key that can spend money, send messages or read all your data does not belong in a page. Examples are the secret keys of payment services (Stripe's start with sk_), the admin key of your database, and the keys of AI services, email services and text-message services. Anyone who copies one can use your account.

Check it yourself: Open your live app, press F12, go to the Sources or Network tab and search the files for sk_, sk-, secret and token.

What to do: Move the key to a server. The page asks your server, and the server asks the service. Then replace the key, because anyone who saw it can still use it.

3Names that publish a key by accident

Some build tools send every variable with a certain name to the browser on purpose: names that start with NEXT_PUBLIC_ in Next.js and with VITE_ in Vite. Putting a secret in a variable like that publishes it, and the name is the only thing that decides.

Check it yourself: Look at the names of your environment variables. For any that start with NEXT_PUBLIC_ or VITE_, ask: is this value allowed in a page?

What to do: Rename the variable so it does not start with the public prefix, and use it only on a server. Replace the key if it has already been published.

4Limit the public keys too

A public key can still be copied and used from somewhere else, to run up your bill or to fill your data. Services give you ways to limit it, and they are easy to skip.

Check it yourself: In the service's dashboard, look at the settings of each public key for allowed websites, allowed actions and spending or usage limits.

What to do: Restrict each key to your own website addresses and to the actions your app needs, and set a spending limit where the service offers one.

What a check can and cannot tell you

Passing these checks does not prove an app is safe. It means these problems were not found. A full review also looks at how your app handles each person's data, and that takes someone who reads the code or tries to get past the sign-in.

Check them all from the outside

Hardex scans a live app the way a stranger on the internet would, with nothing to install. By default it only reads: it never changes anything in your app. It looks for the problems above where they apply to your app, and more, then reports what it found.

What each plan includes is on the plans page.

Scan your app