Skip to content

Commit 4073808

Browse files
Allow the agent to issue redirects.
1 parent c0e10cb commit 4073808

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

module.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,25 @@ func (m *Module) ServeHTTP(w http.ResponseWriter, req *http.Request) {
122122
wafresponse := out.WAFResponse
123123
switch {
124124
case m.config.IsAllowCode(int(wafresponse)):
125-
// continue with normal request
125+
// Continue with normal request
126126
m.handler.ServeHTTP(rw, req)
127127
case m.config.IsBlockCode(int(wafresponse)):
128128
status := int(wafresponse)
129+
130+
// Only redirect if it is a redirect status (3xx) AND there is a redirect URL
131+
if status >= 300 && status <= 399 {
132+
redirect := req.Header.Get("X-Sigsci-Redirect")
133+
if len(redirect) > 0 {
134+
http.Redirect(rw, req, redirect, status)
135+
break
136+
}
137+
}
138+
139+
// Block
129140
http.Error(rw, fmt.Sprintf("%d %s\n", status, http.StatusText(status)), status)
130141
default:
131142
log.Printf("ERROR: Received invalid response code from inspector (failing open): %d", wafresponse)
132-
// continue with normal request
143+
// Continue with normal request
133144
m.handler.ServeHTTP(rw, req)
134145
}
135146

0 commit comments

Comments
 (0)