This commit is contained in:
Mateusz Gruszczyński committed 2026-11-26 08:50:30 +01:00
1 parent 167861fc16
commit aa0a271a1c
38 files changed
+3642 -1058

No files matched your search

+119 -2
View File
@@ -18,8 +18,9 @@ below. VCL remains the owner of its existing cache-rule precedence and terminal
- In the panel, open **Settings → Rules & headers → HTTP policies** globally,
**Vhost → Headers → HTTP policies**, the location's **HTTP policies** section,
or the Docker assignment's policy section. The shared editor offers a rule
builder, a JSON view, import preview and a draft tester. Reordering uses the
visible rule order; switching views preserves the same policy object.
builder, scenario presets, a JSON view, import preview and a draft tester.
Global settings use the same editor at `settings?tab=policies`. Reordering uses
the visible rule order; switching views preserves the same policy object.
- Set `policy` in the complete configuration, `vhosts[].policy`, or
`vhosts[].routes[].policy`. A Docker assignment stores its policy with that
assignment so discovery does not discard the customization.
@@ -39,6 +40,122 @@ headless test after adjusting its backend address. The
[cooperation example](../examples/policy-vcl-cooperation.json) demonstrates a
request classification consumed by VCL-style cache rules.
## Scenario presets and the rule builder
Since 0.42.1, **Scenario presets** beside **Add HTTP rule** opens a searchable catalog
grouped by headers, cache, security, routing and diagnostics. Select a scenario
to read its purpose and application notes; **Preview rules** shows its policy
data. **Add scenario** appends the complete scenario to the current draft with
unique rule IDs. It keeps the existing rules, ACLs and maps. Nothing is activated
until the containing Settings, Vhost, Docker assignment or location form is
saved. The **Documentation** button in the editor toolbar opens this guide;
Vhosts and global settings use the same control.
The catalog contains **40 scenarios built from 54 rules**. Global and Vhost
editors offer all 40. Location editors offer 39: the prefix rewrite uses
`pre_route`, which runs before a location has been selected.
### General scenarios
The following recipes create enabled draft rules, except the disabled legacy
redirect. They still require saving the containing form to become active.
| Scenario | Effect and review points |
| --- | --- |
| Normalize `Vary` | Normalize the final token list, keeping existing dimensions and `*`. |
| Exact duplicate `Vary` | Match the two full fields in the [original example](#exact-duplicate-vary-rule) and replace only that exact combination before cache planning. |
| Hide origin headers | Remove `Server`, `X-Powered-By` and `X-AspNet-Version` from the final response. |
| Basic security headers | Add `X-Content-Type-Options: nosniff` and `Referrer-Policy: strict-origin-when-cross-origin` only when missing; application-provided values remain in place. |
| Private routes | Bypass shared lookup/storage and send private/no-store response headers on common account, administration and checkout paths. Adjust the path list. |
| Authorization bypass | Bypass shared caching when an `Authorization` header is present and send private/no-store response headers. |
| Cookie bypass | Bypass shared caching when a `Cookie` header is present and send private/no-store response headers. This also excludes anonymous requests with tracking cookies. |
| Responses with `Set-Cookie` | Prevent storage of matching origin responses without deleting the cookie; send `Cache-Control: private, no-store`. |
| Error responses | Prevent storage of origin responses with status `400`–`599`; send `Cache-Control: no-store` on final error responses. |
| Health endpoints | Keep common health/readiness paths out of shared caching and mark their responses no-store. Adjust the paths to match your service. |
| Server-sent events | Bypass shared cache for `Accept: text/event-stream`; prevent storage and disable RustProxy compression for event-stream responses. This does not remove origin compression. |
| Block unwanted methods | Return `403` for `TRACE` and `CONNECT`; review them against protocols used by the service. |
| Block sensitive files | Return `403` for literal `.env`, `.env.*`, `.git`, `.svn` and `.hg` path segments. The pattern leaves `.well-known` available and does not cover all encoded aliases. |
| Request correlation | Add the transaction request ID as `X-Correlation-ID` at final delivery when absent; preserve application correlation IDs. |
| Legacy path redirect | Add a disabled exact `/old-path` → `/new-path` redirect with status `302`. Edit the paths and enable the rule; this example drops the original query string. |
### Application and API scenarios
**Off** means the scenario is added with every rule disabled. Edit its example
domains, paths, networks or values, enable the required rules, then save. Keep
the order of a scenario containing several rules.
| Scenario | Added state | Effect and review points |
| --- | --- | --- |
| Language variants | Off | Merge `Accept-Language` into `Vary` before cache planning for `/localized/`; use only when the origin actually varies its response by that header. |
| CORS for one frontend | Off | On `/api/`, remove previous allowed-origin/credentials headers, allow the fixed `https://app.example.test` origin, and merge `Origin` into `Vary` for all matching responses. |
| CORS exposed headers | On | Merge `ETag` and `X-Correlation-ID` into `Access-Control-Expose-Headers` only when an allowed-origin response header already exists. Does not grant CORS access or create those diagnostic headers. |
| Internal redirect locations | Off | Replace the configured internal HTTP host in `3xx` `Location` fields with a fixed public HTTPS host, preserving the captured path/query. Does not rewrite page content. |
| Download attachments | Off | Set `Content-Disposition: attachment` on successful responses under `/downloads/`; edit the path. No filename or access permission is generated. |
| Same-origin framing | Off | Add `X-Frame-Options: SAMEORIGIN` when missing. Review embedded applications and any existing CSP `frame-ancestors` directive. |
| Trial HSTS | Off | Add missing `Strict-Transport-Security: max-age=300` only on the actual TLS listener; no `includeSubDomains` or `preload`. Verify HTTPS first. |
| Browser device permissions | Off | Add missing `Permissions-Policy` denying camera, microphone and geolocation; remove restrictions required by the application. |
| CSP report-only audit | Off | Add a missing report-only CSP for self-hosted resources, no objects and a self-only base URI. Review browser-console violations; no report endpoint is configured. |
| Staging noindex | Off | Send `X-Robots-Tag: noindex, nofollow` throughout the selected scope. This is crawler advice, not authentication. |
| Cross-site write requests | Off | Deny `POST`, `PUT`, `PATCH` and `DELETE` carrying `Sec-Fetch-Site: cross-site`. Keep application CSRF protection; clients without that header are unaffected. |
| JSON API writes | Off | Require exactly one `Content-Type` field declaring `application/json` or `application/*+json` for `POST`, `PUT` and `PATCH` below `/api/`, otherwise return `415`. Missing or duplicate fields are rejected. This checks headers, not body validity. |
| Internal path by client network | Off | Deny `/internal` outside the configured trusted client-IP CIDR. Replace the example `203.0.113.0/24` and path before enabling. |
| Preview/draft query parameters | Off | Bypass lookup/storage and send private/no-store when literal `preview` or `draft` query names exist, even with empty or false values. Does not authorize draft access. |
| Signed/token URLs | Off | Bypass lookup/storage for configured literal signing/token query names. The application still validates the signature and expiry. |
| HTML revalidation | On | Add `Cache-Control: no-cache` only to HTML responses lacking `Cache-Control`. Existing privacy directives remain; the shared object's TTL is unchanged. |
| Public API TTL/grace | Off | Set 60-second TTL and 30-second grace defaults for explicitly public `/api/public` responses without `Set-Cookie`, `private`, `no-cache` or `no-store`. Requires enabled cache. |
| Canonical host | Off | Redirect a configured alias to a fixed HTTPS hostname with `308`, preserving path, query and method. Edit both domains and verify the certificate. |
| HTTP to HTTPS for one host | Off | Redirect the configured host with `308` when received without TLS. Uses listener TLS, not forwarding headers; review external TLS termination to avoid loops. |
| Remove a path prefix | Off | Rewrite `/legacy/…` to `/…` in `pre_route`, retaining query parameters. Review routing/access for the resulting path; available globally and on Vhosts only. |
| Move a URL subtree | Off | Redirect `/docs-old/…` to `/docs/…` with `308`, preserving the rest of the path, query and method. Edit the condition and replacement together. |
| Maintenance response | Off | Return a local `503` after access/authentication checks and add `Retry-After: 300` using a transaction marker. Enable both rules together; the initial condition covers the whole scope. |
| Selected API backend | Off | Send `/api-v2/` to an existing backend member ID. Set the real ID before enabling; backend selection bypasses shared cache. Global use requires that member in each affected Vhost. |
| Cache outcome header | On | Add missing `X-Cache` from `cache_status` at final delivery. Preserves an application header and does not change cache decisions. |
| API/web classification | Off | Set `txn.ui_request_class` to `web` or `api`, then expose it as `X-Request-Class` at delivery. Edit `/api/` and retain all three rules in order; the label is not a trusted identity. |
The CORS recipe configures **response headers only**. The application must handle
`OPTIONS` preflight and authentication. The recipe does not allow credentialed
browser requests or reflect an arbitrary request origin. Enable both rules
together so every applicable response retains `Vary: Origin`.
The public-API TTL/grace recipe does not force cache lookup or weaken credential
and storage privacy checks. Existing VCL TTL/grace assignments take precedence.
Its backend-response stage retains the background-refresh restrictions below.
`no-cache` in the HTML recipe means revalidation, not a prohibition on storage.
Presets are editable starting points; they do not install authentication or
replace existing access rules.
For global policies, review the effects across every affected Vhost. Response
storage rules do not purge existing cache entries or run the backend-response
stage on a HIT. Backend-response rules also retain the background-refresh
restrictions described under [cache boundaries](#actions-and-cache-boundaries).
For the event-stream preset, clients must send `Accept: text/event-stream` to
bypass any existing cache entry before the origin's response type is known.
### Add and inspect conditions
Open a rule's conditions, enter a sample expression, choose an operator and
enter one comparison value per line. **Add condition** commits those fields to
the rule and updates its visible condition list/count. The initial sample is
`path` with a prefix comparison; enter the intended path before adding it.
Choose **AND** to require both the existing condition and the new comparison,
or **OR** to allow either. Existing nested expressions remain grouped.
The builder checks for missing samples/values, invalid numeric values and
condition/value limits before adding a comparison. **exists** takes no values;
case-insensitive matching applies to text comparisons, not numeric, CIDR or
existence tests. **Advanced condition JSON** remains available for nested
AND/OR/NOT expressions and named ACL references. Invalid JSON must be corrected
before switching views or applying changes that would rebuild the editor.
The server still validates sample syntax, stage compatibility and the complete
policy before activation.
Action choices follow the selected stage. **Stop this scope's stage after
matching** has its own row below the stage settings; it ends only the matching
scope's chain at that stage. Policy on/off controls follow **Show on/off settings
as switches** in Appearance, including dynamically added rules and conditions.
The same behavior applies in global settings, Vhosts, Docker assignments and
locations.
## Stages and existing rules
| Stage | Runs when | Relationship to VCL and existing headers |