commit bc6e4389b22ab7da1563b09b2a618435db0f5183
parent 2301ef18367cb67a33af89b9ece0207b9d5f46c5
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 4 Aug 2026 13:44:55 +0200
check X-Forwarded port is well-formed, do not use if default
Diffstat:
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/src/backend/paivana-httpd_helper.c b/src/backend/paivana-httpd_helper.c
@@ -112,6 +112,7 @@ PAIVANA_HTTPD_get_base_url (struct MHD_Connection *connection,
struct GNUNET_Buffer *buf)
{
const char *forwarded_host;
+ bool is_https;
GNUNET_buffer_clear (buf);
if (NULL != PH_base_url)
@@ -120,8 +121,9 @@ PAIVANA_HTTPD_get_base_url (struct MHD_Connection *connection,
PH_base_url);
return true;
}
- if (GNUNET_YES ==
- TALER_mhd_is_https (connection))
+ is_https = (GNUNET_YES ==
+ TALER_mhd_is_https (connection));
+ if (is_https)
GNUNET_buffer_write_str (buf,
"https://");
else
@@ -142,12 +144,32 @@ PAIVANA_HTTPD_get_base_url (struct MHD_Connection *connection,
forwarded_port = MHD_lookup_connection_value (connection,
MHD_HEADER_KIND,
"X-Forwarded-Port");
- if (NULL != forwarded_port)
+ if ( (NULL != forwarded_port) &&
+ (0 != strcmp (forwarded_port,
+ is_https ? "443" : "80") ) )
{
- GNUNET_buffer_write_str (buf,
- ":");
- GNUNET_buffer_write_str (buf,
- forwarded_port);
+ unsigned int port;
+ char c;
+
+ if ( (1 !=
+ sscanf (forwarded_port,
+ "%u%c",
+ &port,
+ &c)) ||
+ (0 == port) ||
+ (65536 <= port) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid X-Forwarded-Port value `%s'. Ignored\n",
+ forwarded_port);
+ }
+ else
+ {
+ GNUNET_buffer_write_str (buf,
+ ":");
+ GNUNET_buffer_write_str (buf,
+ forwarded_port);
+ }
}
}
else