diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-26 19:14:05 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-26 19:14:05 +0100 |
commit | fd3da82dd7772419c01bb751e5b5cb7f198b4752 (patch) | |
tree | a22034831ec31df68b4e9cb22a1c51949e41b613 /http.cpp | |
parent | 9b0320c8b47c43adce1aa5d9821b67c1fa42e1d6 (diff) |
websocket bugfix: socket leak
Diffstat (limited to 'http.cpp')
-rw-r--r-- | http.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -1,7 +1,6 @@ #include "http.h" #include "config.h" -#include "error.h" #include "server.h" #include "response.h" #include "websocket.h" @@ -46,6 +45,32 @@ using namespace Reichwein; namespace { + // Report a failure +void fail(boost::beast::error_code ec, char const* what) +{ + // ssl::error::stream_truncated, also known as an SSL "short read", + // indicates the peer closed the connection without performing the + // required closing handshake (for example, Google does this to + // improve performance). Generally this can be a security issue, + // but if your communication protocol is self-terminated (as + // it is with both HTTP and WebSocket) then you may simply + // ignore the lack of close_notify. + // + // https://github.com/boostorg/beast/issues/38 + // + // https://security.stackexchange.com/questions/91435/how-to-handle-a-malicious-ssl-tls-shutdown + // + // When a short read would cut off the end of an HTTP message, + // Beast returns the error beast::http::error::partial_message. + // Therefore, if we see a short read here, it has occurred + // after the message has been completed, so it is safe to ignore it. + + if (ec == boost::asio::ssl::error::stream_truncated) + return; + + std::cerr << what << ": " << ec.message() << "\n"; +} + // Handles an HTTP server connection template<class Derived> class session |