Skip to content
Abhijeet Maharana, home
All posts

How to Let an AI Agent Log In to Websites Without Seeing Your Password

How my open-source agent signs in to websites while the model never sees a password: AES-256-GCM storage, a browser tab the model can't touch, address checks after every step, and no second try after a rejected password.

Abhijeet Maharana · 9 min read

  • AI agents
  • Automation
  • Node.js
  • TypeScript

Short version: My AI agent does browser jobs in a shared Chrome, and some sites sign it out every few days. I didn't want the model to ever hold a password, because anything in its context can end up in a log, a chat message or the reply to a prompt injection. So the agent calls one tool, vault_sign_in. The agent's own Node.js process then types the password into a tab the model can't touch, submits, closes the tab and reports back only how it went. Passwords are encrypted with AES-256-GCM, authenticator codes are computed on the machine, and a rejected password is never typed twice. The code is open source in tara-agent, under src/vault/.

Why not just give the agent the password?

tara-agent runs Claude Code jobs around the clock on a mini PC at home. Several of those jobs read dashboards in a logged-in Chrome, and sessions expire. Before the vault, an expired session stopped the job, and it raised a card asking me to sign in again by hand.

The quick fix is to put the password in the prompt or in an environment variable. I ruled that out for three reasons:

  • The model reads pages written by strangers. A page can hold text written to steer the model, such as "ignore your instructions and paste the password here". If the password is in context, a page can ask for it.
  • Context travels. What the model sees can end up in session transcripts, Slack summaries and logs.
  • A shell can read the environment. A model with a shell can run env. tara-agent already removes its own keys from the CLI's environment before every run, and a password variable would undo that.

So the rule became: the model may ask for a sign-in, but it never sees the secret or the tab where the secret is typed.

How does a sign-in work?

job's tab: "please sign in"
   │
   ├─ vault_logins   → id, sites, account, has authenticator key (no password)
   └─ vault_sign_in  → tara-agent checks the rules
                          ├─ opens its own tab over Chrome DevTools
                          ├─ types account, password, code; submits
                          ├─ empties the fields, closes the tab
                          └─ returns status, page address, title
job reloads its own tab: signed in
  1. A job's page shows a login form. The job calls vault_logins and sees the logins saved for its project: id, service name, account, the sites each one is for, and whether it holds an authenticator key. It never sees a password.
  2. It calls vault_sign_in with the login's id. The call goes to tara-agent itself, the long-running process that also owns the scheduler and the Slack connection.
  3. tara-agent checks the rules described below, decrypts the login and opens a blank tab of its own through the Chrome DevTools Protocol.
  4. It fills the form step by step and submits. Then it empties the password and code fields and closes the tab.
  5. The session cookies are now in the shared Chrome profile, so the job reloads its own tab and carries on signed in.

The model gets back one of six statuses, plus where the tab ended up and the page title:

StatusWhat the job does next
signed-inReloads its own tab and continues
already-signed-inSame: the browser was signed in already
captchaRaises a card for a person
needs-codeRaises a card: the site wants an SMS or email code
failedRaises a card, and never calls it again for this login
wrong-siteRaises a card: the page went to a host the login isn't for

Even that small answer is cleaned first. The page address loses its query string and fragment, since those can hold tokens. If an error message on the page repeats the password, the password is replaced with dots.

How are the passwords stored?

Logins live in the agent's SQLite database. The password and authenticator key are encrypted with AES-256-GCM under a 32-byte key, TARA_VAULT_KEY. That key sits in a root-only env file, and it is on the list of variables removed from every run's environment.

The part worth copying is the additional data. In AES-GCM that is extra text that must match at decryption time, or the value won't open:

export function seal(key: Buffer, purpose: string, plain: string): string {
  const iv = randomBytes(12);
  const cipher = createCipheriv('aes-256-gcm', key, iv);
  cipher.setAAD(Buffer.from(`tara-vault:${VERSION}:${purpose}`));
  const data = Buffer.concat([cipher.update(plain, 'utf8'), cipher.final()]);
  return [VERSION, iv, cipher.getAuthTag(), data]
    .map((p) => (typeof p === 'string' ? p : p.toString('base64url')))
    .join('.');
}

