Blog · · 12 min read

Chatbot identity verification: bind embedded AI agent conversations to a verified end user so visitors cannot impersonate customers or resume their chats

Chatbot identity verification: bind embedded AI agent conversations to a verified end user so visitors cannot impersonate customers or resume their chats

An AI agent that answers public questions does not care who is asking. The day it reads an order, a subscription, or a support ticket, the chat widget becomes a login screen, and usually the weakest one in your product. Chatbot identity verification is how the agent learns who it is talking to, and most failures happen around the token rather than inside it: a conversation anyone can resume with a leaked ID, an anonymous chat that merges into the next account to sign in, a user switch that keeps the last customer's context, or a verification feature that was configured but never enforced. This guide covers the identity lifecycle an embedded agent needs and the tests that prove it holds.

Why the embedded surface becomes the weakest login in your product

Your product already authenticates users, but the agent runs in a widget, iframe, mobile SDK, webview, or backend call that does not share that session. Usually a client-side identify, setUser, or boot call tells it who the user is.

Botpress states the problem plainly: Webchat does not know who your users are, and a user can give the bot any name or any email address. That is harmless for a bot that only answers documentation questions and dangerous once the bot can look up an account.

Practitioner reports show what happens when the claimed identity is trusted:

  • In chatwoot/chatwoot#2762, any visitor could call setUser with another customer's email and name, and the conversation was assigned to that existing customer with no way for agents to tell. The fix was an inbox setting to make the HMAC identifier mandatory.
  • In cheshire-cat-ai/core#1137, an author report on an open-source agent framework, a default installation with no API key accepted a client-supplied user_id header as the authenticated identity with full permissions, and the proof of concept read another user's conversation history.

Neither failure involves the model. Both are ordinary authentication bugs at a new entry point, made worse because the agent uses whatever identity it was handed.

Three identity states your agent must distinguish

Before writing token code, decide what kinds of caller the agent can have. Three states cover most products:

StateHow it is establishedWhat the agent may do
AnonymousNo credential; the server issues a visitor identityPublic knowledge and explicitly public reads
Trusted assertionYour backend calls the agent API with a credential allowed to assert a userWhat that backend credential and the tenant policy allow
Verified tokenThe browser or app presents a short-lived token your backend signed for the logged-in userAccount reads and actions, subject to per-operation authorization

Keep display traits such as name, email, plan, and company in a separate profile object. They help with greetings and CRM routing, but the page can set any of them. Agentkit's guide to authenticated chatbots makes the same split between claimed identity, authenticated identity, and the authorized resource. MakeYourAgent's chat API, for example, takes a display-only user object and a separate identity field that carries either a signed end-user token or, for server-to-server calls, a subject that requires a dedicated assertion scope; the service rejects identity credentials placed inside free-form metadata.

The anonymous state needs as much design as the verified one, because an anonymous visitor still owns the conversation they started.

Mint the token from your existing session

The token endpoint is the one piece of new backend code most integrations need. Four rules apply.

  1. Read the user from your existing session. Botpress warns that you should take the values from the user session and not from the request, because if the browser can select the user, the token gives you no protection. The endpoint sits behind your normal login.
  2. Use a stable internal identifier as the subject. Chatbase requires user_id or sub and recommends UUIDs over emails or usernames that might change. An email can be reassigned; a primary key cannot.
  3. Keep the lifetime short and refresh it. Intercom advises token expiration that matches your app's session length and refreshing tokens when you update user information. Botpress sets no maximum token life, so a short exp is your job.
  4. Keep the token out of durable browser storage. ChatSystem's guide says the short identity stays in widget memory, never in localStorage, sessionStorage, a URL, the DOM, or analytics.

A minimal endpoint looks like this:

// Runs on your backend, behind your existing login middleware.
app.get("/api/agent-identity", requireSession, (req, res) => {
  const user = req.session.user;            // never req.body or req.query
  const token = signJwt(
    {
      sub: user.id,                         // stable internal ID
      aud: "support-agent",                 // the agent API, not your app
      tenant: user.tenantId,
      exp: nowSeconds() + 15 * 60,          // short, refreshed by the page
    },
    process.env.AGENT_IDENTITY_SIGNING_KEY  // server-only secret
  );
  res.json({ token });
});

