Skip to content

Commit 66e9984

Browse files
committed
fix: Require CRLF in the status line.
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 96b15fb commit 66e9984

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

src/llhttp/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ export class HTTP {
422422
.skipTo(n('res_status'));
423423

424424
n('res_line_almost_done')
425-
.match([ '\r', '\n' ], onStatusComplete)
425+
.match('\n', onStatusComplete)
426426
.otherwise(this.testLenientFlags(LENIENT_FLAGS.OPTIONAL_LF_AFTER_CR, {
427427
1: onStatusComplete,
428428
}, p.error(ERROR.STRICT, 'Expected LF after CR')));

test/response/invalid.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,69 @@ off=22 len=1 span[header_value]="1"
129129
off=24 error code=3 reason="Missing expected LF after header value"
130130
```
131131

132+
### Bare CR after response line
133+
134+
<!-- meta={"type": "response"} -->
135+
```http
136+
HTTP/1.1 200 OK\rContent-Length: 0
137+
138+
139+
```
140+
141+
```log
142+
off=0 message begin
143+
off=0 len=4 span[protocol]="HTTP"
144+
off=4 protocol complete
145+
off=5 len=3 span[version]="1.1"
146+
off=8 version complete
147+
off=13 len=2 span[status]="OK"
148+
off=16 error code=2 reason="Expected LF after CR"
149+
```
150+
151+
### Bare CR after response line (lenient)
152+
153+
<!-- meta={"type": "response-lenient-optional-lf-after-cr"} -->
154+
```http
155+
HTTP/1.1 200 OK\rContent-Length: 0
156+
157+
158+
```
159+
160+
```log
161+
off=0 message begin
162+
off=0 len=4 span[protocol]="HTTP"
163+
off=4 protocol complete
164+
off=5 len=3 span[version]="1.1"
165+
off=8 version complete
166+
off=13 len=2 span[status]="OK"
167+
off=16 status complete
168+
off=16 len=14 span[header_field]="Content-Length"
169+
off=31 header_field complete
170+
off=32 len=1 span[header_value]="0"
171+
off=35 header_value complete
172+
off=37 headers complete status=200 v=1/1 flags=20 content_length=0
173+
off=37 message complete
174+
```
175+
176+
### Bare CR followed by CR after response line
177+
178+
<!-- meta={"type": "response"} -->
179+
```http
180+
HTTP/1.1 200 OK\r\rContent-Length: 4
181+
182+
Evil
183+
```
184+
185+
```log
186+
off=0 message begin
187+
off=0 len=4 span[protocol]="HTTP"
188+
off=4 protocol complete
189+
off=5 len=3 span[version]="1.1"
190+
off=8 version complete
191+
off=13 len=2 span[status]="OK"
192+
off=16 error code=2 reason="Expected LF after CR"
193+
```
194+
132195
### Invalid HTTP version
133196

134197
<!-- meta={"type": "response"} -->
@@ -313,4 +376,4 @@ off=35 headers complete status=200 v=1/1 flags=0 content_length=0
313376
off=35 len=4 span[body]="BODY"
314377
off=39 len=1 span[body]=lf
315378
off=40 len=1 span[body]="\"
316-
```
379+
```

0 commit comments

Comments
 (0)