Skip to content

Commit

Permalink
fix: do not forward webscoket requests to ModSecurity
Browse files Browse the repository at this point in the history
owasp-modsecurity/ModSecurity#1368

Currently ModSecurity is not capable to inspect WebSockets. It is only capable to understand the http requests.
  • Loading branch information
Alexis COUVREUR committed Dec 28, 2021
1 parent 6152221 commit ab6af9a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modsecurity.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h

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

// Webscoket not supported
if isWebsocket(req) {
a.next.ServeHTTP(rw, req)
return
}

// we need to buffer the body if we want to read it here and send it
// in the request.
body, err := ioutil.ReadAll(req.Body)
Expand Down Expand Up @@ -84,3 +90,12 @@ func (a *Modsecurity) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

a.next.ServeHTTP(rw, req)
}

func isWebsocket(req *http.Request) bool {
for _, header := range req.Header["Upgrade"] {
if header == "websocket" {
return true
}
}
return false
}

0 comments on commit ab6af9a

Please sign in to comment.