You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Responses that are never stored:** a response is kept out of every cache unless it is a `200 OK` that hands out no
206
+
cookies (the culture cookie is exempt, since the cache varies by culture anyway). That keeps a 404 for a product created
207
+
a minute later from surviving on the edge for days, and keeps one caller's cookies from being replayed to everybody else.
208
+
This is enforced twice - by an `OnStarting` callback that downgrades `Cache-Control` to `no-store, private` for browsers
209
+
and CDNs, and by clearing `AllowCacheStorage` in `ServeResponseAsync` for the output cache.
210
+
211
+
**Telling shared caches what to vary on:**
212
+
213
+
The output cache keys on `Origin` and `X-Origin`, so the response advertises them too:
214
+
215
+
```
216
+
Vary: Origin, X-Origin
217
+
```
218
+
219
+
-`Origin` - the CORS middleware runs before the output cache middleware and echoes the caller's origin into
220
+
`Access-Control-Allow-Origin`. Without the vary, the first caller's value would be replayed to every other origin and
221
+
their browsers would reject it.
222
+
-`X-Origin` - the header a Blazor Hybrid / standalone WASM client sends to tell the backend which web app url it is
223
+
running under (See `HttpRequestExtensions.GetWebAppUrl`), which can end up embedded in the response.
224
+
225
+
> **A CDN may ignore `Vary`.** Cloudflare does not consider it in caching decisions unless the header is
226
+
> `Accept-Encoding`, or a **Cache Rules → Vary** setting naming `origin` / `x-origin` has been configured on the zone.
227
+
> Without that rule the edge keeps a single variant per URL and hands it to callers of every origin. Configure it before
228
+
> turning `EnableCdnEdgeCaching` on.
229
+
189
230
**Important Security Note:**
190
231
191
232
The `UserAgnostic` property is critical for security. If a response contains user-specific data (e.g., user's name, roles, or tenant information), it **must not** be cached in shared caches (CDN edge or output cache). Setting `UserAgnostic = true` is only safe when the response is identical for all users.
192
233
234
+
> **Multi-tenant + CDN edge:** the `Tenant` discriminator above is part of the **ASP.NET Core output cache key only** -
235
+
> `VaryByValues` never becomes a response header, so a CDN cannot see it. The output cache therefore keeps tenants apart
236
+
> correctly, but an edge cache keyed on host + path does not. Until the tenant is part of the URL or the host, treat
237
+
> `UserAgnostic = true` together with `EnableCdnEdgeCaching` as unsafe for any response whose body is tenant-filtered.
238
+
193
239
---
194
240
195
241
### 3. ResponseCacheService
@@ -215,10 +261,10 @@ public partial class ResponseCacheService
Copy file name to clipboardExpand all lines: src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Infrastructure/Services/HttpMessageHandlers/CacheDelegatingHandler.cs
Copy file name to clipboardExpand all lines: src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/IdentityController.ExternalSignIn.cs
+5-1Lines changed: 5 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,12 @@ public partial class IdentityController
0 commit comments