diff options
| author | Erik Kundiman <erik@megapahit.org> | 2026-10-03 12:53:04 +0800 |
|---|---|---|
| committer | Erik Kundiman <erik@megapahit.org> | 2026-10-03 12:53:04 +0800 |
| commit | 695133b0e9eae18ca99aee8d8606c297a0394475 (patch) | |
| tree | 8bd983ec3941c9f18271528f4eeb616a2987871e /indra/llcorehttp/llwebsocketmgr.cpp | |
| parent | d45e5f46335f8ed579f7663cdd7021c876e52652 (diff) | |
| parent | 0ebee4d8fa2997744dcd882b4be604aa6c14c312 (diff) | |
Merge tag 'Second_Life_Release#0ebee4d8-26.4' into 26.4
Diffstat (limited to 'indra/llcorehttp/llwebsocketmgr.cpp')
| -rw-r--r-- | indra/llcorehttp/llwebsocketmgr.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/indra/llcorehttp/llwebsocketmgr.cpp b/indra/llcorehttp/llwebsocketmgr.cpp index 3c0e0ed952..ef07295eed 100644 --- a/indra/llcorehttp/llwebsocketmgr.cpp +++ b/indra/llcorehttp/llwebsocketmgr.cpp @@ -195,6 +195,7 @@ struct Server_impl mLocalOnly(local_only) { + mServer.set_validate_handler([this](websocketpp::connection_hdl hdl) { return this->onValidate(hdl); }); mServer.set_open_handler([this](websocketpp::connection_hdl hdl) { this->onOpen(hdl); }); mServer.set_close_handler([this](websocketpp::connection_hdl hdl) { this->onClose(hdl); }); mServer.set_message_handler([this](websocketpp::connection_hdl hdl, Server_t::message_ptr msg) { this->onMessage(hdl, msg); }); @@ -312,6 +313,34 @@ struct Server_impl } /** + * @brief Decide whether an upgrade request is let in + * @param hdl WebSocket connection handle from websocketpp + * @return false to answer the request 403 and never open it + * + * Called by websocketpp once the request has been read, before it is + * answered: the owner says which origins it takes. + */ + bool onValidate(websocketpp::connection_hdl hdl) + { + LL_PROFILE_ZONE_SCOPED_CATEGORY_WEBSOCKET; + websocketpp::lib::error_code ec; + Server_t::connection_ptr con = mServer.get_con_from_hdl(hdl, ec); + if (ec || !con) + { + return false; + } + const std::string& origin = con->get_origin(); + if (mOwner->acceptOrigin(origin)) + { + return true; + } + // Once for each origin: a page can ask as often as it likes. + LL_WARNS_ONCE("WebSocket") << mOwner->mServerName << " refused a connection from origin " << origin << LL_ENDL; + con->set_status(websocketpp::http::status_code::forbidden); + return false; + } + + /** * @brief Handle new connection establishment event * @param hdl WebSocket connection handle from websocketpp * |
