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

feat: Require semicolon to start chunk parameters. #181

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/llhttp/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ export class HTTP {

n('chunk_size_otherwise')
.match('\r', n('chunk_size_almost_done'))
.match([ ';', ' ' ], n('chunk_parameters'))
.match('; ', n('chunk_parameters'))
.otherwise(p.error(ERROR.INVALID_CHUNK_SIZE,
'Invalid character in chunk size'));

Expand Down
33 changes: 32 additions & 1 deletion test/request/transfer-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,37 @@ off=157 chunk complete
off=160 chunk header len=0
```

### No semicolon before chunk parameters

<!-- meta={"type": "request"} -->
```http
POST /chunked_w_unicorns_after_length HTTP/1.1
Host: localhost
Transfer-encoding: chunked

2 erfrferferf
aa
0 rrrr


```

```log
off=0 message begin
off=5 len=32 span[url]="/chunked_w_unicorns_after_length"
off=38 url complete
off=48 len=4 span[header_field]="Host"
off=53 header_field complete
off=54 len=9 span[header_value]="localhost"
off=65 header_value complete
off=65 len=17 span[header_field]="Transfer-encoding"
off=83 header_field complete
off=84 len=7 span[header_value]="chunked"
off=93 header_value complete
off=95 headers complete method=3 v=1/1 flags=208 content_length=0
off=96 error code=12 reason="Invalid character in chunk size"
```

## Ignoring `pigeons`

Requests cannot have invalid `Transfer-Encoding`. It is impossible to determine
Expand Down Expand Up @@ -598,5 +629,5 @@ off=37 header_field complete
off=38 len=7 span[header_value]="chunked"
off=47 header_value complete
off=49 headers complete method=4 v=1/1 flags=208 content_length=0
off=51 error code=2 reason="Invalid character in chunk parameters"
off=50 error code=12 reason="Invalid character in chunk size"
```
48 changes: 34 additions & 14 deletions test/response/transfer-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,7 @@ off=61 header_field complete
off=62 len=7 span[header_value]="chunked"
off=71 header_value complete
off=73 headers complete status=200 v=1/1 flags=208 content_length=0
off=79 chunk header len=37
off=79 len=35 span[body]="This is the data in the first chunk"
off=114 len=1 span[body]=cr
off=115 len=1 span[body]=lf
off=118 chunk complete
off=122 chunk header len=28
off=122 len=26 span[body]="and this is the second one"
off=148 len=1 span[body]=cr
off=149 len=1 span[body]=lf
off=152 chunk complete
off=157 chunk header len=0
off=159 chunk complete
off=159 message complete
off=75 error code=12 reason="Invalid character in chunk size"
```

### `chunked` before other transfer-encoding
Expand Down Expand Up @@ -148,4 +136,36 @@ off=75 len=1 span[body]=cr
off=76 len=1 span[body]=lf
off=77 len=1 span[body]=cr
off=78 len=1 span[body]=lf
```
```

### No semicolon before chunk parameters

<!-- meta={"type": "response"} -->
```http
HTTP/1.1 200 OK
Host: localhost
Transfer-encoding: chunked

2 erfrferferf
aa
0 rrrr


```

```log
off=0 message begin
off=13 len=2 span[status]="OK"
off=17 status complete
off=17 len=4 span[header_field]="Host"
off=22 header_field complete
off=23 len=9 span[header_value]="localhost"
off=34 header_value complete
off=34 len=17 span[header_field]="Transfer-encoding"
off=52 header_field complete
off=53 len=7 span[header_value]="chunked"
off=62 header_value complete
off=64 headers complete status=200 v=1/1 flags=208 content_length=0
off=65 error code=12 reason="Invalid character in chunk size"
```