Skip to content

Commit

Permalink
CONNECT: reject TE or CL in 2xx responses
Browse files Browse the repository at this point in the history
A server MUST NOT send any Transfer-Encoding or Content-Length header
fields in a 2xx (Successful) response to CONNECT. (RFC 7231 section
4.3.6)

Also fixes the three test cases that did this.
  • Loading branch information
bagder committed Dec 1, 2016
1 parent aab3321 commit c50b878
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
17 changes: 17 additions & 0 deletions lib/http_proxy.c
Expand Up @@ -529,6 +529,15 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
return result;
}
else if(checkprefix("Content-Length:", line_start)) {
if(k->httpcode/100 == 2) {
/* A server MUST NOT send any Transfer-Encoding or
Content-Length header fields in a 2xx (Successful)
response to CONNECT. (RFC 7231 section 4.3.6) */
failf(data, "Content-Length: in %03d response",
k->httpcode);
return CURLE_RECV_ERROR;
}

cl = curlx_strtoofft(line_start +
strlen("Content-Length:"), NULL, 10);
}
Expand All @@ -538,6 +547,14 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
else if(Curl_compareheader(line_start,
"Transfer-Encoding:",
"chunked")) {
if(k->httpcode/100 == 2) {
/* A server MUST NOT send any Transfer-Encoding or
Content-Length header fields in a 2xx (Successful)
response to CONNECT. (RFC 7231 section 4.3.6) */
failf(data, "Transfer-Encoding: in %03d response",
k->httpcode);
return CURLE_RECV_ERROR;
}
infof(data, "CONNECT responded chunked\n");
chunked_encoding = TRUE;
/* init our chunky engine */
Expand Down
12 changes: 5 additions & 7 deletions tests/data/test1097
Expand Up @@ -15,27 +15,25 @@ HTTP proxy NTLM auth
HTTP/1.1 200 We are fine and cool
Server: Apache/1.3.27 (Dorw1n) PHP/44.1.2
Content-Length: 27

This is all fine and dandy
</data>

# This is the CONNECT response
<connect1001>
HTTP/1.1 200 We are fine and cool
Server: Apache/1.3.27 (Dorw1n) PHP/44.1.2
Content-Length: 27

This is all fine and dandy

</connect1001>

<datacheck>
HTTP/1.1 200 We are fine and cool
Server: Apache/1.3.27 (Dorw1n) PHP/44.1.2
Content-Length: 27


HTTP/1.1 200 We are fine and cool
Server: Apache/1.3.27 (Dorw1n) PHP/44.1.2
Content-Length: 27

This is all fine and dandy
</datacheck>
</reply>
Expand Down
2 changes: 0 additions & 2 deletions tests/data/test1230
Expand Up @@ -23,14 +23,12 @@ mooooooo
<connect>
HTTP/1.1 200 welcome dear
Date: Thu, 09 Nov 2010 14:49:00 GMT
Content-Length: 0

</connect>

<datacheck>
HTTP/1.1 200 welcome dear
Date: Thu, 09 Nov 2010 14:49:00 GMT
Content-Length: 0

HTTP/1.1 200 OK
Date: Thu, 09 Nov 2010 14:49:00 GMT
Expand Down
2 changes: 0 additions & 2 deletions tests/data/test1525
Expand Up @@ -14,7 +14,6 @@ CURLOPT_PROXYHEADER
<reply>
<connect>
HTTP/1.1 200 OK
Content-Length: 17

</connect>
<data>
Expand All @@ -26,7 +25,6 @@ ETag: "21025-dc7-39462498"
</data>
<datacheck>
HTTP/1.1 200 OK
Content-Length: 17

HTTP/1.1 200 OK swsclose
Date: Thu, 09 Nov 2010 14:49:00 GMT
Expand Down

0 comments on commit c50b878

Please sign in to comment.