Skip to main content

Home › All stories

How to keep credentials out of a browser agent's context and logs

The short answerKeep credentials out of a browser agent by letting code, not the model, handle logins. Load a saved login state or fill password fields from a secret store in the harness, give the agent its own least-privilege account, and mask secrets in traces, videos and logs before they are stored.

By · Published · Updated · 5 min read

To keep credentials out of a browser agent's context and logs, never give them to the model. Let the harness, the code around the model, handle every login, and treat everything the agent sees or records as something that may be read later.

Where can a credential leak from a browser agent?

A credential can leak from a browser agent through six places:

Table: Where browser agent credentials leak

PlaceHow it leaks
The prompt and conversationThe model can repeat it, and it is sent to the model provider
Model and application logsPrompts and tool calls are often logged in full
Traces and screenshotsA trace stores DOM snapshots, so a typed password can be in it
Videos and session replaysEvery keystroke shown on screen is recorded
Saved login state filesCookies and tokens in the file let anyone act as the user
A manipulated agentA web page instructs the agent to type secrets into an attacker's form

The OWASP Top 10 for LLM applications lists two of these risks directly. LLM02, Sensitive Information Disclosure, covers credentials among the data a model application can expose. LLM01, Prompt Injection, covers the last row: "Indirect prompt injections occur when an LLM accepts input from external sources, such as websites or files" (OWASP LLM01:2025, OWASP LLM02:2025, read 2026-11-24).

Research shows the last row is practical. The EIA study placed hidden elements on real websites and reported "up to 70% ASR in stealing specific PII" from a capable web agent (EIA, arXiv 2409.11295, read 2026-11-24).

Step 1: How do I log an agent in without the model seeing the password?

Log the agent in with code, before or during the task, so the password never enters the model's context. There are two patterns.

Pattern A: a saved login state.

  1. Sign in once in a clean browser context, by script or by hand.
  2. Save it with Playwright's context.storageState({ path }).
  3. Start each agent session with browser.newContext({ storageState }), which Playwright says "can be used to initialize context with logged-in information" (Playwright Browser API, read 2026-11-24).

The agent opens the site already signed in. It never sees a password.

Pattern B: a login tool.

  1. Give the agent a tool such as login(site) instead of a password.
  2. When the agent calls it, the harness reads the secret from your secret store and fills the field with locator.fill(), outside the model loop.
  3. The tool returns only "signed in" or "failed" to the model.
  4. Check the page's origin before filling, so the tool only fills the password on the real site's address.

Pattern B also handles one-time codes: the tool can fetch the code from an authenticator or ask a person, and the model sees neither.

Step 2: How do I protect the saved login state file?

Protect the login state file like a password, because it works like one. Playwright's authentication guide says "The browser state file may contain sensitive cookies and headers that could be used to impersonate you or your test account" and "We strongly discourage checking them into private or public repositories" (Playwright authentication, read 2026-11-24).

  1. Keep it in your secret store, not in the image or the repository.
  2. Mount it into the session at start and delete the session afterwards.
  3. Give it a short life: refresh it on a schedule and revoke old sessions on the site.
  4. Use one file per agent identity, never one shared account for all agents.

Step 3: Which account should the agent use?

The agent should use its own account with the least privilege the task needs, not a person's account. OWASP's first mitigation for prompt injection is to "Enforce privilege control and least privilege access", and to "Restrict the model's access privileges to the minimum necessary for its intended operations". It also advises: "Provide the application with its own API tokens for extensible functionality" (OWASP LLM01:2025, read 2026-11-24).

In practice:

  • Create a service account per agent or per task type.
  • Give it read access if the task only reads.
  • Turn on the site's own alerts and limits for that account.
  • Never reuse a person's browser profile, which carries every site they are signed in to. Chrome no longer allows its remote debugging switches on the default profile, partly because of "an increase in attackers using Chrome Remote Debugging to extract cookies" (Chrome remote debugging changes, read 2026-11-24).

Step 4: How do I keep secrets out of traces, videos and logs?

Keep secrets out of recordings by masking at capture time, not by cleaning up afterwards.

  1. Start recording after login. With pattern A, the login happened before the session. With pattern B, pause tracing and video around the login tool call.
  2. Mask inputs in DOM replays. rrweb masks password fields by default (maskInputOptions defaults to { password: true }), can mask every input with maskAllInputs, and skips any element with the class rr-block: "An element with the class name .rr-block will not be recorded" (rrweb guide, read 2026-11-24).
  3. Treat Playwright traces as sensitive. A trace holds "a set of complete DOM snapshots for each action" and the network requests (Playwright trace viewer, read 2026-11-24). Cookies and authorisation headers in those requests are in the trace. Store traces with the same access rules as the login state.
  4. Redact before logging. Filter known secret values and patterns (tokens, Authorization headers, Set-Cookie) out of prompt logs, tool-call logs and network logs before they leave the session.
  5. Keep recordings for a limited time. Delete them on a schedule.

Step 5: How do I stop a manipulated agent from sending secrets out?

Stop a manipulated agent from sending secrets out by limiting where the browser can connect and by requiring approval for risky actions. OWASP lists "Require human approval for high-risk actions" among its mitigations (OWASP LLM01:2025, read 2026-11-24). Combine that with a network allow-list, so that even if an agent is tricked into posting data, the browser cannot reach the attacker's site. Our guide to restricting a browser agent's network access shows how.

What is a quick checklist for browser agent credentials?

Use this checklist before an agent touches a real account:

  1. No password, token or cookie appears in the prompt, the system message or tool results.
  2. Logins happen through a saved state file or a login tool run by code.
  3. The agent has its own least-privilege account.
  4. Login state files live in a secret store and expire.
  5. Recordings start after login, and password fields are masked.
  6. Logs are filtered for secrets before storage.
  7. The browser can only reach the sites the task needs.
  8. Purchases, deletions and messages to new recipients need a person's approval.

What we read for this article

Frequently asked

Why should I not put a password in the agent's prompt?

Everything in the prompt can be repeated by the model, stored in logs and sent to the model provider. A page carrying a prompt injection can also ask the agent to type what it knows into a form. A password the model never saw cannot be leaked that way.

How can an agent log in without seeing the password?

The harness logs in for it. Either load a saved login state file into a new browser context, or let the agent ask for a login and have code fill the password field from a secret store, outside the model's view.

Are Playwright storageState files sensitive?

Yes. Playwright's documentation says the file may contain sensitive cookies and headers that could be used to impersonate the account, and strongly discourages checking it into any repository.

How do I keep passwords out of session recordings?

Mask them at capture time. rrweb masks password inputs by default and can mask all inputs or block marked elements. For screenshots and videos, keep login steps out of the recording or blur the fields.