Security Questions to Ask Your AI Coding Agent

My AI coding agent built The Field Map, a store with a cart, checkout, payments, cancellations and returns. It works. The tests pass. And until this week, every order link looked like this:

/orders/TFM-1001?key=8f3a…

The key let a guest come back to their order without an account. Anyone holding it could see the shipping address, cancel the order, or start a return.

I didn't find the problem by reading code. I was thinking through a different design and asked: if links like that show up in logs, and an attacker can read the logs, can they use the links? The answer was yes. URLs get written to server logs, proxy and CDN logs, browser history and email. That key was a password sitting in all of them.

The agent knew this. Once I asked, it explained the risk, filed the issue, and shipped a fix the same day. But it built the store with the key in the URL in the first place, and nothing in a passing test suite would have told me. The agent answers the questions you ask. The security of what it builds depends on which questions you know to ask.

The store was in test mode with no real customers, so nothing leaked. Here are the questions I ask now, and what each one caught or would catch.

1. Where does this secret travel?

A secret isn't just where you store it. It's everywhere it passes through. URLs are the classic leak: they're logged by default almost everywhere. Headers usually aren't. Cookies marked HttpOnly aren't readable by page scripts.

Ask: "List every place this token or key is sent, stored or displayed. Which of those write logs?"

What it caught: the order key. The fix wasn't protecting the key better. It was removing it. The browser that places an order now gets a cookie, and on any other device you sign in with an emailed code. The URL is just /orders/TFM-1001.

2. What does the model see?

When an AI agent uses a tool, the tool's arguments go through the model. They land in the conversation, in the client's logs, and possibly in the model provider's logs. That makes them another kind of log.

Ask: "Does any secret pass through a tool argument or a prompt?"

What it caught: the second half of the same bug. The store's MCP interface, the one AI agents use to shop, returned an access_key at checkout and required it on every later call. Same password, different log. Now an agent's carts and orders belong to its MCP session, and the session ID travels in a header the model never sees.

Once I knew to ask question 1, the agent found this one itself. Naming a concept doesn't just fix one bug. It finds the copies.

3. Who holds the keys?

An agent that holds long-lived credentials can do anything those credentials allow, whether you asked it to or not.

Ask: "What credentials does the agent have? Could it do damage with them if it misunderstood me?"

I wrote about this in The Agent Does Not Hold Its Own Keys. My agent pushes code. The build system and the cluster decide what runs. The agent never holds the cluster's credentials.

4. Where is the rule enforced?

A rule in a prompt, a README or a hidden button isn't enforcement. It's a suggestion. Enforcement happens at the point where the action takes effect: the server, the database, the runtime.

Ask: "If someone skips the UI and sends the request directly, what stops them?"

In the store, the order page only shows a Cancel button when cancelling is valid. That's the convenience. The enforcement is that the server checks again on every request and refuses a cancel for an order that has shipped, whoever asks. I learned this the hard way in Enforce It Where It Takes Effect.

5. Can someone guess the next one?

Order numbers, invoice numbers and user IDs often count up. If knowing the number is enough to open the record, anyone can walk the whole list.

Ask: "Can a stranger get a record by changing a number in the URL? Do they get a different error for 'doesn't exist' than for 'not yours'?"

The store's order numbers count up (TFM-1001, TFM-1002), so they're never enough on their own. Someone who isn't allowed to see an order gets the same "Sign in to see this order" page whether it exists or not, so they can't even learn which numbers are real.

6. Is it stored in plain text?

If the database leaks, every plain-text token in it is a working key.

Ask: "Which secrets are stored as-is? Can we store a hash instead?"

The store keeps only hashes of session tokens, sign-in codes and guest cookies. A copy of the database doesn't let anyone sign in as anyone.

7. What happens if this runs twice?

Networks time out. People double-click. Agents retry. If "pay" runs twice, you charge twice.

Ask: "What happens if this request is sent twice? Is it safe to retry?"

The store's payment form carries an idempotency key, a unique ID for that attempt. The payment system recognizes a repeat and returns the first result instead of charging again.

8. When does it stop working?

A credential that never expires is a credential that's waiting to leak.

Ask: "How long is this valid? How do we revoke it?"

The store's sign-in codes last 10 minutes and allow five wrong guesses. Staff sign-in codes from an authenticator app work once, so a code seen over someone's shoulder can't be replayed. MCP sessions expire after 24 hours.

9. Where can this redirect go?

"Sign in, then go back to where you were" is a convenient feature, and a classic hole. If the destination comes from the URL, an attacker can send people through your real sign-in page and on to their own site.

Ask: "Where can this redirect send someone? Who controls that?"

The store only redirects after sign-in to a path that matches an order page. Anything else goes to the account page.

10. Who can reach this before it's live?

Preview and staging environments feel private. Often they're just unlisted public URLs.

Ask: "Who can reach this right now, and what data is in it?"

My previews are public URLs. So the rule is simple: no unfixed security holes and no real data on a preview, because "nobody knows the address" isn't a protection.

The pattern

None of these are new. They're the questions an experienced engineer asks without thinking, because they've seen each one go wrong. An agent can write the code faster than I can. It can explain every one of these concepts when asked. What it doesn't reliably do is stop and ask them on its own.

So the job changes. You're not reviewing every line. You're reviewing the design by asking the questions that come from knowing how systems fail. The agent does the rest.

Checklist

Before you ship something an agent built, ask it: