Testing User Isolation in an AI Product

Testing User Isolation in an AI Product

user avatar

by me1afon

15 minutes ago


AI tools helped gather research and write the first draft of this article. I edited it and checked every quote and figure against the source page listed at the end, read on 2 December 2026. The cover is AI-generated. The two diagrams were drawn by code from a template. Details at the end.

An AI chat product holds many people's data in the same system, and a model sits in the middle of it. To test that one user never sees another user's data, plant a unique marker in one account, try to reach it from a second account through every place data is stored, cached or passed along, and check the result below the model, where the code decides what the model receives. Asking the chat whether it leaks is not a test.

This article is about isolation between users or tenants of your own product. Injection through retrieved text, scoping an agent's tools, redacting private data and a broader attack checklist are separate questions; see When Retrieved Text Tries to Become an Instruction, Giving an Agent Only the Access It Needs, Keeping Private Data Out of AI Context and Logs and Designing a Focused Red-Team Test for AI Chat.

What "isolation" has to cover

In an ordinary web application, user A's records live in a database and the code checks ownership before returning them. An AI chat adds more places where A's data is stored or reused, and each can be wrong on its own:

  • the conversation history and the identifiers that point at it;
  • uploaded files and the text extracted from them;
  • memory: facts the product keeps about a user between sessions (see What Should an AI Chat Remember?);
  • the retrieval index, where chunks of documents sit as embeddings;
  • caches: provider prompt caches, your own response caches, cached tool results;
  • tool calls, where the model supplies an identifier and your code acts on it;
  • background work such as summaries, memory writes and exports, which run after the request that started them;
  • logs, analytics and shared links.

A product can pass every test on the first item and still leak through the fourth.

Why asking the model is not a test

The tempting test is a chat prompt: log in as user B, ask for the previous user's notes, and call it a pass if the model refuses. OWASP's page on sensitive information disclosure says that adding restrictions to the system prompt about what the model should return can mitigate disclosure, and then adds: "However, such restrictions may not always be honored and could be bypassed via prompt injection or other methods" [1]. A refusal tells you how the model behaved in one attempt. It does not tell you whether the other user's text was in its context.

So the test asserts on what the code decides deterministically: which rows the query returned, which chunk identifiers retrieval returned, what the final prompt contained. A model-level probe is a useful extra, repeated because answers vary, but it can show a leak, never prove its absence.

The pattern: two accounts and a marker

The core of the method is small. It is the author's proposal, assembled from the cited guidance; no cited source prescribes it.

  1. Create two accounts as separate as your product allows, in different organizations if it has them. If it also promises separation inside one organization, add a third account there.
  2. Seed a canary in each surface from account A. A canary is a unique, meaningless string, such as BLUE-HERON-4471, placed in a message, a file, a memory item, an indexed document and a tool result. Use no real customer text.
  3. Run a positive control from account A. Confirm that A can retrieve its own canary through the same path. Without it, a test that finds nothing may simply be broken: a wrong query, an index not yet updated, an empty cache.
  4. Probe from account B, then assert on absence. B asks near-matches of the canary's words, never the canary itself, requests A's object identifiers and repeats while the state is warm. Check that the canary appears nowhere in what B receives and, where a test environment can capture it, nowhere in the context assembled for B's request. Separately, check that every record B gets back belongs to B's partition. The exact canary is used only in A's positive control, so it never appears in B's request, and its appearance in B's reply means a leak.
  5. Try the same from a stale or reused identity. After a logout, an account deletion or a removal from an organization, the old session should find nothing.

A unique canary makes a match unambiguous and points to the surface that leaked.

A test matrix by surface

This matrix is a proposal, not a standard.

