You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b8d95f3
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: .agents/http/key.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ Apply the method component to **both** key branches. A custom `getKey` defines c
22
22
23
23
Without authority, one handler instance that serves several hostnames stores one entry per path for all hosts. This is a normal nitro/h3 virtual-host deployment. Tenant A's rendering could be served to tenant B. h3#1524 finding #2 found this cross-application body leak. Per-instance storage closed it between processes but not between hosts in one instance. An attacker-controlled `Host` could also enter an absolute URL in a rendered canonical link, `Location`, or password-reset link. The shared key then stored that URL and advertised synthesized `s-maxage` to shared CDNs. The old mitigation, `varies: ["host"]`, was disabled by default. It also did nothing on adapters that omit `Host` from `req.headers`.
24
24
25
-
Derive authority from `event.url`, which the adapter resolved. **Never** read it from the `Host` header. If an adapter builds `url` from that header, a reverse proxy must still normalize it. Put authority in the hashed component, not in the human-readable `_pathname` prefix. `_pathname` exists only for debugging. Hash authority and `_path` as a **tuple** so no code can interpret the boundary in two ways. An opaque-scheme pathname does not need to start with `/`. This was a breaking key change, so GET keys moved once.
25
+
Derive authority from `event.url`, which the adapter resolved. **Never** read it from the `Host` header. Narrowing closes the reverse gap by rewriting the handler-visible `Host` to this authority's host; see `.agents/http/request.md`. If an adapter builds `url` from that header, a reverse proxy must still normalize it. Put authority in the hashed component, not in the human-readable `_pathname` prefix. `_pathname` exists only for debugging. Hash authority and `_path` as a **tuple** so no code can interpret the boundary in two ways. An opaque-scheme pathname does not need to start with `/`. This was a breaking key change, so GET keys moved once.
26
26
27
27
`authority(url)` prefers `url.origin` because it canonicalizes values by lowercasing the host and removing a default port. For every **opaque** origin, `url.origin` is the literal string `"null"`. This includes non-special schemes that contain a real authority but do not expose it. For example, `new URL("x-proxy://a.example/p").origin === "null"`, as it does for `b.example`. In this case, use `${protocol}//${host}`. Otherwise, the cross-host collision returns. Authority-less schemes such as `file:`, `data:`, and `about:` use one constant per scheme. This is correct because their identity is entirely in the path, which the tuple also hashes.
Copy file name to clipboardExpand all lines: .agents/http/request.md
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Return bypassed responses without changes. `serialize` runs outside the resolver
16
16
17
17
## What the handler sees
18
18
19
-
The header filter is an **allowlist**. A header reaches the handler only when it appears in `keyHeaderNames`, is `cookie` under the three-way rule below, or appears in `safeHeaderNames`. Remove every other header on cacheable calls.
19
+
The header filter is an **allowlist**. A header reaches the handler only when it appears in `keyHeaderNames`, is `cookie` under the three-way rule below, or appears in `safeHeaderNames`. Remove every other header on cacheable calls.`host` is the one rewritten name: narrowing replaces its value with the keyed URL authority.
20
20
21
21
Forward `varies` headers. Their values are part of the key, so the handler can safely read them. Reading them is the reason to declare them. Earlier code removed declared `varies` headers instead of forwarding them. For example, `varies: ["accept-language"]` produced separate keys and correct `Vary`, but every entry contained the default rendering. Correct forwarding was therefore a breaking behavior change.
22
22
@@ -30,10 +30,17 @@ This rule is the request-side counterpart to `hasUnkeyedVary` in `.agents/http/r
30
30
31
31
`filters.ts` defines these exemptions beside the cookie and query filters. No module may create its own list. Each exempt header cannot vary a rendering and cannot usefully be placed in `varies`:
32
32
33
-
-**`host`** is already covered by the URL authority that `resolveKey` hashes.
34
33
-**`if-none-match` / `if-modified-since`** remain visible because `defaultHandleCacheHeaders` reads them from `event.req` in `http/index.ts` after narrowing replaces that request. If narrowing removed them, 304 responses worked on a HIT but never on a MISS. They are safe to forward. The only conditional responses that a handler can derive from them are 304 and 412, and those statuses are not in `cacheableStatuses`. The cache never stores such output.
35
34
-**`traceparent`, `tracestate`, `x-request-id`, `x-correlation-id`** support logging and trace propagation. They are unique per request by design. Adding one to `varies` would create one entry per request, so no useful keyed configuration exists. A handler that renders one into output creates data that no cache key can cover.
36
35
36
+
### `host`
37
+
38
+
`host` is **not** in `safeHeaderNames`. Narrowing removes the raw header and sets `host` to `(event.url ?? new URL(event.req.url)).host` — the host component of the very authority `resolveKey` hashes. A handler that renders a canonical link, an absolute asset URL, or a `Location` from `host` therefore renders from keyed data by construction.
39
+
40
+
The old exemption assumed the two always agree. They agree only on adapters that build the URL _from_`Host`. An adapter that resolves `event.url` from the connection, from a fixed base, or from a trusted proxy header leaves `Host` attacker-controlled and unkeyed. `Host: a.example` and `Host: b.example` on one resolved authority then shared an entry, and the first tenant's rendering was replayed under a synthesized `max-age` with no `Vary`. This is the same defect that `x-forwarded-host` has, reached through the one header the allowlist still exempted.
41
+
42
+
Normalizing, rather than removing, keeps host-dependent rendering working on the adapters where it was already correct. An authority-less URL (`file:`, `data:`) has no host to give, so the handler sees none. `varies: ["host"]` still puts `host` in `keyHeaderNames`; the raw header is then keyed, so narrowing forwards it unchanged and skips normalization.
43
+
37
44
Do **not** exempt `user-agent` or `baggage`. Device and bot branching commonly use `user-agent`. OTel `baggage` is designed for application values such as tenant IDs and feature flags. This differs from the opaque `traceparent` and `tracestate` pair. Declare both headers in `varies` when they affect output.
ocachedoesnotremoveasmallsetofheadersbecauseacachekeycannotusefullycoverthem. Theseare`If-None-Match`and`If-Modified-Since`, whichocacheusesfor [`304`](#conditional-requests--304),andthetraceheaders`traceparent`, `tracestate`, `X-Request-Id`, and`X-Correlation-Id`. `Host`alsostaysvisible, butwiththe [resolvedorigin's host](#multi-host-deployments) as its value rather than the raw one. `User-Agent` is **not** exempt. Output for different devices or bots needs separate keys. Add `User-Agent` to `varies` if you render from it.
0 commit comments