diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-08-11 17:37:11 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-08-11 17:37:11 +0100 |
commit | e4d4f49e87c8cd62334ab6237320a3c28f1dcb09 (patch) | |
tree | b3643e8da352b0f149aba5f49da69bbffe517ee6 /src/libserver/http | |
parent | 7e66c1c7a047e32acd17c9596ecac1534814c13b (diff) | |
download | rspamd-e4d4f49e87c8cd62334ab6237320a3c28f1dcb09.tar.gz rspamd-e4d4f49e87c8cd62334ab6237320a3c28f1dcb09.zip |
[Fix] Fix brain-damaged behaviour when http request has a custom Host header
Diffstat (limited to 'src/libserver/http')
-rw-r--r-- | src/libserver/http/http_connection.c | 73 | ||||
-rw-r--r-- | src/libserver/http/http_connection.h | 4 | ||||
-rw-r--r-- | src/libserver/http/http_message.c | 5 |
3 files changed, 59 insertions, 23 deletions
diff --git a/src/libserver/http/http_connection.c b/src/libserver/http/http_connection.c index bf4d07b72..aaa34f44e 100644 --- a/src/libserver/http/http_connection.c +++ b/src/libserver/http/http_connection.c @@ -1871,31 +1871,58 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted, } else { if (conn->priv->flags & RSPAMD_HTTP_CONN_FLAG_PROXY) { - rspamd_printf_fstring (buf, - "%s %s://%s:%d/%V HTTP/1.1\r\n" - "Connection: %s\r\n" - "Host: %s\r\n" - "Content-Length: %z\r\n", - http_method_str (msg->method), - (msg->flags & RSPAMD_HTTP_FLAG_SSL) ? "https" : "http", - host, - msg->port, - msg->url, - conn_type, - host, - bodylen); + if ((msg->flags & RSPAMD_HTTP_FLAG_HAS_HOST_HEADER)) { + rspamd_printf_fstring(buf, + "%s %s://%s:%d/%V HTTP/1.1\r\n" + "Connection: %s\r\n" + "Content-Length: %z\r\n", + http_method_str(msg->method), + (msg->flags & RSPAMD_HTTP_FLAG_SSL) ? "https" : "http", + msg->port, + msg->url, + conn_type, + host, + bodylen); + } + else { + rspamd_printf_fstring(buf, + "%s %s://%s:%d/%V HTTP/1.1\r\n" + "Connection: %s\r\n" + "Host: %s\r\n" + "Content-Length: %z\r\n", + http_method_str(msg->method), + (msg->flags & RSPAMD_HTTP_FLAG_SSL) ? "https" : "http", + host, + msg->port, + msg->url, + conn_type, + host, + bodylen); + } } else { - rspamd_printf_fstring (buf, - "%s %V HTTP/1.1\r\n" - "Connection: %s\r\n" - "Host: %s\r\n" - "Content-Length: %z\r\n", - http_method_str (msg->method), - msg->url, - conn_type, - host, - bodylen); + if ((msg->flags & RSPAMD_HTTP_FLAG_HAS_HOST_HEADER)) { + rspamd_printf_fstring(buf, + "%s %V HTTP/1.1\r\n" + "Connection: %s\r\n" + "Content-Length: %z\r\n", + http_method_str(msg->method), + msg->url, + conn_type, + bodylen); + } + else { + rspamd_printf_fstring(buf, + "%s %V HTTP/1.1\r\n" + "Connection: %s\r\n" + "Host: %s\r\n" + "Content-Length: %z\r\n", + http_method_str(msg->method), + msg->url, + conn_type, + host, + bodylen); + } } if (bodylen > 0) { diff --git a/src/libserver/http/http_connection.h b/src/libserver/http/http_connection.h index ada98d250..b6b199fae 100644 --- a/src/libserver/http/http_connection.h +++ b/src/libserver/http/http_connection.h @@ -80,6 +80,10 @@ struct rspamd_storage_shmem { */ #define RSPAMD_HTTP_FLAG_SSL_NOVERIFY (1 << 6) /** + * Body has been set for a message + */ +#define RSPAMD_HTTP_FLAG_HAS_HOST_HEADER (1 << 6) +/** * Options for HTTP connection */ enum rspamd_http_options { diff --git a/src/libserver/http/http_message.c b/src/libserver/http/http_message.c index e68778f3e..d15856956 100644 --- a/src/libserver/http/http_message.c +++ b/src/libserver/http/http_message.c @@ -528,6 +528,11 @@ rspamd_http_message_add_header_len (struct rspamd_http_message *msg, hdr = g_malloc0 (sizeof (struct rspamd_http_header)); nlen = strlen (name); vlen = len; + + if (g_ascii_strcasecmp (name, "host") == 0) { + msg->flags |= RSPAMD_HTTP_FLAG_HAS_HOST_HEADER; + } + hdr->combined = rspamd_fstring_sized_new (nlen + vlen + 4); rspamd_printf_fstring (&hdr->combined, "%s: %*s\r\n", name, (gint)vlen, value); |