[hackers] [quark][PATCH 3/3] do not compare the port for triggering redirection

From: Josuah Demangeon <mail_AT_josuah.net>
Date: Mon, 2 Apr 2018 02:55:01 +0200

An HTTP request may contain the port number:

        $ nc -l 8080
        GET / HTTP/1.1
        Host: localhost:8080
        User-Agent: curl/7.55.1
        Accept: */*

It provoked the canonical host to mismatch while comparing it with
the actual host:

        r->field[REQ_HOST]: localhost:8080
        vhostmatch: localhost

This commit attempts to fix it by replacing the first ':' by '\0'.
Hopefully this will not clash with IPv6 addresses syntax.
---
 http.c | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/http.c b/http.c
index 12ebde8..989907b 100644
--- a/http.c
+++ b/http.c
_AT_@ -401,6 +401,11 @@ http_send_response(int fd, struct request *r)
 		}
 	}
 
+	/* strip the port out of the host name */
+	if ((p = strchr(r->field[REQ_HOST], ':'))) {
+		*p = '\0';
+	}
+
 	/* redirect if targets differ, host is non-canonical or we prefixed */
 	if (strcmp(r->target, realtarget) || (s.vhost && vhostmatch &&
 	    strcmp(r->field[REQ_HOST], vhostmatch))) {
-- 
2.10.0
Received on Mon Apr 02 2018 - 02:55:01 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 02 2018 - 03:00:37 CEST