From d455028de325e029cb1dee251437c46e8118926e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 20 Nov 2026 21:56:12 +0100 Subject: [PATCH] v0.39.1 --- CHANGELOG.md | 2 + SHA256SUMS | 30 +++--- docs/CACHE.md | 8 +- docs/CACHE_TEMPLATE_LIBRARY.md | 4 +- docs/FEATURES.md | 2 +- docs/README.md | 2 +- docs/VCL.md | 6 +- docs/VCL_SUPPORT_MATRIX.md | 10 +- docs/VCL_TRAFFIC_COOKBOOK.md | 8 +- .../vcl/drupal6-parent-session-cookies.vcl | 26 ++++++ langs/en_US.json | 6 +- langs/pl_pl.json | 6 +- src/admin/openapi.json | 2 +- src/cache/rules.rs | 32 ++++++- src/cache/rules_tests.rs | 91 +++++++++++++++++++ src/cache/vcl.rs | 4 +- 16 files changed, 191 insertions(+), 48 deletions(-) create mode 100644 examples/vcl/drupal6-parent-session-cookies.vcl diff --git a/CHANGELOG.md b/CHANGELOG.md index 0194217..e0c0184 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Release history focused on **features, settings, default behavior, compatibility ## 0.39.1 — HEAD cache-fill and public Vhost cookie template (source-only changes) +- **Selective Drupal 6 parent-session cleanup (0.39.1, no version bump):** the existing `remove_req_cookies(...)` / `remove_named_cookies` action now supports one case-sensitive trailing wildcard (for example `SESS*` or `SSESS*`), while exact-name matching and all separate CDN templates remain intact. Empty, shorter-than-3-character and embedded wildcard patterns are rejected. Added an opt-in VCL example that preserves local `session` cookies and explicit `BYPASS`, Rust regression cases and PL/EN UI hints. Verify cookie ownership before enabling and test logged-in sessions against a real origin. + - **Quick cache/VCL rule gallery (0.39.1, no version bump):** added a grouped template dropdown and searchable one-click scenario browser in global, ordinary Vhost and Docker Vhost editors. The independent CDN/parent-cookie presets remain separate. Added safe pass/no-store patterns for sessions, WordPress/WooCommerce, Django, Laravel, Auth.js, ASP.NET, Drupal, private routes, API, GraphQL, signed URLs, SSE and webhooks. Added disabled-by-default public TTL, assets and staging-header examples, with EN/PL descriptions and a dedicated embedded Reader guide. Multi-rule templates are inserted together or not at all if the rule limit is exceeded; parent-cookie rules are placed before matching existing CDN cookie guards. No cache format, runtime rule engine, API or version change; Rust/toolchain and live-origin tests still required. - **Separate parent-cookie and CDN templates:** replaced the risky all-cookie public-Vhost template with a disabled-by-default per-Vhost rule that removes **only** operator-listed exact cookie names using a new `remove_named_cookies` action and RustProxy VCL extension `remove_req_cookies()`. Unlisted cookies, including app sessions, survive to the *unchanged, separate* CDN template and its `bypass remaining cookies` check. No forced hash or terminal action. The Cookie header cannot identify the issuing Domain; use host-only cookies where possible. Existing previously saved broad strip-all rules must be removed manually. Source-only change; Rust compilation pending. diff --git a/SHA256SUMS b/SHA256SUMS index 6a40126..49e5142 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -2,7 +2,7 @@ 4140a2956264b44f259e6a37fc00ba02097bbe68b09296e04d3d243c1287129b .env.example e76e688874828e3743d03693b1d2872b9633b4db09909673786caf30f7cfe489 .gitignore 9ba24d43572540c7929cc58005b5a3b5b065ec3b896c76e7fe863c78c59e04a7 AGENTS.md -92e812d0cdb476acc3318ff3168c1731d55dae644030883f61f7bb866aa5c13b CHANGELOG.md +8a56b914046b44bc3e52f3fe97d5f8ed3919b48fa8e3c16100d3c1e39c547d9b CHANGELOG.md 9ecd4d4f644cf9a4fdb4a2998a8cfdba270c926ffa93c6bfffa3d7a0adf55e85 Cargo.lock 9566307178ed2b4ab15aea7e5b66614a021634d513fd6f467a846ac8f278bfe9 Cargo.toml 788745d4f70a0382c6280020afbd48844bb2af65e835a826852143f8132cdeca Dockerfile @@ -41,14 +41,14 @@ f30c895df3d7f289f3b7c9a73969009ecf91110f59cb247daa242f68e78aa014 docker-agent/s c0940a4b323d71931cf2ad4ad24d58b6d6bfd49af90c6e3fc91fcbe2b4cf312f docs/ACCESS.md e986cbe1534bbe392b2ce6413fc00ac5bc5d70b40d50c247c5b1b6c7b2760fbe docs/API.md 728b15b9825f547f34c4121219784798dd046fbbdd72ece8906d0cd77e8efc64 docs/BACKUP.md -af2d37a1d21fb62def072e3c0b7b4ec9e6d45bff669e3a090fb5874eb32c351f docs/CACHE.md -89952bbe069fb6ed969e8b336bac09b73ccbea42dc8d1e4ab63f4f8e1d14dc33 docs/CACHE_TEMPLATE_LIBRARY.md +a786d93d0adbccf3eca2c55307c412dcc309a90abde1b623d668f960bf8b8f9a docs/CACHE.md +f910b3b56ec705f02a1796e429380b6946ef21d56175ee10d90199680d511e80 docs/CACHE_TEMPLATE_LIBRARY.md a64f72b95918c24938aa7268ec0a534cb0f28dd1ee0aa325b02c49f3347ccf54 docs/CERTIFICATES.md 6aa83366ad45227d10ebe121ed2c4f690ebcb826939ec2b2eafb40bfd714ac69 docs/CONFIGURATION.md fec29ce846d6705eb45819d85d382f28e28a146b265feab2e4c7cce2a35e5883 docs/CUSTOM_LOCATIONS.md 2f3e005ab01bb48b6a2d74dd8f163159f892d08c35d9ad7162e912e1d4def870 docs/DASHBOARD.md 81bd7a901619092e2a5a5fb7e4edd2157f2b5ce7e0483c24581ec290080446c0 docs/DOCKER_DISCOVERY.md -657115a35dd67574aff70f78a157c0e9c08858a059a006aa704711a403edbaff docs/FEATURES.md +94b59d6c70ccadc49a2c72093b0b0c6b1689644ae69033ec9aa3005bc3a80261 docs/FEATURES.md f5835144cd2802abbcac3a36c76bdd4ec2f25fa49307facb199efec5bf9e92d3 docs/HEADLESS.md 4282602f0b814841f71282040003bec91c24611e5152b33407b76e62357f8d3a docs/INSTALL.md 6e37859bf0dced99d4a7db93790cb38fcd90191932827946d5223eaa4c784fce docs/LOGS.md @@ -56,7 +56,7 @@ f5835144cd2802abbcac3a36c76bdd4ec2f25fa49307facb199efec5bf9e92d3 docs/HEADLESS. a7717c4ab03417914805527e573ea1dfd5d35295bf7b347d0c098bda6d469850 docs/MONITORING.md 6d3937088eeb67a9f690d44ebe0b6e660b68116dbf69091ac7816bdc52cec2b6 docs/PERFORMANCE.md d5894c07c68ec4230987767198434abee13b0e525842fea21bcbe752fa82742b docs/PHP_FPM.md -37ad8b2fc720394e831dce5cc72388ff308bdb27bf3fc09ea9af6f6ff424b3fe docs/README.md +a0691df74bc3e29a3c5647cd8202b85a53a6d513308a50e62b8c86800e9ab058 docs/README.md 490a6dbe870f2b1fd4ec7816768dde6c86fa7957fc9de2d2f075e123c9222222 docs/RESPONSE_DELIVERY.md 95ab4786792d5920a2e109b7d196838057f24b512a69d713fb5884dc75c84339 docs/SCREENSHOTS.md 3a48184b36d225757fc5e2d22c629f89bfe5d4007ff087f0be0ce02a5fb04c28 docs/SECURITY.md @@ -64,9 +64,9 @@ bbef60ff1771da9f48af812987766e1e479408873ae2f079b13f1d5c62ecc6ff docs/STREAMS.m c9c9a0b401f0565f15b834d855bfdb34edb3eab46bff03d9e0825af204d20bf8 docs/TODO.md 978097cf53314ad573583d7176491d984b9dbb22295df2b00168a28b14184c4a docs/TRANSPORT.md 1335bc863391858ff4d584eb7f8ad771e270d36708061f2a1bff09de7906a8ab docs/TROUBLESHOOTING.md -f842f10c90520c30071c74ad9f42e59385e1cc95d34fd29bfdb0bbd6dca87e59 docs/VCL.md -f0d5d9d4eed779245615223c06945fea47d2c27aa1fe721dc7193a788e3fa4bd docs/VCL_SUPPORT_MATRIX.md -167eac6f7a4044051e81fd957109575dcf6cdbef20e9ad2c334d153f133e7b1a docs/VCL_TRAFFIC_COOKBOOK.md +ba261fc82735212103e7127134fb3d2590f32f559fd06fc22e816ad1157476ed docs/VCL.md +5272f99a196ed518406109189d5b64cc9537652c84203cb839267616ccb9eb40 docs/VCL_SUPPORT_MATRIX.md +9f8bd9cd1f42487c621359459c023f9665c17ce34d67a6a949ddaeaa53ee95c7 docs/VCL_TRAFFIC_COOKBOOK.md 1169420deeed8f2e8f3a0acfb3ffe16a3419820ba1869059e0b82bb2411e1537 docs/VHOSTS.md e67928a9d044e71b681c3e52f9dd8b151d6b72f965d16d5da8b0eadde98b70e9 docs/WEB_SERVER.md 42822b1c9801bcadb0e2d785cb91883ca2df1da141222631f153030c95f5e197 docs/images/about.png @@ -96,6 +96,7 @@ a6b835dc07defc12b8f0e48491d5f413843c8be2ba4501d7c28140a2822b034f examples/oidc- 5a8f3a8a054abc89c6e78896b9fe2f903212199a24dc3d2d2bcbd0696a31bcde examples/transport.json 07fef8fb9d20f9d6db1520625f17283a1b598a07e3bd10c1ecbb964923899bc2 examples/vcl/advanced-set-cookie-removal.vcl 56747aae2bc970ea0a8cf2e97232201c01fc7ac7748de90dcb23c62254f404f3 examples/vcl/cdn-technical-cookies.vcl +f51b2d2263447008c1d41ed9a7a58a977fc8aa3eed88ee8b77d1798d29e99244 examples/vcl/drupal6-parent-session-cookies.vcl 9de59289bc83e1bb607263a41be3738321dddb9896dc30a483f2c7b18b70859a examples/vcl/experiment-variants.vcl ecfa04e9f1e9c4f1b1629854798dc432c24414cdd6e80788bceffe37a6716011 examples/vcl/headers-and-diagnostics.vcl 33366f6ff579e50e727aabc552db08fe25e7471f5c52041f55c96493c88c362e examples/vcl/language-catalog.vcl @@ -125,8 +126,8 @@ e9cbb0224c4a3d23a6019ba557e0cd568c1ad5e1582ff1e335fb7d99b7a1055d integrations/r 3f092a9ab80221eddd67be4d1a776acbc6e04c1eb6011b588280c28e83b2582f integrations/routeros-oci-build/build-routeros-oci.sh 3f267cafa16006e5456ade78ee2d5fae02cc7ce747839523068ffd8d7c98798a integrations/routeros-oci-build/docker-entrypoint.sh ae2ee2887fcba096d0de25edcc18faa1ffec35759274518db1bf6d6982f7176c langs/README.md -d3cbdaed42261a49f9262dca5cfaa95ff0da3c42908bc2aacca39015a23289de langs/en_US.json -ff8e97d98eec09b815314bc5fbd213f06d5ffb6e7349b0e34d8e607ffb307340 langs/pl_pl.json +ba725d5add889984e8dd9785edba2ff625c1dff8272a052f45e0974dcc573161 langs/en_US.json +b63fae52e1b13fe8a8af4fc23bf36d69bdb795ccd0af065173407f13d1f6e702 langs/pl_pl.json 8ed80f14633970899d56f4ea72684a8d4b1f2843c1c78bfacc4cbb5f7ce9ef4b make_zip.py e830d37dd1f81a4b0aa7d535f5bba69e34e433b0fd99cc8ee0b296786c32379a migrations/0002_admin.sql 20112cc82192098b8d602f1c4f7ca08712e9e1366c845fabb92753187c370d35 migrations/0003_certificate_renewals.sql @@ -166,6 +167,7 @@ e69813fb1d3a4cdcfb7243964cc323fc21a603087bf2e84188fa42b9d3cee4b5 scripts/runtim 91c883cfdce94c8c22c98749f611317f538a112d29be4f3fb1fa460b8f29ceaa scripts/start_stream_backends.sh 6c137b3183a0581383f18e4c5407c4309abd083c6cec975f203406f5371aeddd scripts/test_cache_rule_catalog_ui.cjs dbbd69f582a761430c6da17ecbadec0384a9a0258f74bbba2d7f758885850413 scripts/test_cache_rule_template_catalog.cjs +b43b6241cfda994c6bc5fd59020b50cb622eb034a721f52fc516c2fd66dbcf71 scripts/test_drupal6_cookie_prefix.cjs 82aac95d7e22bdb887f2e33635467942712c0e7c74d10226427944e91fabe97f scripts/test_public_cookie_template.cjs 046b4282550f5cb4e53906665c91c7442be70fc68fd0743466fd832582f7c979 scripts/test_stream_tcp.py f0b48ec0cc4411755cc0b4128eebce710375afa99344cb76198cf31074f8eb63 scripts/test_stream_udp.py @@ -203,7 +205,7 @@ d58a2ed83319176de4e66790ed292447c9497ae031464ec55cfe27174acb639a src/admin/file 77b8c05645969834cc8a58e249a7b60a57d6c47ad1c5cd92ffa5e4a9b5a8e73c src/admin/file_logs_query.rs e287399bfef114028b8831cb854db2323c0e1b61e3503ef409ebb2c5cdbc2a8c src/admin/logging_api.rs 51228956c33358278ebed62941da273e1e87d0b5c5d1c40cc0d2c91aec9d7362 src/admin/mod.rs -02e5c4aed681479e73a06217eb109bfd3a1eb28d8b36bcca889af009c07c3fc3 src/admin/openapi.json +167fc91985b6e08c710cf627d1c572068464da4d358dc110a24c9eaaa6d6a5a3 src/admin/openapi.json 9f8842cdec27d703d1795dd6eb37d9420e9f5a2e56a0df93278c92bace5d1f4c src/admin/operations.rs 257d93a29d0bda96462bcf695aba8d0ec0f9412c379e066ec46ae8ee034e3a53 src/admin/panel_assets.rs f5127855c2994d052678865df36d703b74f4a0afc633daf7718b10da18d26e37 src/admin/panel_content.rs @@ -380,14 +382,14 @@ e26dce02df9c043329ca164fed215d271781bce8fb03240f528331bf3df6b9d7 src/cache/poli 20d4af129be642f727f3de694abe9404210dd0210dc56124028d62c2f8dd4649 src/cache/policy/response.rs 12a6d5d9d6711e956391b4b952e8149658b8bf64cfcc0a4c59c281f2630a6aac src/cache/policy/scope_tests.rs c3a4300f7cdb6b2b7c16fbc489d49ba2451331bb4a55a2d9f618c684fd61eecb src/cache/range.rs -617294b2d3aba5857f640ea88afcaf2ed41f624145559266de4d121af805364c src/cache/rules.rs -20451b3e662b6d7b2a58a838c0cb60814458bd1d662de36c5b505ef099985eac src/cache/rules_tests.rs +95df70c8ac04e80a46fc480e703a69f46e487bf872b378beb17ed6a736531659 src/cache/rules.rs +a58e1d696b75e404aef05c1eb980893a8ce0c0d5afd6765c4ae21ff2ce4b7194 src/cache/rules_tests.rs 48344d7dcbbb220d8c16f5aa9bb88d86a6388b226bbf93d0ca92d8dfbf2c8001 src/cache/stats.rs 2981e35a7fbbc2b36214b5518f4ba97d57c1d2e01f4f375175c4b2c6be955927 src/cache/tests.rs b969394b04859b269dcecd8958b1aab40b532709512714e9900f0ecad6b6d0c5 src/cache/tickets.rs a1132b980833b1b4ce2bba9aa681ff255a0e2d61faaa65a316860da503ea1e27 src/cache/v022_cache_tests.rs adac3b8de21a73f32d784b3fd2240d17309e8fce022163710e781d44ef590117 src/cache/varnish_compatible_tests.rs -b89d95622389915e355976fd62488bdaa188e9bf0feca2965e29634925e91dca src/cache/vcl.rs +99fe1261d044b2812c809df329a1a3153d0cad38c0926a15dbdefc1688e7939d src/cache/vcl.rs 1a2eb6684d9ea4a7e90970d936c75f7c8bbec46a4181fdf273be9bdac8eec847 src/compression/mod.rs 8de82d9188c9c337690c6ec4afdad9fff20651c358e34602a93d8bb8c3d2489a src/compression/tests.rs e695079333ebdc2a6e7b3337cfabef171b3a0a01da0597b77feff70d417f833e src/config.rs diff --git a/docs/CACHE.md b/docs/CACHE.md index 75aa201..c5b9516 100644 --- a/docs/CACHE.md +++ b/docs/CACHE.md @@ -11,7 +11,7 @@ The **Static & diagnostics** subtab provides **Ignore request cookies for static ### 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. +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 selective 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) @@ -23,14 +23,14 @@ A parent domain may set `Set-Cookie: name=value; Domain=.example.test`, making b Two **separate** opt-in templates remain available in the Vhost cache-rule editor: -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). +1. **Vhost: remove selected parent-domain cookies** (inserted **disabled**): the operator supplies verified comma-separated cookie names or trailing-`*` prefixes in the `Remove selected cookies` action, replacing `REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME`. Only matching 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. +**Order:** place the parent-cookie 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. The only supported wildcard is a **single trailing `*`** (a case-sensitive prefix). For example, `SESS*` or `SSESS*` can discard Drupal 6 cookies from an unrelated parent application, but **only if this Vhost never relies on that cookie family**. Interior wildcards, `*` alone, prefixes shorter than 3 characters and arbitrary regexes are rejected. If the same cookie name or prefix 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. +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 or a case-sensitive prefix match for a **single trailing `*`**, preserves other cookies, and refuses to rewrite malformed Cookie fields. The graphical `Remove selected cookies` action uses the same implementation. For a Drupal 6 parent domain with local `session` cookies, see [`examples/vcl/drupal6-parent-session-cookies.vcl`](../examples/vcl/drupal6-parent-session-cookies.vcl). 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. diff --git a/docs/CACHE_TEMPLATE_LIBRARY.md b/docs/CACHE_TEMPLATE_LIBRARY.md index 8f5b7c6..31b4c1f 100644 --- a/docs/CACHE_TEMPLATE_LIBRARY.md +++ b/docs/CACHE_TEMPLATE_LIBRARY.md @@ -57,7 +57,7 @@ A framework template recognizes only the listed paths or cookie names. Where a s | Template (internal key) | Rules / default | Exact effect | Deployment notes | |---|---|---|---| | **CDN technical cookies** (`cdn`) | 5 request rules, all **On** | `pass` non-GET/HEAD; `pass` `/admin`, `/api`, `/auth`, `/login`, `/logout`, `/panel`, `/konto`, `/dashboard`; `pass` `Authorization`; strip **the entire Cookie header only if every cookie name** belongs to the fixed Cloudflare/Akamai technical list; then `pass` if any Cookie remains. | Do not replace the anchored allowlist with a contains/substring match. Cookie names: `__cf_bm`, `cf_clearance`, `_cfuvid`, `__cfruid`, `__cfseq`, `_abck`, `ak_bmsc`, `bm_sz`, `bm_sv`. Use only if those values are irrelevant to the origin's representation. | -| **Selected parent-domain cookies** (`publiccookies`) | 1 request rule, **Off**; **Vhost-only** | Only on GET/HEAD with Cookie, without Authorization and outside specified private prefixes: remove **only exact cookie names** entered by the operator; no forced cache lookup and no `stop`. | Replace `REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME` with verified, nonsession names. Other cookies remain and can trigger the CDN remaining-cookie `pass` guard. | +| **Selected parent-domain cookies** (`publiccookies`) | 1 request rule, **Off**; **Vhost-only** | Only on GET/HEAD with Cookie, without Authorization and outside specified private prefixes: remove **only selected exact cookie names or trailing-`*` prefixes** entered by the operator; no forced cache lookup and no `stop`. | Replace `REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME` with verified names or prefixes (e.g. `SESS*` for an unrelated Drupal 6 parent, never if this Vhost uses Drupal sessions). Other cookies remain and can trigger the CDN remaining-cookie `pass` guard. | **Safe order for a Vhost using both:** @@ -70,7 +70,7 @@ A separate **Any Cookie** guard should also follow the cookie cleanup if used. T **Why names must be verified:** request `Cookie` carries *names and values*, not the `Domain` attribute that originally set the cookie. RustProxy cannot automatically tell whether it came from a parent host. If the parent site and application use the **same** cookie name for different purposes, name-based deletion is unsafe. Prefer host-only cookies at the issuer or an explicit per-route design instead. Removing a Cookie changes both the cache decision **and** what the backend receives. -For copyable VCL syntax, see [parent-domain cookie removal](VCL_TRAFFIC_COOKBOOK.md#12-parent-domain-cookies-remove-selected-names-opt-in), [`public-vhost-remove-parent-cookies.vcl`](../examples/vcl/public-vhost-remove-parent-cookies.vcl) and [`cdn-technical-cookies.vcl`](../examples/vcl/cdn-technical-cookies.vcl). The selective `remove_req_cookies(...)` instruction is a **RustProxy extension**, not standard Varnish VCL. +For copyable VCL syntax, see [parent-domain cookie removal](VCL_TRAFFIC_COOKBOOK.md#12-parent-domain-cookies-remove-selected-names-opt-in), [`public-vhost-remove-parent-cookies.vcl`](../examples/vcl/public-vhost-remove-parent-cookies.vcl) and [`cdn-technical-cookies.vcl`](../examples/vcl/cdn-technical-cookies.vcl). The selective `remove_req_cookies(...)` instruction accepts exact names and a single trailing wildcard (`prefix*`) and is a **RustProxy extension**, not standard Varnish VCL. For Drupal 6 parent cookies see [`drupal6-parent-session-cookies.vcl`](../examples/vcl/drupal6-parent-session-cookies.vcl). ## 4. Public content and cache TTL (10 scenarios) diff --git a/docs/FEATURES.md b/docs/FEATURES.md index 76a45b8..1a4e6e6 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -74,7 +74,7 @@ RustProxy is a single service that combines a reverse proxy, a static/PHP web se ![Cache](images/cache.png) - Searchable **quick-rule template gallery** in global/Vhost/Docker cache editors: grouped ready-made session/privacy, CMS/framework, CDN/parent-cookie, API/GraphQL, public TTL, static assets and response-header scenarios. Risky cache-acceleration templates are disabled until reviewed; examples are documented in [Quick rules library](CACHE_TEMPLATE_LIBRARY.md). -- Separate disabled-by-default per-Vhost template for exact-name removal of verified non-session parent-domain cookies; unrelated/session cookies survive and the unchanged CDN template can independently strip CDN-only cookies or bypass remaining sessions. No automatic cookie Domain detection. +- Separate disabled-by-default per-Vhost template for exact-name or single trailing-prefix (`SESS*`) removal of verified unrelated parent-domain cookies; unrelated/session cookies survive and the unchanged CDN template can independently strip CDN-only cookies or bypass remaining sessions. No automatic cookie Domain detection. - CDN security-cookie template (Cloudflare and Akamai) that strips whole Cookie headers only when every cookie is allowlisted, with session/Authorization/path bypass; opt-in for verified public content. The [VCL support matrix](VCL_SUPPORT_MATRIX.md) documents supported and deliberately excluded constructs. - **VCL subset only:** graphical rules are the canonical configuration. Partial imports require review; the VCL text shown in the editor is an approximate preview. Cache storage is restricted to HTTP 200 (non-200 responses can still receive deliver-header rules). See [VCL import](VCL.md). diff --git a/docs/README.md b/docs/README.md index 1f633f8..ca83f55 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,7 +38,7 @@ Guides for operating RustProxy: installation, publishing services, security, cer - [Cache](CACHE.md) — scope-aware Cache & VCL help modal from global/Vhost/Docker editors, a compact rule tester, HOT/COLD cache, RFC 9111 `Vary` matching/normalization, safe static-asset cookie exceptions, freshness, `Cache-Status` and invalidation. - [Quick rules template library](CACHE_TEMPLATE_LIBRARY.md) — searchable grouped scenarios for sessions, CDN/parent cookies, frameworks, public APIs, assets, no-store and security headers; defaults, risks and smoke tests. -- [VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) — 12 ready-to-import examples, separate name-selective parent-domain and CDN cookie rules, Cookie/`Vary` variants, `curl` verification and failure modes. +- [VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) — 12 cookbook recipes plus a Drupal 6 prefix-cookie example, separate parent-domain and CDN cookie rules, Cookie/`Vary` variants, `curl` verification and failure modes. - [Complete VCL support matrix](VCL_SUPPORT_MATRIX.md) — line-by-line supported, restricted, graphical-only, intentionally excluded and missing instructions, with test scenarios. - [VCL compatibility and header overrides](VCL.md) — supported VCL import syntax, safe request-header edits, `beresp.uncacheable` precedence, `Vary`, cookies, approval of partial imports and storage limits. - [Response delivery](RESPONSE_DELIVERY.md) — compression, transformations and response headers. diff --git a/docs/VCL.md b/docs/VCL.md index c71d028..1c8df16 100644 --- a/docs/VCL.md +++ b/docs/VCL.md @@ -21,7 +21,7 @@ For the **complete reference to all 42 quick-rule templates** (conditions, stage | `vcl_recv` | `return(pass);` | Stops request processing for the matching path; bypasses shared cache. | | `vcl_recv` | `return(hash);` or `return(lookup);` | Stops `vcl_recv` and requests a cache lookup. In compatibility mode, may admit a GET/HEAD carrying `Cookie` (with cookie-partitioned variants); other protections remain. | | `vcl_recv` | `unset req.http.Cookie;` | Removes the **whole** request Cookie header, including what is forwarded to the origin. | -| `vcl_recv` | `remove_req_cookies("parent_analytics");` | **RustProxy extension:** removes only the specified exact-name cookie(s) from the request before later rules, cache lookup and origin forwarding. Remaining session cookies are not removed and can still trigger BYPASS. Not standard Varnish VCL. | +| `vcl_recv` | `remove_req_cookies("parent_analytics", "SESS*");` | **RustProxy extension:** removes exact-name cookies or case-sensitive prefixes marked by one trailing `*` before later rules, cache lookup and origin forwarding. Remaining session cookies are not removed and can still trigger BYPASS. Not standard Varnish VCL. | | `vcl_recv` | `set req.http.X-Device = "mobile";` / `unset req.http.X-Tracking;` | Sets/removes a **safe request header** before later conditions, `vcl_hash`, cache policy and the forwarded origin request. Assignments are constant strings, and a per-vhost edit takes priority over a conflicting global edit. Authentication, identity, request cache policy and transport headers are protected (see below). | | `vcl_recv` | `set req.url = regsuball(req.url, "([?&])(utm_[^=&]*|gclid)=[^&]*", "\1");` | **Restricted conversion only:** recognizes the specific captured-separator, query-parameter-removal pattern. Other `regsub` / `regsuball` rewrites are skipped with warnings; arbitrary URL regex replacement is not supported. | | `vcl_hash` | `hash_data(req.http.X-Name);` | Adds one request header's value to RustProxy's **internal** variant key. It does not automatically add `Vary` for downstream caches. | @@ -56,7 +56,7 @@ sub vcl_hash { Both header edits are visible to later matching rules, the hash calculation and the origin. They also run on cache-disabled reverse-proxy routes (without enabling cache). They **do not** rewrite the client's original `Vary` requirements: if the response varies by `X-Device`, include it in `beresp.http.Vary` or configure it at the origin. A later `unset` is different from setting an empty string. -Protected request headers cannot be set or removed by general request rules: `Authorization`, `Cookie` (except dedicated whole-header `unset` or exact-name `remove_req_cookies(...)` actions), `Cache-Control`, `Pragma`, `Host`, range/precondition headers (`If-*`, `Range`), forwarding and origin identity headers (`Forwarded`, `Via`, `X-Forwarded-*`, `X-Real-IP`, `X-Client-IP`, `CF-Connecting-IP`, `True-Client-IP`), `Proxy-*`, `Sec-*`, `X-RustProxy-*`, `Content-Type`, `Expect` and the protected transport/body header list below. Rejected edits are warned about and never silently applied. Do not assume imported VCL can change authentication or request-cache restrictions. +Protected request headers cannot be set or removed by general request rules: `Authorization`, `Cookie` (except dedicated whole-header `unset` or selective `remove_req_cookies(...)` actions), `Cache-Control`, `Pragma`, `Host`, range/precondition headers (`If-*`, `Range`), forwarding and origin identity headers (`Forwarded`, `Via`, `X-Forwarded-*`, `X-Real-IP`, `X-Client-IP`, `CF-Connecting-IP`, `True-Client-IP`), `Proxy-*`, `Sec-*`, `X-RustProxy-*`, `Content-Type`, `Expect` and the protected transport/body header list below. Rejected edits are warned about and never silently applied. Do not assume imported VCL can change authentication or request-cache restrictions. The query-removal conversion accepts only the supported captured-separator `regsuball` pattern. **Every such conversion emits a warning**, because removing parameters with RustProxy's parser can normalize separators differently from a regex replacement. Variable-name classes such as `utm_[a-z]+` are approximated by a prefix wildcard; value patterns ending in `[^&]+` may preserve empty values that `strip_query` removes. **Review generated parameters and warnings** if byte-exact URL behavior matters. Other URL rewrites are deliberately **not** guessed from keywords such as `utm_`. @@ -148,7 +148,7 @@ sub vcl_recv { } ``` -Use `unset req.http.Cookie;` only when the origin does not need **any** cookies for that route. For a Vhost that receives cookies from a parent domain, prefer the [name-selective opt-in recipe](VCL_TRAFFIC_COOKBOOK.md#12-parent-domain-cookies-remove-selected-names-opt-in): `remove_req_cookies("exact_cookie_name");` is a **RustProxy-specific extension** that removes only named cookies, preserving session and other cookies for later rules. The separate CDN technical-cookie policy still has its own anchored allowlist and remaining-cookie pass. `Cookie` does not disclose the setting `Domain`, so a name must be verified outside RustProxy; avoid removing a name also used by this Vhost. A graphical **Strip cookies** action keeps an allowlist but is not equivalent to selective removal. In strict RFC mode (`cache.varnish_compatible=false`), `return(hash)` does not bypass the request Cookie restriction. `Authorization`, non-GET/HEAD traffic, request `no-store`, access/authentication and sticky-session checks still apply. +Use `unset req.http.Cookie;` only when the origin does not need **any** cookies for that route. For a Vhost that receives cookies from a parent domain, prefer the [name-selective opt-in recipe](VCL_TRAFFIC_COOKBOOK.md#12-parent-domain-cookies-remove-selected-names-opt-in): `remove_req_cookies("exact_cookie_name", "SESS*");` is a **RustProxy-specific extension** that removes exact names or a single trailing-`*` prefix, preserving other cookies for later rules. Use `SESS*` only when the Vhost never uses that session family; see the [Drupal 6 parent-domain example](../examples/vcl/drupal6-parent-session-cookies.vcl). The separate CDN technical-cookie policy still has its own anchored allowlist and remaining-cookie pass. `Cookie` does not disclose the setting `Domain`, so a name must be verified outside RustProxy; avoid removing a name also used by this Vhost. A graphical **Strip cookies** action keeps an allowlist but is not equivalent to selective removal. In strict RFC mode (`cache.varnish_compatible=false`), `return(hash)` does not bypass the request Cookie restriction. `Authorization`, non-GET/HEAD traffic, request `no-store`, access/authentication and sticky-session checks still apply. ## `no-cache` and TTL diff --git a/docs/VCL_SUPPORT_MATRIX.md b/docs/VCL_SUPPORT_MATRIX.md index fe602df..5b8546e 100644 --- a/docs/VCL_SUPPORT_MATRIX.md +++ b/docs/VCL_SUPPORT_MATRIX.md @@ -4,13 +4,13 @@ ## Practical examples and traffic scenarios -The companion [VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) contains **11 complete VCL examples** (including an intentionally restricted importer example and a high-risk advanced example), an HTTP request/response behavior matrix, `curl` checks, expected `PASS`/`MISS`/`HIT` behavior and troubleshooting. The standalone source files are in [`examples/vcl/`](../examples/vcl/). They cover public catalogs, JSON APIs, private routes, CDN cookies, public static files, multilingual responses, A/B variants, SSE/webhooks/errors, safe header changes, query normalization and highly restricted Set-Cookie removal. Each example states its origin/privacy contract and importer limitations. +The companion [VCL traffic cookbook](VCL_TRAFFIC_COOKBOOK.md) contains **12 VCL recipes and an additional Drupal 6 parent-domain example** (including an intentionally restricted importer example and a high-risk advanced example), an HTTP request/response behavior matrix, `curl` checks, expected `PASS`/`MISS`/`HIT` behavior and troubleshooting. The standalone source files are in [`examples/vcl/`](../examples/vcl/). They cover public catalogs, JSON APIs, private routes, CDN cookies, public static files, multilingual responses, A/B variants, SSE/webhooks/errors, safe header changes, query normalization and highly restricted Set-Cookie removal. Each example states its origin/privacy contract and importer limitations. | Goal | Available through imported VCL | Native GUI/API required or not supported | |---|---|---| | Bypass admin/session/credentialed requests | `vcl_recv` with `return(pass)` | Authentication and access policy remain native | | Cache public GET JSON/catalog | `return(hash)` plus conditional `beresp.ttl` | Global/Vhost cache must already be enabled; only 200 can be stored | -| Strip CDN technical cookies | Entire Cookie header removal after an exact allowlist | Removing one cookie by name from a mixed header: graphical action only | +| Strip CDN technical cookies | Entire Cookie header removal after an exact allowlist | Selective exact-name or trailing-* prefix removal is also available through the RustProxy `remove_req_cookies()` VCL extension | | Safely ignore `Vary: Cookie` on public static | VCL can remove request Cookie, but **not** safely override `Vary` | Narrow native static-asset settings, not a general Ignore Vary feature | | Multilingual/CORS/encoded responses | Preserve origin `Vary`; optional internal `vcl_hash` dimension | Origin must emit the complete downstream `Vary` dimensions | | Webhooks, SSE, transient errors | PASS, `beresp.uncacheable=true` | Retries, stale-if-error, streaming and backend failures are native behaviors | @@ -82,11 +82,11 @@ Do **not** use an unanchored regex such as `req.http.Cookie ~ "__cf_bm"` with `u | `return(pass);` | Supported | Cache bypass; terminates applicable request-stage rules and skips `vcl_hash`. | | `return(hash);`, `return(lookup);` | Supported with safety conditions | Explicit lookup; in Varnish-compatibility mode can admit **Cookie-bearing GET/HEAD** requests, partitioned by their remaining Cookie value and with downstream `Vary: Cookie`. Does not override Authorization, unsafe methods, client privacy or disabled cache. | | `unset req.http.Cookie;` | Supported, risky | Removes **every** Cookie value; never use for a session-bearing Vhost. | -| `remove_req_cookies("exact_name", "another_name");` | Supported, RustProxy extension | Deletes **only** selected exact Cookie names on the request, retaining other cookies for later pass/cache checks; refused on malformed Cookie fields. Not stock Varnish VCL. | +| `remove_req_cookies("exact_name", "SESS*");` | Supported, RustProxy extension | Deletes selected exact Cookie names or case-sensitive name prefixes with one trailing `*`; keeps all other cookies for later pass/cache checks. Refuses malformed Cookie fields and rejects `*` alone, prefixes shorter than 3 characters, middle wildcards and general regexes. Not stock Varnish VCL. | | `set req.http.X-Name = "literal";` | Supported with protected-name list | Changes a safe request header to a constant string. Origin sees the change. Dynamic/compound expressions are not recognized. | | `unset req.http.X-Name;` | Supported with protected-name list | Removes all values of an allowed request header. | | `set req.url = regsuball(req.url, "...", "\\1");` | Restricted | Only a pattern that matches a captured query separator plus a known parameter-name list is converted to `strip_query`; importer warns about separator/empty-value differences. See [VCL details](VCL.md#request-header-changes-scope-and-safeguards). | -| `set req.http.Cookie = regsuball(...)`, `regsub()` on cookies | Not implemented | Arbitrary Cookie regex rewrites are unsafe and not imported; use `remove_req_cookies()` or graphical **Remove only named cookies** for selective removal. | +| `set req.http.Cookie = regsuball(...)`, `regsub()` on cookies | Not implemented | Arbitrary Cookie regex rewrites are unsafe and not imported; use `remove_req_cookies()` or graphical **Remove selected cookies (name / prefix*)** for selective removal. | | `set req.backend_hint`, `set req.method`, `set req.hash`, `set req.http.Authorization` | Unsupported (intentional boundary) | Request origin selection, security identity, method, HTTP framing and credentials remain controlled by RustProxy's normal Vhost/route/auth machinery. | | `return(pipe)`, `return(purge)`, `return(synth(...))`, `return(restart)` | Not implemented | Warnings, not equivalents to `pass` or other rules. | | `return(deliver)` in `vcl_recv` | Not implemented | This is not a supported return target in the request stage. | @@ -208,7 +208,7 @@ The labels above distinguish explicit product limits from missing work; **not im ### Included opt-in parent-domain cookie rule (separate from CDN) -The **Vhost: remove selected parent-domain cookies** graphical rule is available only in local Vhost/Docker Vhost editors, inserted disabled. It uses the **Remove only named cookies** action and an operator-edited exact list, not `Strip cookies` / whole-header removal. It applies to GET/HEAD without Authorization and outside example private paths, does **not** return(hash) and does **not** stop later request rules. The equivalent RustProxy-specific VCL `remove_req_cookies("cookie_name");` is imported as `remove_named_cookies`. When a request has parent and session cookies, the session remains; later CDN's `bypass remaining cookies` or RustProxy's default request-cookie guard prevents shared-cache reuse. The operator must verify that the listed name is never used by this Vhost; `Cookie` does not carry the originating Domain. The old whole-header public-Vhost template is no longer offered; remove any already-saved unsafe copy manually. +The **Vhost: remove selected parent-domain cookies** graphical rule is available only in local Vhost/Docker Vhost editors, inserted disabled. It uses the **Remove selected cookies** action and an operator-edited list of exact names or trailing-`*` prefixes, not `Strip cookies` / whole-header removal. It applies to GET/HEAD without Authorization and outside example private paths, does **not** return(hash) and does **not** stop later request rules. The equivalent RustProxy-specific VCL `remove_req_cookies("cookie_name", "SESS*");` is imported as `remove_named_cookies`. A wildcard matches by prefix only, and should be used exclusively for verified unrelated cookie families such as Drupal 6 parent-domain SESS names; see [`drupal6-parent-session-cookies.vcl`](../examples/vcl/drupal6-parent-session-cookies.vcl). When a request has parent and session cookies, the session remains; later CDN's `bypass remaining cookies` or RustProxy's default request-cookie guard prevents shared-cache reuse. The operator must verify that the listed name is never used by this Vhost; `Cookie` does not carry the originating Domain. The old whole-header public-Vhost template is no longer offered; remove any already-saved unsafe copy manually. ### Included opt-in CDN cookie policy diff --git a/docs/VCL_TRAFFIC_COOKBOOK.md b/docs/VCL_TRAFFIC_COOKBOOK.md index 9522564..b80b860 100644 --- a/docs/VCL_TRAFFIC_COOKBOOK.md +++ b/docs/VCL_TRAFFIC_COOKBOOK.md @@ -31,7 +31,7 @@ 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 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 | +| Cookies set broadly by a parent domain | [Selective parent cookie removal](#12-parent-domain-cookies-remove-selected-names-opt-in) | Remove only **verified names or trailing-`*` prefixes**, 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 | @@ -409,11 +409,11 @@ sub vcl_backend_response { **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:** 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. +**Prerequisites:** On the Vhost, add **Vhost: remove selected parent-domain cookies**, replace `REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME` with the verified cookie names or single trailing-`*` prefixes in **Remove selected 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:** 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). +**Caveat:** A cookie name or prefix 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-remove-parent-cookies.vcl`](../examples/vcl/public-vhost-remove-parent-cookies.vcl). +Source: [`examples/vcl/public-vhost-remove-parent-cookies.vcl`](../examples/vcl/public-vhost-remove-parent-cookies.vcl). For a parent Drupal 6 site with dynamic `SESS` names and a separate local `session` cookie, use the [Drupal 6 example](../examples/vcl/drupal6-parent-session-cookies.vcl): it removes `SESS*`/`SSESS*` while explicitly bypassing on `session`. This example requires the prefix-selector-enabled 0.39.1 binary, not an earlier unpatched build. The CDN policy remains separate. ```vcl // Opt-in Vhost-only rule, SEPARATE from the CDN technical-cookie template. diff --git a/examples/vcl/drupal6-parent-session-cookies.vcl b/examples/vcl/drupal6-parent-session-cookies.vcl new file mode 100644 index 0000000..a90c42f --- /dev/null +++ b/examples/vcl/drupal6-parent-session-cookies.vcl @@ -0,0 +1,26 @@ +// Opt-in example: this Vhost uses "session" while an unrelated Drupal 6 site +// at the parent domain sets cookies named SESS or SSESS. +// RustProxy 0.39.1 (with prefix selector support) only: remove_req_cookies() +// supports exact names and a single trailing '*' for case-sensitive prefixes. +// Not standard Varnish VCL. A normal 0.39.1 binary without this patch will +// treat "SESS*" as an exact literal name and WILL NOT strip Drupal cookies. +// +// Only install after confirming this Vhost never uses SESS* or SSESS* for +// authentication, personalization, CSRF protection, or other state. +// Keep CDN technical-cookie rules separate and later than this rule. +// Retain "CDN: bypass remaining cookies" to protect unknown session cookies. +sub vcl_recv { + // Subdomain's OWN login cookie must always skip shared cache. + if (req.http.Cookie ~ "(?:^|;[ \\t]*)session=") { + return(pass); + } + + 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)(/|[?]|$)") { + // Drupal 6 parent-domain session name changes with the site/hash. + // Analytics cookies below are also safe only when nonfunctional here. + remove_req_cookies("SESS*", "SSESS*", "_ga", "_ga_*", "_gid"); + } +} diff --git a/langs/en_US.json b/langs/en_US.json index a125a5f..42b943f 100644 --- a/langs/en_US.json +++ b/langs/en_US.json @@ -3541,7 +3541,7 @@ "cacheRuleActionPass": "Bypass cache (pass)", "cacheRuleActionLookup": "Allow Cookie cache lookup (hash)", "cacheRuleActionStripCookies": "Remove cookies", - "cacheRuleActionRemoveNamedCookies": "Remove only named cookies", + "cacheRuleActionRemoveNamedCookies": "Remove selected cookies (name / prefix*)", "cacheRuleActionStripQuery": "Remove query parameters", "cacheRuleActionSetRequestHeader": "Set request header", "cacheRuleActionRemoveRequestHeader": "Remove request header", @@ -3564,7 +3564,7 @@ "cacheRuleActionHelpIgnoreCacheControl": "Caches even with no-cache, private or no-store from the backend (uses the TTL action or the default TTL). Responses with Set-Cookie still need Remove Set-Cookie.", "cacheRuleActionHelpStripSetCookie": "Removes Set-Cookie from the backend response (stored and delivered), like unset beresp.http.Set-Cookie.", "cacheRuleKeepCookies": "keep cookies (empty = remove all)", - "cacheRuleRemoveNamedCookies": "Exact cookie names to ignore on this vhost (comma separated)", + "cacheRuleRemoveNamedCookies": "Cookie names or prefix* patterns (comma separated, e.g. _ga, SESS*). Never match this app's session.", "cacheRuleKeepOnly": "keep only these", "cacheRuleQueryParams": "utm_*, fbclid (empty = all)", "cacheRuleHeaderValue": "value", @@ -3635,7 +3635,7 @@ "cacheRuleTplHelpWordpress": "Protect wp-admin/login, REST API and common logged-in WordPress cookies; review paths for plugins.", "cacheRuleTplHelpStatic": "Removes all cookies for static extensions and sets 30-day TTL; only if files are identical for guests and logged-in users.", "cacheRuleTplHelpCdn": "Separate Cloudflare/Akamai technical-cookie policy; leaves mixed session cookies for BYPASS.", - "cacheRuleTplHelpPubliccookies": "Disabled by default. Replace the placeholder with verified exact cookie names inherited from a parent domain. Never list app sessions.", + "cacheRuleTplHelpPubliccookies": "Disabled by default. Replace the placeholder with verified parent-domain cookie names or prefix* selectors (e.g. SESS* only if this vhost does not use Drupal sessions). Never match this app's session.", "cacheRuleTplHelpTracking": "Remove known tracking-only query parameters from cache lookup and origin URL; review attribution impact.", "cacheRuleTplHelpApi": "Bypass /api/ on all methods, including otherwise cacheable GET; adjust the API prefix.", "cacheRuleTplHelpLanguage": "Add a language cookie dimension to the key; cache still bypasses real sessions and must honor origin Vary.", diff --git a/langs/pl_pl.json b/langs/pl_pl.json index abdec68..7a6a19d 100644 --- a/langs/pl_pl.json +++ b/langs/pl_pl.json @@ -3541,7 +3541,7 @@ "cacheRuleActionPass": "Pomiń cache (pass)", "cacheRuleActionLookup": "Dopuść cache żądania z Cookie (hash)", "cacheRuleActionStripCookies": "Usuń ciasteczka", - "cacheRuleActionRemoveNamedCookies": "Usuń tylko wskazane ciasteczka", + "cacheRuleActionRemoveNamedCookies": "Usuń cookies po nazwie / prefiksie*", "cacheRuleActionStripQuery": "Usuń parametry zapytania", "cacheRuleActionSetRequestHeader": "Ustaw nagłówek żądania", "cacheRuleActionRemoveRequestHeader": "Usuń nagłówek żądania", @@ -3564,7 +3564,7 @@ "cacheRuleActionHelpIgnoreCacheControl": "Zapisuje mimo no-cache, private lub no-store z backendu (TTL z akcji TTL albo domyślny). Odpowiedzi z Set-Cookie wymagają też Usuń Set-Cookie.", "cacheRuleActionHelpStripSetCookie": "Usuwa Set-Cookie z odpowiedzi backendu (zapisywanej i wysyłanej), jak unset beresp.http.Set-Cookie.", "cacheRuleKeepCookies": "zostaw ciasteczka (puste = usuń wszystkie)", - "cacheRuleRemoveNamedCookies": "Nazwy cookies do pominięcia na tym vhoście (oddziel przecinkami)", + "cacheRuleRemoveNamedCookies": "Nazwy cookies lub prefiksy* (oddziel przecinkami, np. _ga, SESS*). Nie usuwaj sesji tej aplikacji.", "cacheRuleKeepOnly": "zostaw tylko te", "cacheRuleQueryParams": "utm_*, fbclid (puste = wszystkie)", "cacheRuleHeaderValue": "wartość", @@ -3635,7 +3635,7 @@ "cacheRuleTplHelpWordpress": "Chroni panel, logowanie, REST API i typowe cookies zalogowanych; sprawdź ścieżki wtyczek.", "cacheRuleTplHelpStatic": "Usuwa wszystkie cookies dla rozszerzeń statycznych i ustawia TTL 30 dni; tylko gdy pliki są identyczne dla wszystkich.", "cacheRuleTplHelpCdn": "Osobne reguły cookies technicznych Cloudflare/Akamai; cookies sesyjne nadal powodują BYPASS.", - "cacheRuleTplHelpPubliccookies": "Domyślnie wyłączony. Wpisz dokładne nazwy nieistotnych cookies z domeny nadrzędnej; nigdy cookies sesyjnych.", + "cacheRuleTplHelpPubliccookies": "Domyślnie wyłączony. Wpisz zweryfikowane nazwy cookies domeny nadrzędnej lub prefiksy* (np. SESS*, wyłącznie gdy ten vhost nie korzysta z sesji Drupala). Nie usuwaj sesji tej aplikacji.", "cacheRuleTplHelpTracking": "Usuwa wybrane parametry marketingowe z URL i klucza cache; sprawdź wpływ na analitykę.", "cacheRuleTplHelpApi": "Pomija całą ścieżkę /api/, również GET; dopasuj prefiks API.", "cacheRuleTplHelpLanguage": "Dodaje językowe cookie do klucza; sesje nadal muszą omijać cache, a Vary backendu jest obowiązujący.", diff --git a/src/admin/openapi.json b/src/admin/openapi.json index e63bb7a..5ed8e46 100644 --- a/src/admin/openapi.json +++ b/src/admin/openapi.json @@ -8865,7 +8865,7 @@ "maxItems": 16, "items": { "type": "object", - "description": "type: pass, lookup (VCL return(hash), Cookie exception in Varnish-compatible mode), strip_cookies{keep}, remove_named_cookies{names} (exact-name removal; sessions and unknown cookies remain), strip_query{params,keep_only}, hash_header{name}, hash_cookie{name}, set_request_header{name,value}, remove_request_header{name} (request; protected auth/cache/framing headers cannot be changed); ttl{seconds}, grace{seconds}, no_store, allow_store (reverses rule no_store only; origin restrictions remain), ignore_cache_control, strip_set_cookie, set_backend_header{name,value}, remove_backend_header{name} (response, applied before cacheability and forwarded headers); set_header{name,value}, default_header{name,value}, remove_header{name} (deliver, including cache-disabled responses).", + "description": "type: pass, lookup (VCL return(hash), Cookie exception in Varnish-compatible mode), strip_cookies{keep}, remove_named_cookies{names} (exact names or trailing-* prefixes; remaining cookies, including application sessions, survive), strip_query{params,keep_only}, hash_header{name}, hash_cookie{name}, set_request_header{name,value}, remove_request_header{name} (request; protected auth/cache/framing headers cannot be changed); ttl{seconds}, grace{seconds}, no_store, allow_store (reverses rule no_store only; origin restrictions remain), ignore_cache_control, strip_set_cookie, set_backend_header{name,value}, remove_backend_header{name} (response, applied before cacheability and forwarded headers); set_header{name,value}, default_header{name,value}, remove_header{name} (deliver, including cache-disabled responses).", "additionalProperties": true }, "description": "Zero actions allowed only with stop=true (terminal return)." diff --git a/src/cache/rules.rs b/src/cache/rules.rs index 58ecb4a..112c3dc 100644 --- a/src/cache/rules.rs +++ b/src/cache/rules.rs @@ -154,7 +154,8 @@ pub enum RuleAction { #[serde(default, skip_serializing_if = "Vec::is_empty")] keep: Vec, }, - /// Remove only explicitly named cookies; retain unknown/session cookies. + /// Remove explicitly named cookies or names matching a trailing-* prefix. + /// Unknown cookies remain available for session checks and cache bypass. RemoveNamedCookies { names: Vec }, StripQuery { #[serde(default, skip_serializing_if = "Vec::is_empty")] @@ -271,6 +272,27 @@ fn valid_cookie_name(value: &str) -> bool { .all(|byte| byte.is_ascii_graphic() && !b"()<>@,;:\\\"/[]?={}".contains(&byte)) } +// Selective Cookie removal accepts exact names or a single trailing '*'. +// No interior wildcards, '?' patterns, empty prefixes or general regexes: +// a broad match here could expose a logged-in page from shared cache. +fn valid_cookie_remove_selector(value: &str) -> bool { + if value.len() > 128 { + return false; + } + match value.strip_suffix('*') { + // Avoid accidentally stripping huge sets of cookies with "a*" / "s*". + Some(prefix) => prefix.len() >= 3 && !prefix.contains('*') && valid_cookie_name(prefix), + None => !value.contains('*') && valid_cookie_name(value), + } +} + +fn cookie_remove_selector_matches(selector: &str, name: &str) -> bool { + match selector.strip_suffix('*') { + Some(prefix) => name.starts_with(prefix), + None => selector == name, + } +} + fn valid_query_pattern(value: &str) -> bool { !value.is_empty() && value.len() <= 128 @@ -583,9 +605,9 @@ fn validate_action(action: &RuleAction) -> Result<()> { } RuleAction::RemoveNamedCookies { names } => { ensure!(!names.is_empty() && names.len() <= MAX_RULE_VALUES, - "remove_named_cookies requires 1 to 64 exact cookie names"); - ensure!(names.iter().all(|name| valid_cookie_name(name)), - "invalid cookie name"); + "remove_named_cookies requires 1 to 64 cookie names or prefix* selectors"); + ensure!(names.iter().all(|name| valid_cookie_remove_selector(name)), + "invalid cookie removal selector (use an exact name or prefix*)"); } RuleAction::StripQuery { params, keep_only } => { ensure!( @@ -1374,7 +1396,7 @@ impl RequestRuleOutcome { // Do not normalize whitespace *inside* a cookie name: a // malformed/lookalike name must stay present and bypass. if !valid_cookie_name(name) { return; } - if self.remove_named_cookies.iter().any(|removed| removed == name) { + if self.remove_named_cookies.iter().any(|selector| cookie_remove_selector_matches(selector, name)) { continue; } if self.strip_cookies.as_ref().is_some_and(|allow| !allow.iter().any(|item| item == name)) { diff --git a/src/cache/rules_tests.rs b/src/cache/rules_tests.rs index 5be4a33..25f943d 100644 --- a/src/cache/rules_tests.rs +++ b/src/cache/rules_tests.rs @@ -1179,4 +1179,95 @@ sub vcl_deliver { validate_rules(&good.rules, false).unwrap(); } + + #[test] + fn drupal6_parent_cookie_prefixes_are_removed_without_removing_local_session() { + let drupal = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), + "/examples/vcl/drupal6-parent-session-cookies.vcl")); + let cdn = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), + "/examples/vcl/cdn-technical-cookies.vcl")); + let imported = import_vcl(&format!("{drupal}\n{cdn}")).unwrap(); + assert!(imported.warnings.is_empty(), "{:?}", imported.warnings); + validate_rules(&imported.rules, false).unwrap(); + let compiled = CompiledRules::compile("z", &imported.rules, &[], false).unwrap(); + + // Exact names and suffix-* prefixes are case-sensitive. The local + // "session" cookie must survive and force pass regardless of order. + for (cookie, forwarded, pass) in [ + ("SESSabcdef1234=parent", None, false), + ("SSESSabcdef1234=parent", None, false), + ("SESSabcdef1234=parent; _ga_4TEST=x", None, false), + ("SESSabcdef1234=parent; __cf_bm=cdn", None, false), + ("__cf_bm=cdn; SESSdifferenthash=parent", None, false), + ("SESSabcdef=parent; session=app", Some("SESSabcdef=parent; session=app"), true), + ("session=app; SESSabcdef=parent", Some("session=app; SESSabcdef=parent"), true), + ("SESSabcdef=parent; other=unknown", Some("other=unknown"), true), + ("sessionid=abc", Some("sessionid=abc"), true), + ("sessabcdef=other", Some("sessabcdef=other"), true), + ("XSESSabcdef=other", Some("XSESSabcdef=other"), true), + ("SESS=parent", None, false), + ] { + let input = request("/rezerwa/15", None, &[("cookie", cookie)]); + let result = compiled.evaluate_request(&input, false); + assert_eq!(result.pass.is_some(), pass, "Cookie: {cookie}"); + let mut headers = input.headers.clone(); + result.rewrite_cookies(&mut headers); + assert_eq!(headers.get("cookie").and_then(|v| v.to_str().ok()), forwarded, + "Cookie: {cookie}"); + } + + let separate = request("/rezerwa/15", None, &[ + ("cookie", "SESSabc=parent"), ("cookie", "session=app")]); + let result = compiled.evaluate_request(&separate, false); + assert!(result.pass.is_some()); + let mut headers = separate.headers.clone(); + result.rewrite_cookies(&mut headers); + assert!(headers.get_all("cookie").iter().any(|v| v.to_str().ok() == Some("session=app"))); + + for path in ["/admin", "/login", "/account", "/api/orders"] { + let input = request(path, None, &[("cookie", "SESSabcdef=parent")]); + let result = compiled.evaluate_request(&input, false); + assert!(result.pass.is_some(), "{path}"); + assert!(result.remove_named_cookies.is_empty(), "{path}"); + } + let authorized = request("/rezerwa/15", None, &[ + ("cookie", "SESSabcdef=parent"), ("authorization", "Bearer token")]); + assert!(compiled.evaluate_request(&authorized, false).pass.is_some()); + + let mut post = request("/rezerwa/15", None, &[("cookie", "SESSabcdef=parent")]); + post.method = Method::POST; + assert!(compiled.evaluate_request(&post, false).pass.is_some()); + + let mut malformed = request("/rezerwa/15", None, &[]); + malformed.headers.insert(http::header::COOKIE, + HeaderValue::from_static("SESSabc=parent; BROKEN")); + let result = compiled.evaluate_request(&malformed, false); + assert!(result.pass.is_some()); + let mut forwarded = malformed.headers.clone(); + result.rewrite_cookies(&mut forwarded); + assert_eq!(forwarded.get("cookie"), malformed.headers.get("cookie")); + } + + #[test] + fn cookie_prefix_selectors_reject_unsafe_wildcard_syntax() { + let vcl = import_vcl(r#"sub vcl_recv { + remove_req_cookies("SESS*", "SSESS*", "_ga"); + }"#).unwrap(); + assert!(vcl.warnings.is_empty()); + validate_rules(&vcl.rules, false).unwrap(); + + // A dot in a selector is a literal cookie-name character, not a regex. + let literal_dot = import_vcl(r#"sub vcl_recv { + remove_req_cookies("SESS.*"); + }"#).unwrap(); + validate_rules(&literal_dot.rules, false).unwrap(); + + for invalid in ["*", "s*", "se*", "SE*SS", "SESS**", "SESS?", "SESS[0-9]*", ""] { + let rule_json = serde_json::json!({"id": "invalid", "actions": [ + {"type": "remove_named_cookies", "names": [invalid]} + ]}); + assert!(validate_rules(&[rule(rule_json)], false).is_err(), "{invalid}"); + } + } + } diff --git a/src/cache/vcl.rs b/src/cache/vcl.rs index afa5298..da5db35 100644 --- a/src/cache/vcl.rs +++ b/src/cache/vcl.rs @@ -606,13 +606,13 @@ fn vcl_actions( Err(format!("set {target} is not supported")) } } - // RustProxy-specific, safe exact-name Cookie removal (not stock Varnish VCL). + // RustProxy-specific exact-name / trailing-* Cookie removal (not stock Varnish VCL). (RuleStage::Request, "remove_req_cookies") => { if tokens.len() < 4 || !matches!(tokens.get(1), Some(VclToken::Sym("("))) || !matches!(tokens.last(), Some(VclToken::Sym(")"))) { - return Err("remove_req_cookies requires quoted cookie names".into()); + return Err("remove_req_cookies requires quoted cookie names or prefix* selectors".into()); } let args = &tokens[2..tokens.len() - 1]; if args.len() % 2 == 0 {