File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2505,17 +2505,24 @@ func parseChunkSize(r *bufio.Reader) (int, error) {
25052505 c , err := r .ReadByte ()
25062506 if err != nil {
25072507 return - 1 , ErrBrokenChunk {
2508- error : fmt .Errorf ("cannot read '\r ' char at the end of chunk size: %w" , err ),
2508+ error : fmt .Errorf ("cannot read '\\ r' char at the end of chunk size: %w" , err ),
25092509 }
25102510 }
25112511 // Skip chunk extension after chunk size.
25122512 // Add support later if anyone needs it.
25132513 if c != '\r' {
2514+ // Security: Don't allow newlines in chunk extensions.
2515+ // This can lead to request smuggling issues with some reverse proxies.
2516+ if c == '\n' {
2517+ return - 1 , ErrBrokenChunk {
2518+ error : errors .New ("invalid character '\\ n' after chunk size" ),
2519+ }
2520+ }
25142521 continue
25152522 }
25162523 if err := r .UnreadByte (); err != nil {
25172524 return - 1 , ErrBrokenChunk {
2518- error : fmt .Errorf ("cannot unread '\r ' char at the end of chunk size: %w" , err ),
2525+ error : fmt .Errorf ("cannot unread '\\ r' char at the end of chunk size: %w" , err ),
25192526 }
25202527 }
25212528 break
You can’t perform that action at this time.
0 commit comments