Commit 30ec3e6
authored
docs: warn about underscore header spoofing in NewRequestWithContext (#2460)
## What
Document that `NewRequestWithContext` does not strip request headers
whose name contains an underscore.
## Why
CGI maps dashes to underscores (`Foo-Bar` becomes `HTTP_FOO_BAR`), so a
client-supplied `Foo_Bar` header is indistinguishable from a legitimate
`Foo-Bar` in `$_SERVER` and can spoof it. This affects any such header
an application or upstream proxy trusts (forwarded-for, auth, etc.).
The Caddy-based server and reverse proxies like nginx
(`underscores_in_headers off`) already drop these. Callers using the Go
API directly must do it themselves unless they explicitly whitelist
them.
## Changes
- Doc comment on `NewRequestWithContext` explaining the risk and
mitigation.
- `ExampleServeHTTP` now drops underscore headers before building the
request.1 parent 64bb386 commit 30ec3e6
2 files changed
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
64 | 73 | | |
65 | 74 | | |
66 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
813 | 823 | | |
814 | 824 | | |
815 | 825 | | |
| |||
0 commit comments