Surface Seed as A Probe as B Pass if
Conversation and message IDs A conversation containing a canary Request A's conversation and message IDs directly, change one ID, replay A's share link Same refusal as for an ID that does not exist; no canary
Uploaded files A file containing a canary Ask for A's file by ID; ask to summarize "the file I uploaded" B never receives A's file or text
Memory A memory item with a canary Ask what the product remembers B's context holds only B's memory
Retrieval index An indexed document with a canary Query with a near-match of the canary's words Returned chunk IDs belong only to B's partition
Caches Warm each cache with A's request Send B the identical and a near-identical request B's answer is built from B's data; cache keys include the user or tenant
Tool calls A record with a canary Make the model call a tool with A's record ID The tool rejects it from the session identity
Background work A queued summary or export B acts while A's job runs and after it ends Output lands only in A's space
Logs and exports A request with a canary Open B's dashboards and exports B never sees A's entries
Revocation A deleted item or removed member Retry with the old identity Nothing remains reachable, including index and cache copies

Code-drawn diagram of the two-account test: account A seeds a canary into messages, files, memory, the index and a cache; account B probes each surface; a check below the model asserts that no canary reaches B, with a positive control confirming that A can still see its own data.

Object IDs: the model is a caller, not an authority

OWASP's access control category lists "Permitting viewing or editing someone else's account by providing its unique identifier (insecure direct object references)" among common failures. Its prevention advice includes "Except for public resources, deny by default" and "Model access controls should enforce record ownership rather than allowing users to create, read, update, or delete any record" [2]. The API-specific entry puts it as a rule for every endpoint: "Every API endpoint that receives an ID of an object, and performs any action on the object, should implement object-level authorization checks" [3]. Comparing the session's user ID with the ID in the request "isn't a sufficient solution" on its own [3].

An AI chat adds a new caller. When the model emits a tool call such as "open note 812", the identifier came from generated text, which anything in the context may have influenced. Treat it as an untrusted client parameter. This is my reading of the OWASP rule applied to model output, not a statement from those pages: the tool code should check that the note belongs to the signed-in user, taken from the session, not from anything the model wrote.

The test follows. As B, make the model request A's object, by naming A's ID in the chat or by calling the tool in a harness with A's ID and B's session. A pass is a denial from the tool code that looks the same as the response for an object that does not exist, so B learns nothing about what A has.

Retrieval and storage partitions

OWASP's page on vector and embedding weaknesses describes the failure for retrieval: "In multi-tenant environments where multiple classes of users or applications share the same vector database, there’s a risk of context leakage between users or queries" [4]. Its mitigations include "permission-aware vector and embedding stores", "strict logical and access partitioning of datasets", and "detailed immutable logs of retrieval activities" [4]. The last one matters for testing: retrieval logs make it possible to assert which chunks were fetched.

Each partitioning design moves the thing to test. Pinecone's documentation, for example, describes one namespace per tenant, with every read and write targeting one namespace, and says this "reduces the risk of application bugs that could search the wrong tenant’s data" [5]. That is a vendor's description of its own design. It leaves a question for your tests: does your code pass the right namespace on every call, including the background job's and the cache warm-up's?

The database side has its own trap. PostgreSQL's row security documentation says that when row security is enabled and no policy exists, "a default-deny policy is used", which is a good default [6]. It also says that "Superusers and roles with the BYPASSRLS attribute always bypass the row security system", and that table owners normally bypass it too [6]. A test that connects as a superuser, as a role with BYPASSRLS, or as the table owner (unless the table has FORCE ROW LEVEL SECURITY) says little about the policy: those roles bypass row security, so the run can pass while the policy that applies to the application's role is broken. Run isolation tests with the role the application uses at runtime, and check that this role is not a superuser, lacks BYPASSRLS and is not the table owner. The page's general principle fits this whole article: "it's important to test and ensure that the system is behaving as expected" [6].

Caches: what the documentation says and what it cannot say

