This commit is contained in:
Mateusz Gruszczyński committed 2026-11-20 19:51:27 +01:00
1 parent 15425fb803
commit 0fc9c0d239
21 files changed
+395 -36

No files matched your search

+16
View File
@@ -13,6 +13,14 @@ The **Static & diagnostics** subtab provides **Ignore request cookies for static
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)
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.
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).
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.
**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.
## `Vary` matching (RFC 9111 §4.1)
@@ -152,6 +160,14 @@ done
Look for cache reason labels including `request_cookie`, `request_authorization`, `response_cache_control`, `route_disabled` and `cache_hit` when diagnostic headers are enabled. A `MISS` alone does not prove the object was admitted to HOT/COLD.
### Browser differs from curl (HTML, cookies, reloads)
Compare **two consecutive normal GET navigations** to exactly the same URL and inspect **Network → request headers** and **response headers** in the browser. Use `X-Cache-Reason` to distinguish `request_cookie` (BYPASS) from `request_no_cache` / `request_max_age` (revalidation) and from `cache_miss` (no matching stored variant). A browser may send session/analytics cookies absent from a plain curl request. `Vary: Cookie` is an explicit instruction to partition cached representations by the complete incoming Cookie header; a VCL rule stripping *approved technical cookies* from the request does not remove application cookies or automatically suppress `Vary: Cookie` for HTML. Do not remove the latter or strip session cookies unless the application guarantees that both headers and body are identical for every visitor.
For a faithful command-line comparison, use **Copy as cURL** for a browser request and repeat the resulting command without changing its Cookie, `Accept-Encoding`, URL or request cache directives. Then test a second invocation with only irrelevant technical cookies omitted, if appropriate. Different compression/`Vary` representations may each have their own initial MISS. For manual reloads, check **Disable cache** in DevTools and `Cache-Control`/`Pragma` on the *request*. With the default `varnish_compatible=true`, only the supported reload directives are ignored for fresh lookup; `no-store`, Cookie bypass and credential policy are not ignored.
An eligible uncached `HEAD` is forwarded upstream as `GET` and can populate the same cache entry as a future GET. RustProxy returns the HEAD headers and drains the fetched body **without delivering it to the HEAD client**; the fill is asynchronous and bounded by the configured cache object size and a 30-second deadline. A GET requested before this fill has completed may still show MISS or wait for the in-flight fill; if the body exceeds the size/deadline or fails, no object is stored. HEAD responses to requests which bypass the cache are **not** drained by this mechanism.
### In-panel cache and VCL guide
Click **Cache & VCL guide** in **Settings → Cache**, **Vhosts → Cache** or a Docker service's **Cache** editor for the same interactive modal. The example-insertion target is the **editor that opened the modal** (global, ordinary vhost or Docker vhost), not always the global rules. The context badge identifies the destination, and the scope note explains which rules/settings are inherited and which are local. Opening the guide from a vhost does not save or modify global rules. It shows the **current form values** for compatibility mode, fallback TTL and grace, including a warning if the cache is disabled. The form may have unsaved changes; the modal does not apply settings. Example VCL snippets explain how `Cookie`, `Vary`, safe `req.http.*`, `beresp.http.*`, `resp.http.*`, `beresp.uncacheable = false` and `return(hash)` affect cache decisions. The **Insert into VCL importer** buttons copy a starting snippet into that editor's Rules import textarea (without importing or saving the rule) and invalidate older import previews; warnings now require explicit approval of a partial import. The guide warns that only 200 responses can be stored, and that VCL export is an approximate view. Validate the rule tester before saving. The modal explicitly lists unsupported VCL hooks and includes a short HIT/MISS/BYPASS checklist. For complete syntax, use [VCL import](VCL.md).