## Problem Builder page navigation, Authentication, and HTTP response headers used different path matchers from published Remix pages. For example, Builder did not select a `/docs/*` page at `/docs`, and a request for `/%64ocs` could reach the `/docs` page without matching its Authentication rule. ## Change - Use Remix's framework-independent router for page selection and project path rules. Adapt Webstudio named splats and preserve encoded static path segments. - Keep Authentication's first matching rule and Headers' ordered application of every matching rule. - Preserve previously saved encoded literals such as `/%2A`, `/%3F`, and `/%3Aid`. They match only their literal encoded pathname and cannot become wildcards or parameters. Previously accepted malformed encoding remains a literal path. - Replace Builder's separate route ranking and URLPattern matcher. URLPattern remains for page path validation and path editing. - Use the request URL for the project-domain authentication exemption instead of trusting `x-forwarded-host`. Generated HTML, XML, and text routes share one authentication helper. - Extend the HTTP headers guide and shared path pattern reference with matching behavior, an iframe example, and verification steps. ## Validation - Authentication package: 88 tests. New regression cases cover saved Authentication and Headers rules, literal matching, route ranking, parameter values, and a marker collision attempt. The regressions failed before the fix and pass now. - Project build: 2,484 tests, including 214 route and redirect checks. SDK: 636 tests. CLI: 1,165 tests. Builder system: 5 tests. - Typechecks: Authentication, project build, Builder, SDK, and CLI. Lint, package boundaries, formatting, and diff checks pass. - The fixture pipeline completed and made no additional changes. The generated fixture files already changed by this PR remain included. - Staging project build 196 published successfully using the companion published-site Worker branch. The edge dispatcher was deployed from its staging branch to normalize forwarded hosts. Live HTTP checks covered base and child routes, dynamic pages, redirects, 404s, global headers, and route-scoped headers. The generated site challenged protected base and child paths, accepted the route password, and left public routes accessible. The project domain intentionally skips route-specific auth and has a separate staging Basic Auth gate, so the successful route-password request was checked in the generated production runtime. A forged `x-forwarded-host` no longer changes the hosted project-domain auth decision. - An initial CLI run alongside two other full suites timed out in one fixture API test; that test passed alone, and the full CLI suite passed when rerun alone. ## Compatibility - [x] Preserve previously accepted percent-encoded route literals before merging. - The old URLPattern test asserting that `/docs/*` does not match `/docs` was intentionally changed because the published Remix router does match the base path. Tests for the removed custom route sorter were replaced with router-selection tests. ## Rollout - [x] Migrate matching in this repository. - [x] Update user documentation. - [x] Verify package consumers and related code. - [ ] Merge [webstudio-saas#665](https://github.com/webstudio-is/webstudio-saas/pull/665) before releasing this PR. The current published-site Worker template imports the removed `matchesPathnamePattern` export; without the companion change, a published site fails at Wrangler build. - [ ] After publishing the new `@webstudio-is/wsauth` version, update the published-site Worker template’s pinned `0.301.0` dependency, remove the temporary fallback, and deploy the hosted Worker. Replaces #6482 so the review tracks the deployed `headers.staging` branch.
5.5 KiB
description
| description |
|---|
| Configure HTTP response headers and route-specific policies for a published site. |
HTTP response headers
HTTP response headers are metadata sent with a page response. Browsers and other clients use them to decide how to handle the response—for example, whether a page can appear inside an iframe, how to handle referrers, or how long to cache content. Headers are sent by the server; they are different from the visible content on your page and from HTML added to the page's <head>.
Use Project settings > Headers to add response header rules to your published site.
Add a header rule
- Open Project settings and select Headers.
- Enter a path pattern, a header name, and its value.
- Select Add.
- Publish your site for the rule to take effect.
To change a rule, remove it with the trash button and add it again with the updated values.
Header names are case-insensitive. Suggestions in the header-name field are common choices, not a complete allowlist; you can enter other valid header names too. Webstudio reserves platform-managed and connection-specific headers, as well as headers that describe response-body framing, such as Content-Length and Transfer-Encoding.
Choose which paths receive a header
The path pattern determines which page responses receive the rule. Headers use the same path pattern syntax as project-level Authentication. See Path patterns for the complete syntax, examples, and matching behavior.
Add separate rules to use the same header on different paths. If several matching rules set the same header, the last matching rule in the list wins. A route-specific value replaces the value that would otherwise apply to that response; write the full value you want the browser to receive.
Webstudio Cloud defaults
On Webstudio Cloud, responses receive these defaults when you have not configured the corresponding header:
| Header | Default value | Purpose |
|---|---|---|
Content-Security-Policy |
frame-ancestors 'self' |
Allows pages to be framed by the same site. |
X-Frame-Options |
SAMEORIGIN |
Legacy framing protection for same-origin embedding. |
Referrer-Policy |
strict-origin-when-cross-origin |
Limits referrer details sent to another origin. |
X-Powered-By, X-Content-Type-Options, and Strict-Transport-Security are managed by Webstudio Cloud and cannot be configured in this section.
On Webstudio Cloud, the defaults and custom headers on staging domains are free. Custom header rules on a custom domain require Pro.
Example: allow a trusted site to frame one page
By default, your pages can be framed by your own site. This helps protect visitors from clickjacking: an attacker could place your site inside a hidden or misleading frame and trick a visitor into clicking a control on your site without realizing it.
Sometimes a trusted analytics tool offers an iframe-based heatmap viewer. The viewer needs to display your page in a frame so it can place click data over the page. You can allow that viewer while leaving the rest of your site protected:
- Add a rule for the page you want the viewer to show, for example
/campaigns/spring. - Set the header name to
Content-Security-Policy. - Set its value to
frame-ancestors 'self' https://analytics.example.com, replacing the example origin with the exact origin of the trusted viewer. - Select Add and publish.
frame-ancestors lists the origins allowed to frame the page. Keep 'self' if your own site should still be allowed. If the page is nested inside more than one frame, every ancestor must be allowed by the policy. Use a route pattern such as /* only when the same embedding rule should apply across the entire site.
Webstudio also sends X-Frame-Options: SAMEORIGIN by default. Modern browsers ignore X-Frame-Options when an enforced CSP includes frame-ancestors, so the explicit CSP rule allows the trusted origin. Older browsers that do not support frame-ancestors may still follow X-Frame-Options and block external framing. See the CSP specification and MDN's frame-ancestors reference.
Publish and verify
Publish after adding or changing a rule. Then request the published page and inspect the response headers. For example:
curl -sS -D - -o /dev/null https://example.com/campaigns/spring
Check that the response includes the header and value you configured. Use a GET request as above; a HEAD request may not follow the same response path as a page load.
Hosting behavior and limits
Webstudio Cloud applies configured headers to site responses, including redirects and site errors. Static assets served by the CDN keep their existing headers.
If you export and host the site elsewhere, configure response headers with your hosting provider. The Headers settings do not automatically configure that host.
You can add up to 100 rules. Header values must be non-empty, cannot contain line breaks or characters outside Latin-1, and can be up to 8 KB; all rules combined are limited to 16 KB. Cookies, connection-specific headers, and response-body framing headers cannot be configured.