Skip to content

Commit 5be13c6

Browse files
net.http: reject malformed Content-Length in H2Conn
A non-numeric Content-Length value (e.g. '12junk') caused all_digits() to return false on the combined condition, silently leaving has_content_length false and skipping the body-length completeness check. The response was then returned successfully despite the invalid header. Split the condition so a present-but-non-numeric value returns a stream error ('h2: malformed Content-Length: <value>') instead of being silently ignored. RFC 9113 §8.2.1 requires malformed field values to be rejected. Co-Authored-By: WOZCODE <contact@withwoz.com>
1 parent 4b2bc70 commit 5be13c6

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

vlib/net/http/h2_conn.v

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,13 @@ fn (mut c H2Conn) read_response(stream_id u32, req H2ClientRequest) !H2ClientRes
228228
// Only update body_expected on the first (non-1xx) HEADERS
229229
// frame. A content-length field in a trailer must not
230230
// overwrite the value used for the completeness check below.
231-
if !got_headers && f.name == 'content-length' && all_digits(f.value) {
232-
body_expected = f.value.u64()
233-
has_content_length = true
231+
if !got_headers && f.name == 'content-length' {
232+
if all_digits(f.value) {
233+
body_expected = f.value.u64()
234+
has_content_length = true
235+
} else {
236+
return error('h2: malformed Content-Length: ${f.value}')
237+
}
234238
}
235239
}
236240
}

0 commit comments

Comments
 (0)