Skip to content

Send cookies and headers to your site - #12

Merged
birazzzz merged 1 commit into
mainfrom
feat/cookies-headers
Oct 25, 2026
Merged

birazzzz merged 1 commit into
mainfrom
feat/cookies-headers

Conversation

@birazzzz

Copy link
Copy Markdown
Collaborator

Why

wrapguard sees whatever the server hands it. A site running an A/B test can serve a different variant to the baseline run and the PR check, and a preview deployment behind protection, or a page behind a sign-in, can't be reached at all. Someone asked about exactly this on the launch thread.

What

"cookies": { "hero-test": "b" },
"headers": { "x-feature-flags": "new-pricing" }
  • Config: both are maps of names to values. A value that isn't text stops with the key it belongs to (`cookies.session` must be text, not undefined), which is what an unset environment variable in a JS config looks like. Both need an http(s) baseUrl.
  • Only your site gets them. Cookies are set for the host in baseUrl. Headers go through a context.route that only matches baseUrl's origin, rather than extraHTTPHeaders, which would send them to fonts, analytics and every other host. Headers can hold a token.
  • Sitemap: reading it sends them too, so a protected preview works end to end.
  • README: a "Cookies and headers" section (pinning a variant, one config per variant, secrets from environment variables), config table rows, --config in the command list, and the sign-in limit now points at a session cookie.

Trade-off: Playwright turns off its HTTP cache while a route is set, so runs with headers may be a little slower. Runs without them are unchanged.

Checked

  • 48 tests, 3 new in test/site.test.ts, against two local servers:
    • the page shows the cookie and header it received (variant b, cookie hero-test=b)
    • a stylesheet on another origin never gets the header (with the route changed to match every host, this test fails)
    • the sitemap answers 401 without the header and lists its page with it
    • config defaults to {} and rejects a non-text value, a list, and a file:// baseUrl
  • tsc --noEmit clean

Not released. This would go out as 0.3.0 (new config options).

For pinning an A/B variant, turning on a feature flag, or getting past a
preview deployment's protection.

- `cookies` and `headers` in the config, each a map of names to values.
  A value that isn't text (usually an unset environment variable) stops
  with the cookie or header it belongs to. Both need an http(s) baseUrl.
- Cookies are set for the host in baseUrl. Headers go through a route that
  only matches baseUrl's origin, not `extraHTTPHeaders`, so fonts,
  analytics and other hosts never get them.
- Reading the sitemap sends them too.
- README: a "Cookies and headers" section, config rows, `--config` in the
  command list, and a session cookie as the way onto signed-in pages.
@birazzzz
birazzzz merged commit f69b966 into main Oct 25, 2026
3 checks passed
@birazzzz birazzzz mentioned this pull request Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant