[gupnp/wip/phako/55: 3/3] service: Validate Host header in GENA handlers




commit c3e204438c942e2819942284650745e95ef5c307
Author: Jens Georg <mail jensge org>
Date:   Sat Jul 3 19:26:28 2021 +0200

    service: Validate Host header in GENA handlers
    
    Fixes #55

 libgupnp/gupnp-service.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
---
diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index b441dd1..2a33ea5 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -1379,6 +1379,20 @@ subscription_server_handler (G_GNUC_UNUSED SoupServer        *server,
 
         service = GUPNP_SERVICE (user_data);
 
+        const char *host =
+                soup_message_headers_get_one (msg->request_headers, "Host");
+        GUPnPContext *context = gupnp_service_info_get_context (user_data);
+        if (!gupnp_context_validate_host_header(context, host)) {
+                g_warning ("Host header mismatch, expected %s:%d, got %s",
+                           gssdp_client_get_host_ip (GSSDP_CLIENT (context)),
+                           gupnp_context_get_port (context),
+                           host);
+
+                soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
+
+                return;
+        }
+
         callback = soup_message_headers_get_one (msg->request_headers,
                                                  "Callback");
         nt       = soup_message_headers_get_one (msg->request_headers, "NT");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]