Skip to content

Commit ceae8f6

Browse files
Move the SECURITY: comment to the add call it explains.
1 parent fda76fa commit ceae8f6

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

‎lib/protocol/http1/body/chunked.rb‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,13 @@ def as_json(...)
148148
private
149149

150150
# Read the trailer from the connection, and add any headers to the trailer.
151-
#
152-
# SECURITY: Received trailers are added to the same headers object as the header section and are not marked with `Headers#trailer!`. This is not a smuggling vector: `add(..., trailer: true)` rejects any field whose policy does not permit it as a trailer, so a field such as `content-length` or `host` cannot arrive here, and position in the message does not change what a permitted field means. Marking them would make a buffering proxy re-send them as trailers and drop them from non-chunked responses. Whether the `Generic` fallback policy should permit unknown fields as trailers is tracked in socketry/protocol-http#127.
153151
def read_trailer
154152
while line = @connection.read_line
155153
# Empty line indicates end of trailer:
156154
break if line.empty?
157155

158156
if match = line.match(HEADER)
157+
# SECURITY: Received trailers join the same headers object as the header section and are not marked with `trailer!`. This is not a smuggling vector: `trailer: true` rejects any field whose policy does not permit it as a trailer, so a field such as `content-length` or `host` cannot arrive here, and position in the message does not change what a permitted field means. Marking them would make a buffering proxy re-send them as trailers and drop them from non-chunked responses. Whether the `Generic` fallback policy should permit unknown fields as trailers is tracked in socketry/protocol-http#127.
159158
@headers.add(match[1], match[2], trailer: true)
160159
else
161160
raise BadHeader, "Could not parse header: #{line.inspect}"

0 commit comments

Comments
 (0)