middleware: test ClientIPFromHeader does not fall back to other headers (#1208)
This commit is contained in:
parent
fff8bb28cb
commit
c9744a3641
1 changed files with 12 additions and 0 deletions
|
|
@ -527,6 +527,18 @@ func TestAdvisory_GHSA_rjr7_jggh_pgcp(t *testing.T) {
|
|||
t.Errorf("want 203.0.113.7 (the only trusted header), got %q", got)
|
||||
}
|
||||
})
|
||||
|
||||
// When the opted-in header is absent, ClientIPFromHeader must not fall
|
||||
// back to other attacker-supplied headers; it leaves no client IP set.
|
||||
t.Run("no_fallback_when_opted_in_header_missing", func(t *testing.T) {
|
||||
got := run(t, ClientIPFromHeader("X-Real-IP"), func(r *http.Request) {
|
||||
r.Header.Set("True-Client-IP", "1.1.1.1") // attacker-supplied; ignored.
|
||||
r.Header.Set("X-Forwarded-For", "2.2.2.2") // attacker-supplied; ignored.
|
||||
})
|
||||
if got != "" {
|
||||
t.Errorf("VULNERABLE: fell back to attacker-supplied header, got %q", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// GHSA-j6qf-3m9c-vwj3 (tenbbughunters): ClientIPFromXFF never checked that
|
||||
|
|
|
|||
Loading…
Reference in a new issue