Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
AI

The AI Prompt That Checks Whether a Caching Layer Can Return Another Tenant’s Data Because the Cache Key Omits the Tenant ID

- 30.10.26 - ErcanOPAK

🤖 The AI Prompt That Checks Whether a Caching Layer Can Return Another Tenant’s Data Because the Cache Key Omits the Tenant ID

Caching code gets reviewed for hit rate and invalidation logic far more often than for whether its cache key actually isolates one tenant’s data from another’s in a multi-tenant system. A key built only from a resource ID — without the tenant, account, or organization ID folded in — can return Tenant A’s cached result to Tenant B simply because they both happened to request a resource with the same ID in their own separate data sets. This prompt isolates that one question so it never gets skipped in a general code review.

🔎 The Prompt

You are reviewing caching code in a multi-tenant application
where each tenant's data must stay fully isolated from every
other tenant's.

For the caching code below, answer only these questions:

1. What exact fields make up the cache key for each cached
   value? Quote the key construction code or format string.
2. Does the cache key include the tenant, account, or
   organization identifier? If not, could two different
   tenants ever produce the same key for logically different
   data (e.g. both have a "resource ID 42")?
3. Is the tenant identifier used to build the key read from a
   trusted source (an authenticated session/claim) or from
   something the caller supplies directly (a query parameter,
   a request body field)?
4. If the cache is shared infrastructure (a shared Redis
   instance, a shared in-memory cache across requests), confirm
   there is no code path that could read a key before confirming
   which tenant is making the current request.

--- CACHING CODE ---
<paste the cache read/write code, including key construction></paste>

✅ What This Prompt Catches

  • A cache key built from just a resource ID (`”product:42″`) in a system where every tenant has its own independent product catalog, so Tenant B’s request for their own product 42 can be served Tenant A’s cached result the moment both IDs happen to collide.
  • A tenant ID that IS included in the key, but is read from a request header or query parameter the client controls rather than from the authenticated session — letting a malicious caller simply supply a different tenant ID to probe another tenant’s cached data directly.
  • A cache populated by a background job that runs without per-tenant context at all, writing a key that no per-request tenant check was ever applied to in the first place.

🚨 Why This Is Dangerous

  • This prompt only evaluates the key construction logic you paste in — it can’t verify that every single call site in a large codebase builds the key the same safe way, so grep for every place that reads from or writes to this cache before concluding the whole system is isolated.

A cache key that forgets the tenant isn’t a performance bug waiting to happen — it’s a data breach waiting for two tenants to ask for the same resource ID on the same day.

— AI Power User

Related posts:

AI Prompt: Generate Regex Patterns from Examples

AI Prompt: Generate Regex Patterns from Examples

The AI Prompt That Reviews Your Database Connection Pool Settings for Exhaustion Risk Under Real Tra...

The AI Prompt That Reviews Your Database Connection Pool Settings for Exhaustion Risk Under Real Tra...

Generate Unit Tests with AI

Generate Unit Tests with AI

Views: 8

Post navigation

SQL Server: Fix a Trigger Silently Not Firing on a Bulk Insert Because the Bulk Copy Operation Was Run With FIRE_TRIGGERS Left Off
Photoshop: Fix a Pattern Overlay Looking Blurry at Export Because Its Scale Was Set Relative to a Downsampled Preview

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com