Providers document their prompt-cache boundaries. Anthropic says: "Different organizations never share caches, even if they use identical prompts", adds isolation between workspaces on some platforms, and states that "Cache hits require 100 percent identical prompt segments" [7]. It also says the response with caching is "identical to what you would get if prompt caching were not used" [7]. OpenAI says: "Caches are not shared across organizations", and that "Keys influence routing; they do not pin requests to a machine or guarantee a cache hit" [8]. Its prompt_cache_key can also keep cache accounting separate per customer or user, and the page says separate keys "help prevent cache-hit probing across users" [8]. That is a useful setting, but it is applied by your code on each request, so it belongs in your tests rather than replacing them.

A research paper adds the other side. Its abstract reports that prompt caching creates timing differences, that "if the cache is shared across users, an attacker could identify cached prompts from fast API response times to learn information about other users' prompts", and that the authors "detect global cache sharing across users in seven API providers, including OpenAI" [9]. This is a 2025 audit of provider behaviour at that time (version 2 dated 13 July 2025), read here only as an abstract.

For your product this is a division of labour, and the author's reading rather than a statement from the providers. In the usual setup your end users share your organization's provider account, so the providers' statements describe the line between their customers, not between your user A and your user B. Any cache you build yourself, such as a response cache, a semantic cache that matches similar questions, or a memoized tool result, is yours to test. The rule to check: the cache key must include whatever decides who may see the entry, and nothing built from one user's data may be returned for another's request.

A fictional example

The following example is invented. Example Notes is a made-up product: a notes app with an AI assistant that answers questions about a user's own notes. Ana and Ben are fictional users in different workspaces, and the bug is fictional too.

The first release has an isolation suite built on the matrix above. As Ana, it stores a note containing BLUE-HERON-4471. As Ben, it asks "Summarize my open notes", checks that the retrieved chunk IDs belong to Ben's namespace and that the assembled prompt does not contain the canary. A positive control confirms that Ana's own query finds her note. All checks pass.

Two weeks later the team adds a response cache to cut waiting time, keyed by a hash of the normalized question text. The release passes its functional tests. The isolation suite, which runs on every change to prompt assembly, retrieval or caching, fails on the cache row: Ana's request warms the cache with "Summarize my open notes", and Ben's identical question returns Ana's summary, canary included. Retrieval and prompt were correct; the bug sat in a later layer.

The fix adds workspace and user to the cache key, plus a test that sends the same question as two users and asserts different, correctly scoped answers.

Code-drawn diagram of the fictional Example Notes bug: Ana's question warms a response cache keyed only by question text; Ben's identical question hits that entry and receives Ana's summary; a second panel shows the fixed key, which includes workspace and user, so Ben misses and gets his own answer.

Keeping the tests useful

  • Run them on every change to the layers around the model: prompt assembly, retrieval, caching, memory, tool code, database roles and migrations.
  • Keep the data fictional and the environment separate. A test tenant with canary strings should never hold real user content.
  • Test deletion. Removing a conversation or a member should remove or invalidate copies in the index and caches; delete as A, then probe as B and with A's old session.
  • Test the background path. Identity should be captured when a job is queued; interleave two users' jobs and check where each output lands.
  • Block the release on a failing row. One user's data reaching another is a different kind of defect from a poor answer.

What this article cannot tell you

A passing suite shows that its scenarios did not leak, not that no path leaks. The matrix is a proposal, not a standard, and no source read here measured how often real products fail each row. The article does not cover determined adversaries, side channels beyond the one study cited, legal obligations for your data and region, or incident response after a leak. The provider documentation describes those services as written on the pages read and can change; none of it describes your own caches. The Pinecone page is a vendor's description of its own design, the caching paper was read as an abstract only, and the example is invented. The author has not run these tests against a product for this article: the method is assembled from the cited guidance and the author's own reasoning, marked where it appears.

How this article was made

Task What the AI did What a person did How it was checked
Research Gathered candidate sources and drafted notes Chose the question and which pages to rely on Every quote checked against the raw page text, read on 2 December 2026
Draft Wrote the first draft from the notes Edited the text, the test matrix and the example An independent review compares claims with the sources before publication
Images Generated the cover; wrote the code that draws the two diagrams Chose and checked them Labelled in the disclosure line and alt text
Not done by AI — The decision to publish and responsibility for the text —

