Skip to content

Commit abb4f43

Browse files
authored
feat: Require semicolon to start chunk parameters. (#181)
1 parent 1cc0c6d commit abb4f43

3 files changed

Lines changed: 67 additions & 16 deletions

File tree

src/llhttp/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ export class HTTP {
806806

807807
n('chunk_size_otherwise')
808808
.match('\r', n('chunk_size_almost_done'))
809-
.match([ ';', ' ' ], n('chunk_parameters'))
809+
.match('; ', n('chunk_parameters'))
810810
.otherwise(p.error(ERROR.INVALID_CHUNK_SIZE,
811811
'Invalid character in chunk size'));
812812

test/request/transfer-encoding.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,37 @@ off=157 chunk complete
232232
off=160 chunk header len=0
233233
```
234234

235+
### No semicolon before chunk parameters
236+
237+
<!-- meta={"type": "request"} -->
238+
```http
239+
POST /chunked_w_unicorns_after_length HTTP/1.1
240+
Host: localhost
241+
Transfer-encoding: chunked
242+
243+
2 erfrferferf
244+
aa
245+
0 rrrr
246+
247+
248+
```
249+
250+
```log
251+
off=0 message begin
252+
off=5 len=32 span[url]="/chunked_w_unicorns_after_length"
253+
off=38 url complete
254+
off=48 len=4 span[header_field]="Host"
255+
off=53 header_field complete
256+
off=54 len=9 span[header_value]="localhost"
257+
off=65 header_value complete
258+
off=65 len=17 span[header_field]="Transfer-encoding"
259+
off=83 header_field complete
260+
off=84 len=7 span[header_value]="chunked"
261+
off=93 header_value complete
262+
off=95 headers complete method=3 v=1/1 flags=208 content_length=0
263+
off=96 error code=12 reason="Invalid character in chunk size"
264+
```
265+
235266
## Ignoring `pigeons`
236267

237268
Requests cannot have invalid `Transfer-Encoding`. It is impossible to determine
@@ -598,5 +629,5 @@ off=37 header_field complete
598629
off=38 len=7 span[header_value]="chunked"
599630
off=47 header_value complete
600631
off=49 headers complete method=4 v=1/1 flags=208 content_length=0
601-
off=51 error code=2 reason="Invalid character in chunk parameters"
632+
off=50 error code=12 reason="Invalid character in chunk size"
602633
```

test/response/transfer-encoding.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,7 @@ off=61 header_field complete
3333
off=62 len=7 span[header_value]="chunked"
3434
off=71 header_value complete
3535
off=73 headers complete status=200 v=1/1 flags=208 content_length=0
36-
off=79 chunk header len=37
37-
off=79 len=35 span[body]="This is the data in the first chunk"
38-
off=114 len=1 span[body]=cr
39-
off=115 len=1 span[body]=lf
40-
off=118 chunk complete
41-
off=122 chunk header len=28
42-
off=122 len=26 span[body]="and this is the second one"
43-
off=148 len=1 span[body]=cr
44-
off=149 len=1 span[body]=lf
45-
off=152 chunk complete
46-
off=157 chunk header len=0
47-
off=159 chunk complete
48-
off=159 message complete
36+
off=75 error code=12 reason="Invalid character in chunk size"
4937
```
5038

5139
### `chunked` before other transfer-encoding
@@ -148,4 +136,36 @@ off=75 len=1 span[body]=cr
148136
off=76 len=1 span[body]=lf
149137
off=77 len=1 span[body]=cr
150138
off=78 len=1 span[body]=lf
151-
```
139+
```
140+
141+
### No semicolon before chunk parameters
142+
143+
<!-- meta={"type": "response"} -->
144+
```http
145+
HTTP/1.1 200 OK
146+
Host: localhost
147+
Transfer-encoding: chunked
148+
149+
2 erfrferferf
150+
aa
151+
0 rrrr
152+
153+
154+
```
155+
156+
```log
157+
off=0 message begin
158+
off=13 len=2 span[status]="OK"
159+
off=17 status complete
160+
off=17 len=4 span[header_field]="Host"
161+
off=22 header_field complete
162+
off=23 len=9 span[header_value]="localhost"
163+
off=34 header_value complete
164+
off=34 len=17 span[header_field]="Transfer-encoding"
165+
off=52 header_field complete
166+
off=53 len=7 span[header_value]="chunked"
167+
off=62 header_value complete
168+
off=64 headers complete status=200 v=1/1 flags=208 content_length=0
169+
off=65 error code=12 reason="Invalid character in chunk size"
170+
```
171+

0 commit comments

Comments
 (0)