Skip to content

Commit 0c658f2

Browse files
committed
fix: do not forward webscoket requests to ModSecurity
owasp-modsecurity/ModSecurity#1368 Currently ModSecurity is not capable to inspect WebSockets. It is only capable to understand the http requests.
1 parent f6dbf18 commit 0c658f2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

modsecurity.go

+15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
4747

4848
func (a *Modsecurity) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
4949

50+
// Webscoket not supported
51+
if isWebsocket(req) {
52+
a.next.ServeHTTP(rw, req)
53+
return
54+
}
55+
5056
// we need to buffer the body if we want to read it here and send it
5157
// in the request.
5258
body, err := ioutil.ReadAll(req.Body)
@@ -84,3 +90,12 @@ func (a *Modsecurity) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
8490

8591
a.next.ServeHTTP(rw, req)
8692
}
93+
94+
func isWebsocket(req *http.Request) bool {
95+
for _, header := range req.Header["Upgrade"] {
96+
if header == "websocket" {
97+
return true
98+
}
99+
}
100+
return false
101+
}

0 commit comments

Comments
 (0)