This commit is contained in:
Mateusz Gruszczyński committed 2026-11-20 20:54:40 +01:00
1 parent 53d92e0da6
commit 08d1608ef5
21 files changed
+928 -408

No files matched your search

+25 -24
View File
@@ -31,8 +31,8 @@ Read together with [VCL compatibility](VCL.md) and the [supported/unsupported ca
| CMS articles or a public catalog | [Public catalog](#2-public-catalog-with-explicit-short-ttl) | Cache genuinely shared 200 GETs, set TTL/grace | Force storage of `private`, `Set-Cookie` or 404 |
| Public JSON endpoint for prices/stock | [Public JSON API](#3-public-get-json-api) | Short-lived shared cache | Cache credentialed/private API responses |
| Admin, login, checkout, user dashboard | [Private routes](#1-exclude-private-routes-and-unsafe-methods) | Bypass shared cache | Replace ACL, OIDC, Basic Auth, app permissions |
| Cookies inherited from a parent domain on a **fully public** Vhost | [Public Vhost inherited cookies](#12-public-vhost-inherited-cookies-opt-in) | Remove **all** Cookie for eligible GET/HEAD after operator review | Detect which cookies came from a parent domain; guarantee safe login/personalization routes |
| Cloudflare/Akamai technical cookies | [CDN cookie allowlist](#4-cdn-technical-cookies-without-dropping-sessions) | Strip an **entire** allowlisted Cookie header | Partially delete one Cookie from a mixed list |
| Cookies set broadly by a parent domain | [Selective parent cookie removal](#12-parent-domain-cookies-remove-selected-names-opt-in) | Remove only **verified exact cookie names**, leaving application sessions intact | Infer which Domain set them; safely delete an overlapping session cookie name |
| Cloudflare/Akamai technical cookies | [CDN cookie allowlist](#4-cdn-technical-cookies-without-dropping-sessions) | Strip an **entire** CDN-only Cookie header; separate from parent cookie rule | Treat unknown or session cookies as CDN cookies |
| Public CSS, JS, fonts, images | [Static assets](#5-static-assets-and-vary-cookie) + native static settings | Strip request Cookie if proven safe; optional **conditional** `Vary: Cookie` treatment | Override any other arbitrary `Vary` dimension |
| Multilingual catalog | [Language variants](#6-language-specific-representations) | Preserve origin `Vary: Accept-Language` and separate variants | Automatically translate or change language |
| Low-cardinality public A/B content | [A/B variants](#7-low-cardinality-public-ab-variants) | Add internal header dimension via `vcl_hash` | Write `Vary` for downstream caches |
@@ -403,38 +403,37 @@ sub vcl_backend_response {
}
```
### 12. Public Vhost: inherited cookies (opt-in)
### 12. Parent-domain cookies: remove selected names (opt-in)
**Goal:** Keep cache working on a completely public site when a browser includes unrelated cookies set with `Domain=.example.test` by another host. This is generic for any hostname; **it cannot detect the cookie's original Domain**, which is not part of the HTTP `Cookie` request header.
**Goal:** A subdomain receives an unrelated, verified cookie set by a parent domain. Remove only this cookie's *name*, keeping any session/CSRF/authentication cookies for later `BYPASS` rules. The HTTP Cookie request header **does not identify the issuing Domain**. The recommended long-term fix is a host-only `Set-Cookie` at the issuing app.
**Expected traffic:** `GET /catalog`, `Cookie: parent_session=x; analytics=y` → Cookie stripped before cache lookup and before origin forwarding. The origin serves its anonymous public representation; an eligible repeat GET may HIT. `GET /account` or a request with `Authorization` keeps its cookies and follows normal bypass/auth policies. POST is unaffected.
**Expected traffic:** `GET /catalog` with `parent_marketing=1; app_session=abc` → remove `parent_marketing`, preserve `app_session`, and then the separate CDN **remaining cookies** rule causes `BYPASS`. With only `parent_marketing=1`, RustProxy may cache eligible anonymous content. With `parent_marketing=1; __cf_bm=2`, the parent rule removes the first and the separate CDN rule removes the second; this allows normal cache lookup. POST, protected paths and Authorization are unaffected.
**Prerequisites:** Use the per-Vhost cache rule editor, confirm that the *entire eligible area* is public for guests and logged-in users, and extend the excluded path regex to cover **all** private routes of the application. The graphical template is **disabled by default** until manually enabled. Avoid installing it globally or after existing terminal Cookie `pass` rules. The safest fix is often to remove the broad `Domain` attribute from `Set-Cookie` at the issuing application so browsers no longer send unrelated cookies to siblings.
**Prerequisites:** On the Vhost, add **Vhost: remove selected parent-domain cookies**, replace `REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME` with the actual verified cookie names in **Remove only named cookies**, review sensitive paths, then enable. Keep the CDN template as its **own group of rules**, with this new rule above `CDN: remove ONLY technical cookies` and `CDN: bypass remaining cookies`. Do not enable a previous **ignore ALL inherited cookies** rule: it could strip login sessions and force cache lookup. Removing that old rule from existing saved configurations is manual.
**Caveat:** This deliberately removes **every** cookie on the allowed public pages, not just analytics or inherited cookies. It can break logins, preferences, locale choice, cart, stickiness or security challenge behavior, and may serve anonymous content to a logged-in user. Never apply it to personalized content. It does not rewrite origin `Vary: Cookie`, `Set-Cookie` or `Cache-Control` and does not bypass RustProxy response privacy checks. Use [`docs/CACHE.md`](CACHE.md#inherited-cookies-on-public-vhosts-opt-in-disabled-by-default) for configuration and risk details.
**Caveat:** A cookie name may be shared by both the parent and the application; if so, do not strip it by name. This is a RustProxy-specific VCL extension rather than standard Varnish VCL. Origin privacy guards, `Set-Cookie`, and `Vary` remain active. See [Cache](CACHE.md#parent-domain-cookies-opt-in-per-vhost-name-filtering).
Source: [`examples/vcl/public-vhost-ignore-cookies.vcl`](../examples/vcl/public-vhost-ignore-cookies.vcl).
Source: [`examples/vcl/public-vhost-remove-parent-cookies.vcl`](../examples/vcl/public-vhost-remove-parent-cookies.vcl).
```vcl
// OPT-IN: use ONLY on an HTTP reverse-proxy Vhost with fully public,
// cookie-independent GET/HEAD content. Import into that Vhost, NOT globally.
// Useful when a parent domain sets Domain=.example.test cookies that a public
// sibling subdomain neither needs nor should forward to the backend.
// Opt-in Vhost-only rule, SEPARATE from the CDN technical-cookie template.
// RustProxy VCL extension: remove_req_cookies() is NOT standard Varnish VCL.
// Replace REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME with exact, verified names
// that this Vhost NEVER uses for login, user state, language, cart, etc.
// Cookie headers do NOT reveal Domain; a name may also belong to this Vhost.
// Never list a session cookie that could be valid for this Vhost.
//
// Cookie does not include the cookie's Domain attribute. It is IMPOSSIBLE
// to distinguish inherited cookies from host-only cookies in vcl_recv.
// This deliberately strips ALL cookies on permitted public paths; verify
// that users do not need login, preferences, locale, cart or affinity there.
// Customize the excluded path list to fit your application before enabling.
// Backend must return an eligible PUBLIC response (no private/no-store or
// Set-Cookie); this does not override response cache privacy or Vary.
// Install ABOVE "CDN: remove ONLY technical cookies" and
// "CDN: bypass remaining cookies", which must stay as separate rules.
// DO NOT use the old strip-all inherited-cookie rule in parallel.
// This rule has no return(hash): remaining cookies and sessions still pass
// through the CDN/normal cache safety checks.
sub vcl_recv {
if ((req.method == "GET" || req.method == "HEAD") &&
req.http.Cookie &&
!req.http.Authorization &&
req.url !~ "^/(admin|api|auth|login|logout|account|profile|user|settings|dashboard|cart|checkout|panel|konto|wp-admin|wp-login[.]php)(/|[?]|$)") {
unset req.http.Cookie;
return(hash);
remove_req_cookies("REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME");
}
}
```
@@ -460,9 +459,11 @@ The outcomes below describe **decision paths**, not a guaranteed X-Cache label:
| `Cookie: __cf_bm=a; cf_clearance=b` | CDN cookie allowlist | Strip whole Cookie header | Only exact allowlisted cookie names pass. |
| `Cookie: __cf_bm=a; session=b` | CDN cookie allowlist | PASS | Even one non-allowlisted name prevents removal. |
| Two physical Cookie fields, one technical and one session | CDN cookie allowlist | PASS | Patched matcher examines combined cookie values. |
| `GET /catalog`, Cookie from parent domain | Public-Vhost opt-in | Strip all Cookie; eligible | Only on verified cookie-independent pages with reviewed exclusions. |
| `GET /account`, parent-domain Cookie | Public-Vhost opt-in | Ordinary bypass/auth rules | Protected-path guard leaves Cookie untouched. |
| `GET /catalog`, Cookie plus Authorization | Public-Vhost opt-in | Native auth/bypass | The template does not remove Cookie with Authorization. |
| `GET /catalog`, `parent_marketing=a` (listed) | Parent-name template | Remove only listed cookie; eligible | The operator must verify the name is not used for app sessions. |
| `parent_marketing=a; __cf_bm=b` | Parent-name + separate CDN templates | Both removed in order; eligible | Keep the parent rule before the CDN remaining-cookie bypass. |
| `parent_marketing=a; app_session=b` | Parent-name + separate CDN templates | Preserve `app_session`; BYPASS | Never force lookup for remaining unknown/session cookies. |
| `GET /account`, parent-domain Cookie | Parent-name template | Ordinary bypass/auth rules | Protected-path guard leaves Cookie untouched. |
| `GET /catalog`, Cookie plus Authorization | Parent-name template | Native auth/bypass | The template does not remove Cookie with Authorization. |
| `GET /assets/site.css`, arbitrary Cookie | Public static | Strip Cookie **if verified safe** | Separate native `Vary: Cookie` setting has additional conditions. |
| `GET /assets/user-avatar.png`, Cookie | Do **not** use static bypass | PASS recommended | Do not remove session personalization merely due to extension. |
| `GET /experiment`, `X-Experiment: A` | A/B variants | Eligible A partition | Origin must emit downstream `Vary: X-Experiment`. |