On the page, timing matters too. Botpress notes that if you start Webchat before the token arrives, the user can send a message before Botpress checks the identity. Fetch the token first, then initialize the agent surface.

Bind every conversation to its owner

Verifying the token and authorizing each lookup still does not prove that the person continuing a conversation is the person who started it.

A conversation ID is a bearer credential unless the conversation is bound to a principal, so give anonymous visitors a server-issued identity too and reject any token whose subject differs from the conversation's before loading history.

The everruns project fixed this bug in 2026. Its public chat sessions were resumable using only the app ID and a client-supplied threadId, so a leaked thread ID was enough to read or append to another visitor's conversation. The merged fix routes sessions by a tag derived from the signed-in principal and, for anonymous visitors, from a server-issued HttpOnly, SameSite=Lax visitor cookie. Screenshots, shared links, analytics events, and logs all carry thread IDs.

The binding check should run before anything sensitive is read:

on chat request(conversation_id, credential):
  principal = verify(credential)            # anonymous visitor, assertion, or token
  conversation = load_header(conversation_id)
  if conversation is new:
      bind(conversation, principal.subject, principal.issuer, principal.mode)
  elif conversation.subject != principal.subject or conversation.issuer != principal.issuer:
      reject("start a new conversation")    # before messages, files, or pending actions load
  load messages, files, pending actions

MakeYourAgent's identity design follows the same order: a conversation bound to one verified subject rejects a request carrying a token for a different subject without loading conversation content or executing tools, and the client has to start a new conversation. Whatever platform you use, test that a valid token for user B cannot open user A's conversation ID, and that an anonymous visitor in a second browser gets "not found" for a conversation started in the first.

Handle upgrade, logout, and account switch as lifecycle events

Identity changes mid-conversation more often than teams plan for: a visitor logs in after asking a question, a colleague logs in on a shared laptop, an agency user switches client workspaces in one tab.

Treat an identity change in the same browser or device as a teardown, not a profile update: do not auto-merge anonymous conversations into the account that signs in next, and re-authorize any pending action created before the upgrade.

Several platforms merge by default, which is convenient and risky. Chatbase's Android SDK documents that a successful verify() automatically merges previously anonymous, device-scoped conversations into the verified user's account. Intercom notes that if a user logs in within the same browser after starting a conversation as a lead, they will be upgraded to a user. On a personal phone that is what the user wants. On a shared device, the pre-login conversation may have been typed by someone else, and merging it attaches their messages, and possibly their personal details, to the account that signs in.

In chatwoot/chatwoot#15933, opened on 2026-09-21 and still open, a host page called setUser with a different identifier on a browser that already held another contact's session cookie. The API switched contacts, but the widget's realtime socket kept streaming from the old contact's channel, so replies never appeared. The reported workaround is deleting the widget cookies whenever the identity changes. As reported, it breaks message delivery rather than leaking data, and it shows how much state an identity change must replace.

A decision table makes the policy explicit:

EventConversationStream subscriptionPending actionsMemory
Anonymous to verifiedStart new, or offer an explicit "attach this chat" step that is loggedReplaceDiscard or re-authorize under the verified principalDo not copy anonymous memory into the account by default
LogoutEnd and clear the client's conversation IDCloseCancel anything not yet confirmedKeep server-side, scoped to the account
Account or tenant switchStart newReplaceCancelScope to the new account only
Token refresh, same subjectContinueKeepKeepKeep

Client SDKs expose the hooks. Chatbase documents a resetUser call for logout and an Android logout() that clears the current conversation ID, and ChatSystem's provider has a subscribe() callback that tells the widget to forget the previous identity after login, logout, or an account switch. Call them from the code that handles your auth state changes.

Keep display traits out of authorization and out of the model's trust

Teams often keep sending the old unsigned profile next to the signed token, and that second channel reaches the model. Chatbase documents that attributes passed outside of the JWT are visible to the AI agent and advises keeping sensitive information inside the token. Botpress warns that it does not check the data field, and data in that field has no more value than text from the user. Anything the page can set, an attacker can set, including a name of "admin" or an account_id belonging to someone else.

