Skip to content

Commit 6f8c509

Browse files
committed
Option to hide server signature in HTTP response
Hiding the server signature reduces the likelihood of targeted attacks by making it harder for attackers to identify the server's configuration. In built-in default configuration security.server_signature is set to false. It is also set to false in coolwsd.xml packaged with production builds. HTTP response header is like: Server: COOLWSD HTTP Server In debug mode security.server_signature is set to true in coolwsd.xml. HTTP response header is like: Server: COOLWSD HTTP Server 24.04.9.1 Signed-off-by: Andras Timar <[email protected]> Change-Id: Ie23c2dbc1514e46e2942f558ada2e27d0f108bea
1 parent 384ba58 commit 6f8c509

File tree

7 files changed

+30
-1
lines changed

7 files changed

+30
-1
lines changed

common/Unit.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace
4747
std::thread TimeoutThread;
4848
std::mutex TimeoutThreadMutex;
4949
std::condition_variable TimeoutConditionVariable;
50+
bool CppunitTesting = false;
5051

5152
} // namespace
5253

@@ -354,6 +355,16 @@ void UnitBase::rememberInstance(UnitType type, UnitBase* instance)
354355
}
355356
}
356357

358+
void UnitBase::setCppunitTesting(bool cppunitTesting)
359+
{
360+
CppunitTesting = cppunitTesting;
361+
}
362+
363+
bool UnitBase::isCppunitTesting()
364+
{
365+
return CppunitTesting;
366+
}
367+
357368
int UnitBase::uninit()
358369
{
359370
// Only in debug builds do we support tests.

common/Unit.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class UnitBase
145145
/// Returns 0 on success.
146146
static int uninit();
147147

148+
static void setCppunitTesting(bool cppunitTesting);
149+
static bool isCppunitTesting();
150+
148151
/// Do we have a unit test library hooking things & loaded
149152
static bool isUnitTesting()
150153
{

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ bundle_msg="using uglified bundled JS and CSS"
421421
LOK_LOG_ASSERTIONS=0
422422
log_asserts_msg="disabled"
423423
SSL_VERIFY="true"
424+
SERVER_SIGNATURE="false"
424425

425426
# a reasonable default
426427
NUM_PRESPAWN_CHILDREN=4
@@ -440,6 +441,7 @@ if test "$enable_debug" = "yes"; then
440441
BROWSER_LOGGING="true"
441442
debug_msg="low security debugging mode"
442443
SSL_VERIFY="false"
444+
SERVER_SIGNATURE="true"
443445

444446
# helps attaching to the right process
445447
NUM_PRESPAWN_CHILDREN=1
@@ -527,6 +529,8 @@ AC_MSG_RESULT([$SSL_VERIFY])
527529
AC_DEFINE_UNQUOTED([SSL_VERIFY],["$SSL_VERIFY"],[Default SSL Verification mode])
528530
AC_SUBST(SSL_VERIFY)
529531

532+
AC_SUBST(SERVER_SIGNATURE)
533+
530534
dnl check for a file at a path with an env-var with a given suffix
531535
AC_DEFUN([CHK_FILE_VAR], dnl env-var, suffix, file-to-match, msg
532536
[

coolwsd.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
<macro_security_level desc="Level of Macro security. 1 (Medium) Confirmation required before executing macros from untrusted sources. 0 (Low, not recommended) All macros will be executed without confirmation." type="int" default="1">1</macro_security_level>
227227
<enable_websocket_urp desc="Should we enable URP (UNO remote protocol) communication over the websocket. This allows full control of the Kit child server to anyone with access to the websocket including executing macros without confirmation or running arbitrary shell commands in the jail." type="bool" default="false">false</enable_websocket_urp>
228228
<enable_metrics_unauthenticated desc="When enabled, the /cool/getMetrics endpoint will not require authentication." type="bool" default="false">false</enable_metrics_unauthenticated>
229+
<server_signature desc="Whether to send server signature in HTTP response headers" type="bool" default="@SERVER_SIGNATURE@">@SERVER_SIGNATURE@</server_signature>
229230
</security>
230231

231232
<certificates>

net/Socket.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
#include <Log.hpp>
5656
#include <Watchdog.hpp>
5757
#include <wasm/base64.hpp>
58+
#include <common/ConfigUtil.hpp>
59+
#include <common/Unit.hpp>
5860

5961
// Bug in pre C++17 where static constexpr must be defined. Fixed in C++17.
6062
constexpr std::chrono::microseconds SocketPoll::DefaultPollTimeoutMicroS;
@@ -1732,7 +1734,13 @@ namespace http
17321734
{
17331735
std::string getAgentString() { return "COOLWSD HTTP Agent " + Util::getCoolVersion(); }
17341736

1735-
std::string getServerString() { return "COOLWSD HTTP Server " + Util::getCoolVersion(); }
1737+
std::string getServerString()
1738+
{
1739+
if (!UnitBase::isCppunitTesting())
1740+
if (config::getBool("security.server_signature", false))
1741+
return "COOLWSD HTTP Server " + Util::getCoolVersion();
1742+
return "COOLWSD HTTP Server";
1743+
}
17361744
}
17371745

17381746
extern "C" {

test/HttpRequestTests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class HttpRequestTests final : public CPPUNIT_NS::TestFixture
108108
= new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslParams);
109109
Poco::Net::SSLManager::instance().initializeClient(nullptr, std::move(invalidCertHandler), std::move(sslContext));
110110
#endif
111+
UnitBase::setCppunitTesting(true);
111112
}
112113

113114
~HttpRequestTests()

wsd/COOLWSD.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,7 @@ void COOLWSD::innerInitialize(Poco::Util::Application& self)
20842084
{ "security.seccomp", "true" },
20852085
{ "security.jwt_expiry_secs", "1800" },
20862086
{ "security.enable_metrics_unauthenticated", "false" },
2087+
{ "security.server_signature", "false" },
20872088
{ "certificates.database_path", "" },
20882089
{ "server_name", "" },
20892090
{ "ssl.ca_file_path", COOLWSD_CONFIGDIR "/ca-chain.cert.pem" },

0 commit comments

Comments
 (0)