From 17927400759710536e51a84a266f40506f21b310 Mon Sep 17 00:00:00 2001 From: Artem Boldariev Date: Mon, 5 Jul 2021 16:03:50 +0300 Subject: [PATCH] Ignore an "Accept" HTTP header value We were too strict regarding the value and presence of "Accept" HTTP header, slightly breaking compatibility with the specification. According to RFC8484 client SHOULD add "Accept" header to the requests but MUST be able to handle "application/dns-message" media type regardless of the value of the header. That basically suggests we ignore its value. Besides, verifying the value of the "Accept" header is a bit tricky because it could contain multiple media types, thus requiring proper parsing. That is doable but does not provide us with any benefits. Among other things, not verifying the value also fixes compatibility with clients, which could advertise multiple media types as supported, which we should accept. For example, it is possible for a perfectly valid request to contain "application/dns-message", "application/*", and "*/*" in the "Accept" header value. Still, we would treat such a request as invalid. --- lib/isc/netmgr/http.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index fe9f73bd70..723dd57e7e 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -1805,23 +1805,6 @@ server_handle_content_type_header(isc_nmsocket_t *socket, const uint8_t *value, return (resp); } -static isc_http_error_responses_t -server_handle_accept_header(isc_nmsocket_t *socket, const uint8_t *value, - const size_t valuelen) { - const char type_accept_all[] = "*/*"; - const char type_dns_message[] = DNS_MEDIA_TYPE; - isc_http_error_responses_t resp = ISC_HTTP_ERROR_SUCCESS; - - UNUSED(socket); - - if (!(HEADER_MATCH(type_dns_message, value, valuelen) || - HEADER_MATCH(type_accept_all, value, valuelen))) - { - resp = ISC_HTTP_ERROR_UNSUPPORTED_MEDIA_TYPE; - } - return (resp); -} - static isc_http_error_responses_t server_handle_header(isc_nmsocket_t *socket, const uint8_t *name, size_t namelen, const uint8_t *value, @@ -1831,7 +1814,6 @@ server_handle_header(isc_nmsocket_t *socket, const uint8_t *name, const char path[] = ":path"; const char method[] = ":method"; const char scheme[] = ":scheme"; - const char accept[] = "accept"; const char content_length[] = "Content-Length"; const char content_type[] = "Content-Type"; @@ -1852,9 +1834,6 @@ server_handle_header(isc_nmsocket_t *socket, const uint8_t *name, } else if (!was_error && HEADER_MATCH(content_type, name, namelen)) { code = server_handle_content_type_header(socket, value, valuelen); - } else if (!was_error && - HEADER_MATCH(accept, (const char *)name, namelen)) { - code = server_handle_accept_header(socket, value, valuelen); } return (code);