Three rules follow, framed as implementation recommendations:

  • Tools that act on user-owned resources receive the owner from the verified principal, injected server-side. If the model or the page supplies a customer ID, ignore or reject it rather than preferring it.
  • Treat model-visible profile fields as untrusted text, the same as a user message. The OWASP AI Agent Security Cheat Sheet lists "rely solely on model output for authorization decisions" as a don't, and a prompt that says "the customer's account is 2187" turns an unsigned claim into exactly that.
  • Never place the raw identity token in the prompt, the transcript, or tool logs. The agent needs the result of an authorized lookup, not the credential.

Zendesk's Get User action shows a cleaner pattern: it exposes whether the user is authenticated, plus externalId and authenticatedEmail, so a flow can branch on verification state.

Turn enforcement on everywhere and prove it

Signing tokens is not enforcement: prove on every surface that an unsigned, wrong-subject, or attribute-only request is rejected, because vendors ship verification behind separate switches and leave unsigned fields beside the signed one.

Intercom says that turning Messenger security off leaves your data vulnerable to unauthorized access or cross-user impersonation, and that securing web while leaving iOS or Android integrations unsecured still puts data at risk. Botpress accepts unsigned user data until an administrator adds a public key, after which Webchat rejects user data that has no signature. Chatwoot users in 2021 reported that sending an identifier_hash did not stop a spoofed email from overwriting an identified contact until the maintainers added an enforcement toggle (#2762). In each case the integration can look correct in a demo, with tokens flowing, while the unsigned path is still open.

Write the negative tests first and run them against every surface that can start a conversation: web widget, mobile SDK, webview, and any server API your backend or partners call.

TestRequestExpected result
No credentialAccount question with only display traitsPublic answer or login prompt; no account read
Attribute onlyuser.id or account_id set in profile or metadata, no tokenSame as no credential
Wrong subjectValid token for user B on user A's conversationRejected before history loads
Leaked conversation IDUser A's conversation ID from a fresh browserNot found
Expired tokenReplay after expRe-authentication; no tool call
Wrong audience or tenantToken minted for another agent or tenantRejected
Model-supplied ownerPrompt asks for order 4813 owned by someone elseOwnership check denies; generic not-found reply
Same-device switchLog out A, log in B, open the agentNew conversation; no A messages, no A stream
Upgrade with pending actionAnonymous request creates a draft action, then loginAction requires fresh authorization under B

Agentkit's guide has a cross-account test table; the rows above add conversation ownership, enforcement, and lifecycle. Keep them in CI and rerun them after any identity, widget, or platform change.

Failure handling and tradeoffs

  • Token expires mid-conversation. Refresh silently while the session is valid. If refresh fails, keep the conversation readable, but require login before the next account read or action rather than continuing on a stale principal.
  • Signing key rotation. Accept old and new keys for a bounded overlap, then fail closed. Test rotation before you need it.
  • Anonymous chat still has to work. Give anonymous visitors a server-issued identity, least privilege, and rate limits, and offer login when a request needs account data.
  • Lead-style identities. If visitors can type an email to "identify" themselves, treat that as contact information. Intercom states it does not verify that leads own the email addresses they enter and recommends prompting leads to log in or routing locked-out users to a secure flow. Account recovery belongs in your reviewed recovery process, and OWASP recommends step-up authentication for critical actions such as account recovery.

A rollout sequence for an existing product

If the agent is already live with unsigned identity, change it in stages. This sequence is a recommendation drawn from the sources above.

  1. Inventory every surface and field that carries identity today, and mark which are signed.
  2. Add the token endpoint and send tokens alongside the existing profile, with verification in audit-only mode. Log mismatches between the claimed and verified subject.
  3. Bind new conversations to their principal, including anonymous visitors, and reject subject mismatches for internal users first.
  4. Require a verified principal for the riskiest operations: refunds, address changes, subscription changes, and any read that exposes personal data.
  5. Turn enforcement on for every surface in the same release, run the negative tests against production, and treat existing conversations as unverified.

What to do next

Pick the one account-specific action your embedded agent performs most often, such as order status. Run the "attribute only" and "wrong subject" rows from the test table against it on web and on your mobile app today. If either returns account data, enforcement is not on where you think it is, and that is the first fix, before any change to prompts or models. Then add conversation binding, so your chatbot identity verification covers the conversation itself and not only the first request.

Be first in line.

Join the waitlist and we'll email you the moment it's ready. No sales call.

Try the demo →
or talk to us