Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameengine): -control refuses Origin null
Olcay Seygand9edfda1f653
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ControlServer.h b/GeneralsMD/Code/GameEngine/Include/Common/ControlServer.hindex fc612b450..93b01501f 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ControlServer.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ControlServer.h@@ -76,8 +76,8 @@ extern void ControlServer_shutdown( void );and RFC 6455 ships a worked example to test it against. */extern Bool ControlServer_computeAcceptKey( const char *clientKey, char *out, Int outSize );-/** Whether an upgrade request may have the socket: no Origin (a script), "null", or a page on this- machine. Anything else is a web page reaching for ws://127.0.0.1 from the player's browser. */+/** Whether an upgrade request may have the socket: no Origin (a script) or a page on this machine.+ Anything else, "null" included, is a web page reaching for ws://127.0.0.1 from the player's browser. */extern Bool ControlServer_originAllowed( const char *request );#endif // __CONTROLSERVER_H_diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cppindex ff2768734..1edfc7d04 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp@@ -517,15 +517,14 @@ static Bool findHeader( const char *request, const char *name, char *valueOut, I}/* A browser names the page that opened the socket in Origin, and any web page can open ws://127.0.0.1.- So a request with an Origin is let in only from this machine's own pages (or "null", a file:// page);- the project's tools (control_client.py, Node's WebSocket) send no Origin at all. */+ So a request with an Origin is let in only from this machine's own pages. "null" is refused: a+ sandboxed iframe on any web site sends it. The project's tools (control_client.py, Node's+ WebSocket) send no Origin at all. */Bool ControlServer_originAllowed( const char *request ){char origin[ 256 ];if (!findHeader( request, "origin:", origin, sizeof( origin ) ))return TRUE;- if (strcmp( origin, "null" ) == 0)- return TRUE;static const char *const LOCAL[] = { "http://localhost", "https://localhost", "http://127.0.0.1", "https://127.0.0.1", "http://[::1]", "https://[::1]" };for( Int k = 0; k < (Int)ARRAY_SIZE( LOCAL ); ++k )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex ad1528b52..532bf604c 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -21811,7 +21811,7 @@ TEST(control_server_refuses_a_web_pages_origin)request = std::string( head ) + "\r\n";CHECK( ControlServer_originAllowed( request.c_str() ) );- const char *allowed[] = { "null", "http://localhost", "http://localhost:5173", "https://127.0.0.1:443", "http://[::1]:8080", "null " };+ const char *allowed[] = { "http://localhost", "http://localhost:5173", "https://127.0.0.1:443", "http://[::1]:8080", "http://localhost " };for( Int i = 0; i < (Int)ARRAY_SIZE( allowed ); ++i ){request = std::string( head ) + "Origin: " + allowed[ i ] + "\r\n\r\n";@@ -21821,7 +21821,7 @@ TEST(control_server_refuses_a_web_pages_origin)CHECK( ControlServer_originAllowed( request.c_str() ) );const char *refused[] = { "https://evil.example", "http://localhost.evil.example", "http://localhost:80.evil.example",- "http://127.0.0.1.nip.io", "http://localhost:", "", "file://", "http://LOCALHOSTX" };+ "http://127.0.0.1.nip.io", "http://localhost:", "", "file://", "http://LOCALHOSTX", "null" }; // null: a sandboxed iframe on any sitefor( Int i = 0; i < (Int)ARRAY_SIZE( refused ); ++i ){request = std::string( head ) + "Origin: " + refused[ i ] + "\r\n\r\n";