Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1740ac6061 | ||
|
|
6e370b346b |
No files matched your search
@@ -2326,7 +2326,8 @@ but for these headers:
|
|||||||
claims and are replaced. `X-Forwarded-For` names the peer, `X-Forwarded-Host`
|
claims and are replaced. `X-Forwarded-For` names the peer, `X-Forwarded-Host`
|
||||||
the host it asked for, and `X-Forwarded-Proto` plain `http`. Every other
|
the host it asked for, and `X-Forwarded-Proto` plain `http`. Every other
|
||||||
header whose name starts with `X-Forwarded-` is removed, and so are
|
header whose name starts with `X-Forwarded-` is removed, and so are
|
||||||
`Forwarded` and `X-Real-IP`.
|
`Forwarded` and `X-Real-IP`. A name spelt with `_` for `-`, such as
|
||||||
|
`X_Forwarded_Ssl`, counts as the same name.
|
||||||
- `X-Request-ID`, which carries the fresh id.
|
- `X-Request-ID`, which carries the fresh id.
|
||||||
- `X-Client-ASN` and `X-Client-Country`, which carry what `waf` answered. A
|
- `X-Client-ASN` and `X-Client-Country`, which carry what `waf` answered. A
|
||||||
header it did not give is left out. Any of the two the visitor sent is
|
header it did not give is left out. Any of the two the visitor sent is
|
||||||
|
|||||||
@@ -105,17 +105,16 @@ func setForwardedHeaders(in, out *http.Request, peer netip.Addr, trusted bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReverseProxy has removed Forwarded and the three set below. Go's server
|
// An app behind CGI or FastCGI reads X_Forwarded_Ssl as X-Forwarded-Ssl, so
|
||||||
// gives header names in canonical form, so the prefix matches the name in
|
// a name is matched with each _ read as - and in any letter case.
|
||||||
// any letter case.
|
|
||||||
for name := range out.Header {
|
for name := range out.Header {
|
||||||
if strings.HasPrefix(name, "X-Forwarded-") {
|
spelt := strings.ToLower(strings.ReplaceAll(name, "_", "-"))
|
||||||
|
if strings.HasPrefix(spelt, "x-forwarded-") ||
|
||||||
|
spelt == "forwarded" || spelt == "x-real-ip" {
|
||||||
delete(out.Header, name)
|
delete(out.Header, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Header.Del("X-Real-IP")
|
|
||||||
|
|
||||||
out.Header.Set("X-Forwarded-For", forwardedFor)
|
out.Header.Set("X-Forwarded-For", forwardedFor)
|
||||||
out.Header.Set("X-Forwarded-Host", in.Host)
|
out.Header.Set("X-Forwarded-Host", in.Host)
|
||||||
out.Header.Set("X-Forwarded-Proto", "http")
|
out.Header.Set("X-Forwarded-Proto", "http")
|
||||||
|
|||||||
@@ -561,6 +561,7 @@ func TestAPeerNotTrustedHasItsForwardedHeadersReplaced(t *testing.T) {
|
|||||||
"X-Forwarded-Tls-Client-Cert-Info", "X-Real-Ip",
|
"X-Forwarded-Tls-Client-Cert-Info", "X-Real-Ip",
|
||||||
"X-Forwarded-Scheme", "X-Forwarded-Ssl", "X-Forwarded-Protocol",
|
"X-Forwarded-Scheme", "X-Forwarded-Ssl", "X-Forwarded-Protocol",
|
||||||
"X-Forwarded-Path", "X-Forwarded-Client-Cert",
|
"X-Forwarded-Path", "X-Forwarded-Client-Cert",
|
||||||
|
"X_Forwarded_Ssl", "X_Forwarded_Proto", "X_Real_IP",
|
||||||
}
|
}
|
||||||
|
|
||||||
standIn := startWAF(t, allow)
|
standIn := startWAF(t, allow)
|
||||||
@@ -628,6 +629,7 @@ func TestATrustedProxysForwardedHeadersPassOn(t *testing.T) {
|
|||||||
forwardedProtoHeader: "https",
|
forwardedProtoHeader: "https",
|
||||||
"X-Real-Ip": "198.51.100.1",
|
"X-Real-Ip": "198.51.100.1",
|
||||||
"X-Forwarded-Ssl": "on",
|
"X-Forwarded-Ssl": "on",
|
||||||
|
"X_Forwarded_Ssl": "on",
|
||||||
}
|
}
|
||||||
|
|
||||||
req := newRequest(t, http.MethodGet, addr, "/", http.NoBody)
|
req := newRequest(t, http.MethodGet, addr, "/", http.NoBody)
|
||||||
|
|||||||
@@ -507,8 +507,9 @@ func TestAStatusWAFDoesNotTakeIsReportedAs599(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// startRProxyProcess runs `sww rproxy` in a process of its own, with the
|
// startRProxyProcess runs `sww rproxy` in a process of its own, with the
|
||||||
// settings in env, each as NAME=value. It returns where rproxy listens, and
|
// settings in env, each as NAME=value. It returns where rproxy listens and a
|
||||||
// what stops it as SIGTERM does, which checks that it stopped in order.
|
// function that sends rproxy SIGTERM and fails the test unless it exits with
|
||||||
|
// status 0 within waitLimit.
|
||||||
func startRProxyProcess(t *testing.T, env ...string) (string, func()) {
|
func startRProxyProcess(t *testing.T, env ...string) (string, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -526,17 +527,7 @@ func startRProxyProcess(t *testing.T, env ...string) (string, func()) {
|
|||||||
"SWRP_LISTEN_ADDR="+localhost+":0")
|
"SWRP_LISTEN_ADDR="+localhost+":0")
|
||||||
cmd.Env = append(cmd.Env, env...)
|
cmd.Env = append(cmd.Env, env...)
|
||||||
|
|
||||||
err = cmd.Start()
|
exited := startProcess(t, cmd)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("start: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
exited := make(chan int, 1)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
_ = cmd.Wait()
|
|
||||||
exited <- cmd.ProcessState.ExitCode()
|
|
||||||
}()
|
|
||||||
|
|
||||||
addr, _ := out.lineBeforeExit(t, "starting", exited)["address"].(string)
|
addr, _ := out.lineBeforeExit(t, "starting", exited)["address"].(string)
|
||||||
|
|
||||||
|
|||||||
+30
-11
@@ -38,6 +38,35 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(sww.Main(testVersion))
|
os.Exit(sww.Main(testVersion))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// startProcess starts cmd and returns a channel that gets its exit status. As
|
||||||
|
// the test ends, cmd is killed and the test waits for it to exit.
|
||||||
|
func startProcess(t *testing.T, cmd *exec.Cmd) <-chan int {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
err := cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("start: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
exited := make(chan int, 1)
|
||||||
|
waitReturned := make(chan struct{})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
_ = cmd.Wait()
|
||||||
|
exited <- cmd.ProcessState.ExitCode()
|
||||||
|
|
||||||
|
close(waitReturned)
|
||||||
|
}()
|
||||||
|
|
||||||
|
t.Cleanup(func() {
|
||||||
|
_ = cmd.Process.Kill()
|
||||||
|
|
||||||
|
<-waitReturned
|
||||||
|
})
|
||||||
|
|
||||||
|
return exited
|
||||||
|
}
|
||||||
|
|
||||||
func TestMainRunsWAF(t *testing.T) {
|
func TestMainRunsWAF(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -67,17 +96,7 @@ func TestMainRunsWAF(t *testing.T) {
|
|||||||
rulesDir+"="+t.TempDir(),
|
rulesDir+"="+t.TempDir(),
|
||||||
lookupSource+"=off")
|
lookupSource+"=off")
|
||||||
|
|
||||||
err = cmd.Start()
|
exited := startProcess(t, cmd)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("start: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
exited := make(chan int, 1)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
_ = cmd.Wait()
|
|
||||||
exited <- cmd.ProcessState.ExitCode()
|
|
||||||
}()
|
|
||||||
|
|
||||||
starting := out.lineBeforeExit(t, "starting", exited)
|
starting := out.lineBeforeExit(t, "starting", exited)
|
||||||
addr, _ := starting["address"].(string)
|
addr, _ := starting["address"].(string)
|
||||||
|
|||||||
Reference in new issue
Block a user