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

+15 -4
View File
@@ -9,17 +9,28 @@ The **Static & diagnostics** subtab provides **Ignore request cookies for static
**Safety requirement:** use both options only when the complete static response (body **and headers**) is identical for all visitors regardless of Cookie. `Vary: Cookie` is a declaration that content may vary, so overriding it on a genuinely session-dependent file can expose one user's cached variant to another. RustProxy applies this override only to responses with an explicit `Cache-Control: public` directive, positive remaining freshness (without mandatory revalidation) and no `Set-Cookie`, `private`, `no-store` or invalid Vary. A zero-TTL response, including `public` with no configured fallback TTL, retains `Vary: Cookie` even if it can be stored for later revalidation. If the response is not cacheable, `Vary: Cookie` is passed through unchanged. Do not enable this optimization for user-specific downloads, generated PDFs, account JSON, or any path where Flask or another origin changes content according to a session cookie; prefer removing the needless `Vary: Cookie` at the origin where possible.
### Ready-made quick rules library
The **Add from template** dropdown is grouped by scenario. **Browse scenarios** opens a searchable panel with descriptions and one-click **Add** buttons for ready-made request, response and delivery rules. The library includes common application sessions, WordPress/WooCommerce, Django, Laravel, Auth.js, API and private routes, SSE/webhooks, TTL for verified public content and defensive headers. Some scenarios add multiple rules. Templates with a risk of unexpected shared-cache reuse are **disabled until reviewed**. The CDN and exact-name parent-domain cookie templates stay separate. See [Quick rules template library](CACHE_TEMPLATE_LIBRARY.md) for categories, order, defaults and tests. Adding rules changes the draft; save settings before relying on them.
### CDN security cookies (opt-in VCL template)
The cache rules template menu now includes **CDN technical cookies** for Cloudflare (`__cf_bm`, `cf_clearance`, `_cfuvid`, `__cfruid`, `__cfseq`) and Akamai (`_abck`, `ak_bmsc`, `bm_sz`, `bm_sv`). It bypasses non-GET/HEAD methods, restricted application paths and `Authorization`. It strips the entire Cookie header **only if all Cookie fields contain allowlisted technical cookies**, and bypasses any request with a remaining Cookie (for example `session`, `wordpress_logged_in_*`, CSRF tokens or other personalized cookies). The source equivalent is [`examples/vcl/cdn-technical-cookies.vcl`](../examples/vcl/cdn-technical-cookies.vcl). Import it only after reviewing warnings; enable the graphical template only on tested public Vhosts. Some challenge cookies (especially `cf_clearance`, `_abck` and `ak_bmsc`) are important to specific origin/CDN configurations; removing them can break a challenge flow. **This is not turned on automatically for existing Vhosts.**
### Inherited cookies on public Vhosts (opt-in, disabled by default)
### Parent-domain cookies: opt-in per-Vhost name filtering
A parent domain may set `Set-Cookie: name=value; Domain=.example.test`, causing browsers to send it to *all* subdomains. A received `Cookie` header contains only names and values: RustProxy **cannot determine the source Domain** or whether a cookie was set by the current subdomain. The preferred fix is to make the cookie host-only at the issuing application (omit `Domain`), if it is not meant for sibling hosts.
A parent domain may set `Set-Cookie: name=value; Domain=.example.test`, making browsers send it to subdomains. The incoming `Cookie` header **does not include the Domain attribute**: RustProxy cannot distinguish the parent cookie from a cookie with the same name set by this Vhost. Prefer configuring host-only cookies (omit `Domain`) at the issuing application.
For a subdomain that serves **exclusively public, cookie-independent GET/HEAD pages**, the Vhost **Cache rules → Add from template → Public vhost: ignore inherited cookies** template is available. It is deliberately **disabled when added**, absent from the global template menu, and must be reviewed before enabling. The template strips **all incoming request cookies** before lookup **and** before forwarding to the origin, only for GET/HEAD with Cookie, without `Authorization`, and outside its conservative private-path exclusion regex. The path regex is only an example; adapt it to the application. Do not use on logged-in pages, language/session-dependent pages, checkout, downloads, CSRF or custom authenticated paths. A public page must return identical body and headers regardless of Cookie; otherwise do not enable the rule. The independently importable VCL equivalent is [`examples/vcl/public-vhost-ignore-cookies.vcl`](../examples/vcl/public-vhost-ignore-cookies.vcl).
Two **separate** opt-in templates remain available in the Vhost cache-rule editor:
This rule does not remove an origin `Vary: Cookie` header. Since Cookie has been removed from the request before lookup and the backend fetch, all eligible requests compare the **absent** Cookie variant. RustProxy still requires normal response eligibility: `Cache-Control` privacy, `Set-Cookie`, response `Vary`, authentication and route checks remain active. If the origin emits an unnecessary `Vary: Cookie` for a truly public page, correct it at the origin rather than unsetting all `Vary` in a deliver-stage rule. Avoid installing the new template *after* a same-scope early `pass` rule for Cookie: stop/return prevents later rules running. Prefer the **per-Vhost editor** and verify `X-Cache-Reason` with a real browser Cookie before rollout.
1. **Vhost: remove selected parent-domain cookies** (inserted **disabled**): the operator supplies an exact comma-separated list of **non-session** cookie names in the `Remove only named cookies` action, replacing `REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME`. Only those names are removed from incoming GET/HEAD requests; every other cookie, including the application's session, stays intact. The rule has **no** `return(hash)` and **does not stop** subsequent cache rules. It excludes Authorization and example private paths; review the path list for your application. The example is [`examples/vcl/public-vhost-remove-parent-cookies.vcl`](../examples/vcl/public-vhost-remove-parent-cookies.vcl).
2. **CDN technical cookies** (independent, unchanged): its safe-method/private-path/Authorization guards, its anchored whole-header CDN cookie allowlist and **CDN: bypass remaining cookies** continue to run after parent cookie removal. It never treats a remaining session cookie as a CDN cookie. See [`examples/vcl/cdn-technical-cookies.vcl`](../examples/vcl/cdn-technical-cookies.vcl).
**Order:** place the parent-name rule **above** `CDN: remove ONLY technical cookies` and especially **above** `CDN: bypass remaining cookies`; leave the CDN guard rules active at the top. **Delete/disable any old `Public vhost: ignore inherited cookies` rule that uses `strip_cookies: keep=[]` + `lookup`**. Updating the binary does not remove existing saved rules. Never add an application session cookie, login token, CSRF token, locale/personalization cookie or sticky-session identifier to the parent-name list. Do not wildcard cookie names. If the same cookie name can belong to the parent **and** this application, use host-only cookies at the issuer instead of the removal rule.
Resulting request behavior on public pages: `Cookie: parent_marketing=1` (listed) → stripped → cache eligible; `Cookie: parent_marketing=1; __cf_bm=2` → parent removed by this rule, then CDN removed by its separate template → eligible; `Cookie: parent_marketing=1; app_session=abc` → only parent removed, session retained → CDN remaining-cookie rule **BYPASS**; POST, Authorization and private paths are not rewritten by the new template. Verify each using **Cache rule tester** and live `X-Cache-Reason` headers. Responses with `Set-Cookie`, `private` or `no-store` still cannot enter shared storage. The origin's `Vary: Cookie` stays intact and is evaluated against the **remaining** Cookie value. Configure logged-in origin responses as `private, no-store` as defense in depth.
The import syntax `remove_req_cookies("name1", "name2");` is a **RustProxy-specific VCL extension**, not stock Varnish syntax. It performs exact, case-sensitive name matching, preserves other cookies, and refuses to rewrite malformed Cookie fields. A graphical `Remove only named cookies` action uses the same implementation. This new action is not the dangerous `Strip cookies` / "keep" operation, which can remove other cookies.
**Do not extend** `Ignore Vary: Cookie for public static assets` to a general "Ignore Vary" control. `Accept-Encoding`, `Accept-Language`, `Accept`, `Origin`, `User-Agent` and custom response-specific dimensions can change bytes, permissions or CORS headers. Keep the response's actual dimensions and use the existing safe normalization of recognized list fields below, or remove an unnecessary `Vary` at the origin only after proving the response is invariant. A VCL `unset beresp.http.Vary` is *possible*, but it is not the equivalent of a guarded static-file optimization.