Conflicts of interest: none. The author has no commercial relationship with the organisations or vendors named here.

Responsible for this article: Dmitriy Lastovka, author. Corrections: contact form.

Sources

Labels: standard (a published security framework), documentation (a vendor's or project's own documentation), research (a preprint or paper abstract). Quotes are as on the pages read on 2 December 2026.

  1. OWASP GenAI Security Project, LLM02:2025 Sensitive Information Disclosure. https://genai.owasp.org/llmrisk/llm022025-sensitive-information-disclosure/ Standard.
  2. OWASP Top 10:2025, A01 Broken Access Control. https://owasp.org/Top10/2025/A01_2025-Broken_Access_Control/ Standard.
  3. OWASP API Security Top 10, API1:2023 Broken Object Level Authorization. https://owasp.org/API-Security/editions/2023/en/0xa1-broken-object-level-authorization/ Standard.
  4. OWASP GenAI Security Project, LLM08:2025 Vector and Embedding Weaknesses. https://genai.owasp.org/llmrisk/llm082025-vector-and-embedding-weaknesses/ Standard.
  5. Pinecone, "Implement multitenancy". https://docs.pinecone.io/guides/index-data/implement-multitenancy Documentation; a vendor's description of its own product.
  6. PostgreSQL documentation, current release (19), 5.10 Row Security Policies. https://www.postgresql.org/docs/current/ddl-rowsecurity.html Documentation.
  7. Anthropic, prompt caching documentation, section "Cache storage and sharing". https://platform.claude.com/docs/en/build-with-claude/prompt-caching Documentation; no revision date on the page.
  8. OpenAI, prompt caching guide. https://platform.openai.com/docs/guides/prompt-caching Documentation; no revision date on the page.
  9. Gu, Li, Kuditipudi, Liang, Hashimoto, "Auditing Prompt Caching in Language Model APIs", arXiv:2502.07776 (v2, 13 July 2025; the page states acceptance at ICML 2025). https://arxiv.org/abs/2502.07776 Research; abstract page only.

Tier I

Sector: #18291

Sealed Hiding Place Room

Resource Cache

Resource Cache

Tier I

Requires 25% Tier Progress to Claim
Meme Cache

Meme Cache

Tier I

Requires 50% Tier Progress to Claim
Equipment Cache

Equipment Cache

Tier I

Requires 75% Tier Progress to Claim

After collecting, hiding places will be stored in your inventory and can be opened with Keys.

Other articles

Keeping Private Data Out of AI Context and Logs

Where a chat message gets copied, what to strip before it reaches the model, what logs should not hold, and a canary test to check it.

user avatarme1afon

Validating Model Output Before an Action

Where to check an AI reply before it acts: in code, at a boundary beside each executor, with checks set by the destination. A fictional order bot and a test.

user avatarme1afon

Giving an Agent Only the Access It Needs

How to limit what an AI agent can do through its tools: fewer tools, narrower functions, scoped credentials, user context and approvals. A fictional example.

user avatarme1afon

When Retrieved Text Tries to Become an Instruction

Why text an AI agent reads from a document cannot be treated as a command, what OWASP and the research say, and a checkable rule for your own chat.

user avatarme1afon

Teaching a Chat to Say It Does Not Know

When a chat should decline to answer: four kinds of no-answer, what research says models do instead, a fictional help-chat example and a test plan.

user avatarme1afon

Handling Stale and Conflicting Sources

Two retrieved passages give different numbers. Name the kind of disagreement, apply a rule written in advance, and show the dates.

user avatarme1afon

Important disclaimer: The information presented on the Dapp.Expert portal is intended solely for informational purposes and does not constitute an investment recommendation or a guide to action in the field of cryptocurrencies. The Dapp.Expert team is not responsible for any potential losses or missed profits associated with the use of materials published on the site. Before making investment decisions in cryptocurrencies, we recommend consulting a qualified financial advisor.