Hassan SalemNotebook · München
← Notebook
AI17 November 20268 min read

The Dashboard Was Great. The Key Was in the Browser

A secret in the browser is not a secret. Ask the agent where the key ends up after the build, not only where it is written.


"Built our customer health dashboard over the weekend. No engineers were harmed!"

Mira posted this in our general channel on Wednesday at 07:50, with a link and a screenshot. Mira runs customer success. She does not write code, or she did not until two months ago.

The screenshot looked really good. Every customer as a card, green, yellow or red. Last payment, failed payments, open support tickets, days since last login. I know engineers who would need a sprint for this.

I opened the link with my coffee. It loaded fast. No login screen.

That was the first small itch.

Old habits in DevTools

I have a habit from many years of doing code reviews for frontend people. When I open a new web app, I open DevTools, go to the sources, and search the bundle for a few words. token, secret, key. Most of the time I find nothing and feel a bit paranoid.

This time the third search had a hit.

const PAYMENT_API_KEY = "live_****************************";
// Note: for production, move this key to a secure backend.

The prefix was the one our payment provider uses for secret live keys. Not a public key. The real one, the one that can read every customer, every invoice, and also create refunds.

It was in a JavaScript file that anyone with the link could download. And the link was in our general channel, where we also have two freelancers and an agency that helps us with marketing.

My first feeling was cold in the stomach. My second feeling was frustration, and I have to be honest, a part of it was at the agent. It wrote a comment that said "move this to a secure backend". It knew. It put the warning in the one place the user would never read.

I deleted the message I started typing in the channel. A public "SECURITY PROBLEM" message at 08:00 helps nobody and makes one person feel terrible in front of everyone.

A phone call, then a key rotation

I called Mira.

She was proud of the dashboard, so I started with that, because it was true. Then I told her what I found, slowly, without the words "exposed" and "breach". She understood fast. She went quiet for a second and said: "But it kept saying unauthorized. I gave it the key and asked it to make it work."

That was exactly the story. The agent asked for credentials, she opened our shared password vault, copied the key that our backend uses, and pasted it in the chat. The agent made it work. That was the request.

We agreed on three steps. She takes the link down from the hosting right now. I rotate the key. Then we look together at how to build it properly.

Rotating sounds simple. It was not, because this key was not only in Mira's app. It was the same key our production backend uses for checkout. If I rotate it and forget one place, checkout breaks in the middle of a Wednesday.

So I opened the agent in our main repos and gave it a narrow job:

Do not change anything.
Search all repositories, CI variables and deployment configs
you can read for any use of the payment provider secret key.
List file, line, and how the value gets there.

Here the agent was great. It found the two places I knew: the backend config and the CI secret. And it found a third one I did not know at all: an old billing export script in a forgotten folder, running once a month on a small server, with the key in its own config file. Without that list, the rotation would have broken a report on the first of next month, and someone would have spent a day to find out why.

I rotated the key at 09:30, updated the three places, made a test payment on our staging and one small real one with my own card. Everything worked. Then I checked the provider's logs for the old key since Saturday. Only calls from our backend and from Mira's dashboard. Nobody else had used it.

We were lucky. Luck is not a process.

A secret in the browser is not a secret. It is a public value that nobody has looked at yet.

The fix that was not a fix

Mira's dashboard was useful, and the team wanted it back. So I opened her repo with the agent and wrote, a bit too short: "Remove the hardcoded payment key from the frontend."

The answer came fast and proud. It created a .env file, put the key in a variable called VITE_PAYMENT_API_KEY, and changed the code to read import.meta.env.VITE_PAYMENT_API_KEY. It even added .env to .gitignore. Then the summary: "The key is no longer hardcoded and will not be committed to git."

Technically every word was true.

And the key would still be in the bundle. In Vite, variables with the VITE_ prefix are replaced into the client code at build time. That is the whole purpose of the prefix. The agent moved the secret from line 12 to a file that gets copied back to line 12 during the build.

I laughed a little, the tired kind of laugh. Then I asked: "After npm run build, is the value of this variable present in the files in dist?"

It answered correctly, immediately, and explained the Vite behavior better than I just did. It knew the docs perfectly. It just answered the question I wrote, not the problem I had. "Remove the hardcoded key" is a different request than "the browser must never see this key". The second one was in my head, not in the prompt.

So we did it properly. A small endpoint in our Kotlin backend, behind our company login, using a new restricted key with read rights only:

@GetMapping("/internal/customer-health")
@PreAuthorize("hasRole('STAFF')")
fun customerHealth(): List<CustomerHealthDto> =
    paymentClient.listCustomersWithLastPayment()
        .map { it.toHealthDto(tickets.openCountFor(it.customerId)) }

The frontend now calls this endpoint and never sees a key. The agent wrote most of it in twenty minutes, including a test that the endpoint returns 403 without the staff role. I asked it to also write a test that fails if any string looking like a provider key appears in the built frontend files. It suggested to run it in CI, which was a good idea.

Not a locked door

At lunch our CEO asked if we should stop people like Mira from building tools.

I said no. In one weekend she built something that customer success needed for months, and she understood her own users better than I ever will. The problem was not that she built it. The problem was that she had nobody to tell her where the danger is, and the agent only whispered it in a comment.

So we changed a few small things. Mira helped with all of them.

We made a starter repo for internal tools. It has a tiny backend with company login already wired, so the "make it work" path is also the safe path. And it has an instruction file the agents read at the start of every session, CLAUDE.md and the same text in AGENTS.md for the other tools:

Never put API keys, tokens or passwords in frontend code,
in VITE_ or NEXT_PUBLIC_ variables, or in comments.
If an API needs a secret, stop and tell the user:
"This needs a backend endpoint. Ask engineering for 15 minutes."
Every internal tool must require company login.

We also moved the payment key in the password vault to a folder that only the backend deploy can read. Humans do not need to copy it anymore, so nobody can paste it into a chat by accident.

Mira tested the starter repo on Friday with a new idea, a small tool for renewals. The agent stopped at the payment API and told her to ask engineering. She sent me a message: "It told on me." Fifteen minutes later she had her endpoint.

What I keep from this week

  1. Ask where the secret ends up, not where it is written. After any change with keys, my question to the agent is: "After the build, which files contain this value?" It answers this one correctly.
  2. Write the real constraint into the prompt. "Remove the hardcoded key" and "the browser must never see the key" sound the same to a human. For the agent they are two different tasks.
  3. Make the safe path the easy path. A starter repo with auth and a backend already there helps more than a policy document nobody reads.
  4. Secrets humans cannot copy cannot be pasted. Keep production keys where only the deploy can read them, and give people restricted keys for their own tools.
  5. Before rotating, let the agent find every use. It found the forgotten script in two minutes. I would have found it on the first of next month.

The agent knew the right answer the whole time. It wrote it in a comment. I keep thinking about how many of those comments sit in our code right now, polite and correct, and unread.

Do you search your bundles for keys, or do you also only find out when someone opens DevTools with their coffee?

Written by Hassan Salem in Munich — software engineer, slow German learner, compulsive note-taker. More about me →

Telc German B1 Exam Success Kit (20/80 Rule)

If this was useful

Telc German B1 Exam Success Kit (20/80 Rule)

The 20% of German that keeps showing up in the telc B1 exam. Learn it first and walk in already knowing what to expect. €7.99

Get it on Gumroad — €7.99