Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespace between start-line and first HTTP header not properly handled #152

Closed
zeyu2001 opened this issue Apr 4, 2022 · 0 comments · Fixed by #180
Closed

Whitespace between start-line and first HTTP header not properly handled #152

zeyu2001 opened this issue Apr 4, 2022 · 0 comments · Fixed by #180

Comments

@zeyu2001
Copy link

zeyu2001 commented Apr 4, 2022

Issue transferred over from HackerOne.

According to RFC7230 section 3:

A recipient that receives whitespace between the
start-line and the first header field MUST either reject the message
as invalid or consume each whitespace-preceded line without further
processing of it (i.e., ignore the entire line, along with any
subsequent lines preceded by whitespace, until a properly formed
header field is received or the header section is terminated).

However, the parser does not adhere to this and accepts a first header with a leading whitespace.

GET / HTTP/1.1
 Host: foo

Server code used for testing:

const http = require('http');

http.createServer((request, response) => {
   let body = [];
   request.on('error', (err) => {
      response.end("error while reading body: " + err)
   }).on('data', (chunk) => {
      body.push(chunk);
   }).on('end', () => {
   body = Buffer.concat(body).toString();
   
   response.on('error', (err) => {
      response.end("error while sending response: " + err)
   });

   response.end(JSON.stringify({
         "URL": request.url,
         "Headers": request.headers,
         "Length": body.length,
         "Body": body,
      }) + "\n");
   });
}).listen(80);

Request:

GET / HTTP/1.1
 Host: foo

Expected result: As per the RFC, either return a 400 Bad Request or ignore the header entirely.

Actual result: The header is processed as host (with a leading whitespace).

HTTP/1.1 200 OK
Date: Mon, 28 Mar 2022 17:34:47 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 59

{"URL":"/","Headers":{" host":"foo"},"Length":0,"Body":""}

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant