Skip to content

Commit

Permalink
fix: lenient chunk extension parsing leading to request smuggling iss…
Browse files Browse the repository at this point in the history
…ues (#1899)

* fix request smuggling issue

* correct broken error messages

* fix lint
  • Loading branch information
JeppW authored Nov 24, 2024
1 parent ed2d390 commit 7b74fc9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2505,17 +2505,24 @@ func parseChunkSize(r *bufio.Reader) (int, error) {
c, err := r.ReadByte()
if err != nil {
return -1, ErrBrokenChunk{
error: fmt.Errorf("cannot read '\r' char at the end of chunk size: %w", err),
error: fmt.Errorf("cannot read '\\r' char at the end of chunk size: %w", err),
}
}
// Skip chunk extension after chunk size.
// Add support later if anyone needs it.
if c != '\r' {
// Security: Don't allow newlines in chunk extensions.
// This can lead to request smuggling issues with some reverse proxies.
if c == '\n' {
return -1, ErrBrokenChunk{
error: errors.New("invalid character '\\n' after chunk size"),
}
}
continue
}
if err := r.UnreadByte(); err != nil {
return -1, ErrBrokenChunk{
error: fmt.Errorf("cannot unread '\r' char at the end of chunk size: %w", err),
error: fmt.Errorf("cannot unread '\\r' char at the end of chunk size: %w", err),
}
}
break
Expand Down

0 comments on commit 7b74fc9

Please sign in to comment.