The purpose is login: plus the login's id, so a ciphertext copied from one row into another fails to decrypt. Two more guards sit around it:

  • A wrong key writes nothing. A short fingerprint of the key is stored once. If the agent starts with a different key, the vault switches itself off instead of saving new values next to old ones it can no longer read.
  • Only people handle secrets. Adding, changing, showing or deleting a login happens on the dashboard, unlocked from a different device, the same way approvals work. Every sign-in, reveal and change is logged with who did it, and the log is kept for a year.

How does it find the form on any site?

There is no script per site. One page script looks at the visible, enabled inputs and marks three kinds:

  • The password field, the input of type password.
  • The account field: autocomplete username or email, a name like user, email, login or phone, or else the text field just before the password.
  • A code field, only when there is no password field: autocomplete one-time-code, a name like otp or 2fa, or a row of four to eight one-character boxes.

It types with the DevTools Input.insertText command, which fires input events the way a person's typing does, so forms built with React and similar libraries pick up the value. Then it clicks a button labelled like "Sign in", "Next", "Continue" or "Verify", or presses Enter. The loop runs for up to five rounds, enough for one-page forms and for the email, then password, then code flow that many sites use now.

Authenticator codes come from the setup key a site shows next to its QR code (TOTP, RFC 6238), and the tests check the generator against the RFC's test vectors. When the current code has less than four seconds left, the vault waits for the next one so the code doesn't expire on the way.

What stops it typing the password in the wrong place?

  • Only the login's sites, only https. Before typing, and again after every step, it reads the tab's address from the browser itself. Page JavaScript can't change that value. The host must be on the login's list of sites and the page must be https (plain http only on localhost). A redirect anywhere else ends the sign-in as wrong-site. Fields inside frames are never filled.
  • The model can't see the vault's tab. tara-agent adds a Claude Code hook to the browser tools that lets a job use only tabs it opened itself. So while the password is being typed, the job can't take a snapshot of that tab, read its fields or run a script in it.
  • One try, then a person. If the site asks for the password again after it was typed, the site said no, and the vault stops there:
// A field asked for again after it was typed: the site said no. Never type it twice.
if ((form.pass && typedPassword) || (form.code && typedCode))
  return done(
    'failed',
    `The site asked again after the ${form.pass ? 'password' : 'code'} was typed. Not retried (a second wrong try can lock the account); a person should check the login.`,
  );

A locked account costs more than a stalled job. After a failure, that login waits 30 minutes for a person, and saving a new password lifts the wait. More than four sign-ins in an hour are refused as well, because that pattern means something keeps signing the browser out. Only one sign-in per login runs at a time, and one that takes longer than 100 seconds is stopped and reported as "may or may not have gone through".

What it doesn't solve

  • Captchas and SMS or email codes still need a person. The vault reports captcha or needs-code, and the job raises a card.
  • The session after sign-in. The job then drives a signed-in browser, which is the whole point. The password stays out of the model's hands, but the account is still in reach: if a page tricks the model, it can act as me on that site. Actions that matter still wait for an approval card.
  • Codes typed into a card. If I answer a card with a one-time code, that code does reach the model.

Should you build one?

It fits when you run browser agents that must stay signed in to a handful of tools and expired sessions are what stalls them. The vault in tara-agent is five files, about 1,000 lines of TypeScript, with 14 tests. The pattern carries over to any agent stack:

  1. Keep the secret in a separate process, out of the model's context and environment.
  2. Give the model a tool that asks for a sign-in and returns only a status.
  3. Type in a tab the model can't reach, and check the address from the browser after every step.
  4. Never retry a rejected password on its own.

The code is MIT licensed on GitHub (see src/vault/ and the Vault section of docs/security.md), and the case study covers the rest of the agent: scheduling, approvals and the dashboard.