commit 9b749c1: [Minor] Make server header reply configurable

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Feb 7 17:56:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-02-07 17:49:03 +0000
URL: https://github.com/rspamd/rspamd/commit/9b749c197119e93ce82fa03f7d1cb3960b170662 (HEAD -> master)

[Minor] Make server header reply configurable

---
 src/libutil/http_connection.c | 11 ++++++-----
 src/libutil/http_context.c    | 13 +++++++++++++
 src/libutil/http_context.h    |  4 +++-
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/libutil/http_connection.c b/src/libutil/http_connection.c
index 3848788d6..027dc9d5b 100644
--- a/src/libutil/http_connection.c
+++ b/src/libutil/http_connection.c
@@ -1713,7 +1713,7 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
 											"Date: %s\r\n"
 											"Content-Length: %z\r\n"
 											"Content-Type: %s", /* NO \r\n at the end ! */
-									msg->code, &status, "rspamd/" RVERSION,
+									msg->code, &status, priv->ctx->config.server_hdr,
 									datebuf,
 									bodylen, mime_type);
 				}
@@ -1725,7 +1725,7 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
 											"Server: %s\r\n"
 											"Date: %s\r\n"
 											"Content-Length: %z", /* NO \r\n at the end ! */
-									msg->code, &status, "rspamd/" RVERSION,
+									msg->code, &status, priv->ctx->config.server_hdr,
 									datebuf,
 									bodylen);
 				}
@@ -1734,10 +1734,11 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
 				rspamd_printf_fstring (buf,
 						"HTTP/1.1 200 OK\r\n"
 						"Connection: close\r\n"
-						"Server: rspamd\r\n"
+						"Server: %s\r\n"
 						"Date: %s\r\n"
 						"Content-Length: %z\r\n"
 						"Content-Type: application/octet-stream\r\n",
+						priv->ctx->config.server_hdr,
 						datebuf, enclen);
 			}
 			else {
@@ -1750,7 +1751,7 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
 											"Date: %s\r\n"
 											"Content-Length: %z\r\n"
 											"Content-Type: %s\r\n",
-									msg->code, &status, "rspamd/" RVERSION,
+									msg->code, &status, priv->ctx->config.server_hdr,
 									datebuf,
 									bodylen, mime_type);
 				}
@@ -1762,7 +1763,7 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
 											"Server: %s\r\n"
 											"Date: %s\r\n"
 											"Content-Length: %z\r\n",
-									msg->code, &status, "rspamd/" RVERSION,
+									msg->code, &status, priv->ctx->config.server_hdr,
 									datebuf,
 									bodylen);
 				}
diff --git a/src/libutil/http_context.c b/src/libutil/http_context.c
index 4d701d0c5..d7e530d56 100644
--- a/src/libutil/http_context.c
+++ b/src/libutil/http_context.c
@@ -92,6 +92,7 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
 	static const gdouble default_rotate_time = 120;
 	static const gdouble default_keepalive_interval = 65;
 	static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL;
+	static const gchar *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL;
 
 	ctx = g_malloc0 (sizeof (*ctx));
 	ctx->config.kp_cache_size_client = default_kp_size;
@@ -99,6 +100,7 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
 	ctx->config.client_key_rotate_time = default_rotate_time;
 	ctx->config.user_agent = default_user_agent;
 	ctx->config.keepalive_interval = default_keepalive_interval;
+	ctx->config.server_hdr = default_server_hdr;
 	ctx->ups_ctx = ups_ctx;
 
 	if (cfg) {
@@ -243,6 +245,17 @@ rspamd_http_context_create (struct rspamd_config *cfg,
 				}
 			}
 
+			const ucl_object_t *server_hdr;
+			server_hdr = ucl_object_lookup (client_obj, "server_hdr");
+
+			if (server_hdr) {
+				ctx->config.server_hdr = ucl_object_tostring (server_hdr);
+
+				if (ctx->config.server_hdr && strlen (ctx->config.server_hdr) == 0) {
+					ctx->config.server_hdr = "";
+				}
+			}
+
 			const ucl_object_t *keepalive_interval;
 
 			keepalive_interval = ucl_object_lookup (client_obj, "keepalive_interval");
diff --git a/src/libutil/http_context.h b/src/libutil/http_context.h
index f7697c406..82ee400b0 100644
--- a/src/libutil/http_context.h
+++ b/src/libutil/http_context.h
@@ -40,6 +40,7 @@ struct rspamd_http_context_cfg {
 	gdouble client_key_rotate_time;
 	const gchar *user_agent;
 	const gchar *http_proxy;
+	const gchar *server_hdr;
 };
 
 /**
@@ -49,7 +50,8 @@ struct rspamd_http_context_cfg {
  * @return new context used for both client and server HTTP connections
  */
 struct rspamd_http_context *rspamd_http_context_create (struct rspamd_config *cfg,
-														struct ev_loop *ev_base, struct upstream_ctx *ctx);
+														struct ev_loop *ev_base,
+														struct upstream_ctx *ctx);
 
 struct rspamd_http_context *rspamd_http_context_create_config (
 		struct rspamd_http_context_cfg *cfg,


More information about the Commits mailing list