Commit 101a7ac
authored
fix(server): let batch request headers win over sub-request headers (#1912)
The batch handler's default `mapSubrequest` merged the batch root
request headers into each sub-request but let the sub-request win on
collision. That order is now flipped, so the batch request headers take
priority.
The batch root request is the only part the transport actually saw. Its
headers are set by the browser (`cookie`, `origin`, `sec-fetch-*`) or by
a proxy (`x-forwarded-for`, `authorization`), while a sub-request is
client-controlled request payload. A sub-request can no longer overwrite
them.
## Compatibility
With the default `BatchLinkPlugin`, behavior is unchanged. Its batch
headers are the headers common to every sub-request, and its default
`mapSubrequest` strips those from each sub-request, so the two sets
never collide. Only setups with a custom client `headers` option, or a
hand-rolled client, that deliberately set a per-sub-request override of
a batch-level header are affected. They can restore the old merge
through the `mapSubrequest` option.
## Testing
`packages/server`, `packages/client`, and the root `tests/` suites pass,
along with `pnpm lint` and `pnpm type:check`. The existing header-merge
test now asserts the new precedence, and a spoofing test covers a
sub-request trying to override an `authorization` header carried by the
batch request.1 parent 3ff7f48 commit 101a7ac
2 files changed
Lines changed: 21 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | | - | |
| 418 | + | |
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
422 | 433 | | |
423 | 434 | | |
424 | 435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | | - | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
107 | 113 | | |
108 | 114 | | |
109 | 115 | | |
| |||
0 commit comments