-
Notifications
You must be signed in to change notification settings - Fork 30
Description
I see that the middleware is ignoring websocket requests here:
traefik-modsecurity-plugin/modsecurity.go
Line 56 in 19cdb47
| if isWebsocket(req) { |
Why is that? A request for WebSocket is actually a valid HTTP request, which may contains spurious/malicious data.
Also, there is another problem with this technique: an attacker can send a Upgrade header while issuing a normal request to any web page, as the server can ignore the Upgrade header for any reason (e.g. no websocket is expected?) and continue to process the request as if the header does not exists. Which means that an attacker can add the Upgrade header to any request to bypass the security check.
I didn't test the code with WebSockets, so I don't know if there is any issue (probably something with the body?). In that case I propose two possible solutions:
- have a configuration parameter where WebSocket endpoints can be specified; or
- when a websocket is detected, the body buffering is skipped, and the request to the mod-security backend will be made without body
The 2nd solution is less secure, as we're still skipping the body in presence of an header, but we don't know if there is any WebSocket or not. So I prefer the 1st.
I may contribute in few weeks if you like, I'm quite busy at the moment :-)