zwoop commented on code in PR #13420:
URL: https://github.com/apache/trafficserver/pull/13420#discussion_r4428859419
##########
src/proxy/hdrs/VersionConverter.cc:
##########
@@ -200,8 +201,27 @@ VersionConverter::_convert_req_from_2_to_1(HTTPHdr
&header) const
// :authority
if (MIMEField *field = header.field_find(PSEUDO_HEADER_AUTHORITY);
field != nullptr && field->value_is_valid(is_control_BIT | is_ws_BIT)) {
- auto authority{field->value_get()};
- header.m_http->u.req.m_url_impl->set_host(header.m_heap, authority, true);
+ auto value{field->value_get()};
+
+ // No host to parse, and url_parse_internet() reads *start before checking
the length.
+ if (value.empty()) {
+ return ParseResult::ERROR;
+ }
+
+ // Copy out first: allocating from header.m_heap may coalesce it and free
the field's storage.
+ ts::LocalBuffer<char> buf(value.length());
+ std::string_view authority{buf.data(), value.length()};
+
+ std::copy(value.begin(), value.end(), buf.data());
+
+ // Require full consumption: url_parse_internet() stops at a '/', '?' or
'#'.
+ const char *astart = authority.data();
+ const char *aend = authority.data() + authority.length();
+
+ if (url_parse_internet(header.m_heap, header.m_http->u.req.m_url_impl,
&astart, aend, true, true) != ParseResult::DONE ||
+ astart != aend) {
+ return ParseResult::ERROR;
+ }
Review Comment:
Fixed in 54e35de5b2: `parse_req_would_accept()` now leaves CONNECT to
`parse_req()`, since an authority-form target has no Host field to vet its
userinfo or port. Such a request falls back to the existing 400 path. Covered
by "a CONNECT request" in `HdrParseReqWouldAccept`.
##########
src/proxy/hdrs/HTTP.cc:
##########
@@ -1292,6 +1293,40 @@ validate_hdr_content_length(HdrHeap *heap, HTTPHdrImpl
*hh)
return ParseResult::DONE;
}
+bool
+HTTPHdr::parse_req_would_accept(int strict_uri_parsing, size_t
max_request_line_size, size_t max_hdr_field_size)
+{
+ auto method{this->method_get()};
+ URL *url = this->url_get();
+
+ if (method.empty() || !std::all_of(method.begin(), method.end(),
&ParseRules::is_token)) {
+ return false;
+ }
Review Comment:
Fixed in 54e35de5b2. `method_get()` returns the WKS spelling once an index
is set, while `print()` writes the stored one, so the gate now runs
`hdrtoken_method_tokenize()` on the stored spelling and falls back when the
result differs from `method_get_wksidx()`. Covered by "a method that matches a
known one only without case".
##########
src/proxy/http2/Http2Stream.cc:
##########
@@ -864,15 +925,35 @@ Http2Stream::update_write_request(bool call_update)
// Process the new data
if (!this->parsing_header_done) {
- // Still parsing the request or response header
int bytes_used = 0;
ParseResult state;
- if (this->is_outbound_connection()) {
+ HTTPHdr *send_hdr = this->_pending_send_header();
+
+ if (send_hdr != nullptr) {
+ // Field by field: copy() would wipe the pseudo-headers create(HTTP_2_0)
reserved.
+ if (this->is_outbound_connection()) {
+ this->_send_header.method_set(send_hdr->method_get());
Review Comment:
Fixed in 54e35de5b2. The field-by-field copy moved into
`http2_copy_send_header()`, which sets the method with the index `parse_req()`
gave it instead of tokenizing it again, so an extension method `head` stays
`head` and is not framed as HEAD. Covered by "copy a send header with an
extension method and padded values" in `test_HTTP2`.
##########
src/proxy/hdrs/HTTP.cc:
##########
@@ -1292,6 +1293,40 @@ validate_hdr_content_length(HdrHeap *heap, HTTPHdrImpl
*hh)
return ParseResult::DONE;
}
+bool
+HTTPHdr::parse_req_would_accept(int strict_uri_parsing, size_t
max_request_line_size, size_t max_hdr_field_size)
+{
+ auto method{this->method_get()};
+ URL *url = this->url_get();
+
+ if (method.empty() || !std::all_of(method.begin(), method.end(),
&ParseRules::is_token)) {
+ return false;
+ }
+ // A CONNECT target is authority-form, so parse_req() checks its userinfo;
it has no Host for validate_hdr_host().
+ if (!url_is_uri_compliant(strict_uri_parsing, url->user_get()) ||
Review Comment:
Fixed in 54e35de5b2 by the same change as the CONNECT userinfo thread:
CONNECT no longer takes the direct path, so `parse_req()` checks the full
target, port text included.
##########
src/proxy/hdrs/HTTP.cc:
##########
@@ -1292,6 +1293,40 @@ validate_hdr_content_length(HdrHeap *heap, HTTPHdrImpl
*hh)
return ParseResult::DONE;
}
+bool
+HTTPHdr::parse_req_would_accept(int strict_uri_parsing, size_t
max_request_line_size, size_t max_hdr_field_size)
+{
+ auto method{this->method_get()};
+ URL *url = this->url_get();
+
+ if (method.empty() || !std::all_of(method.begin(), method.end(),
&ParseRules::is_token)) {
+ return false;
+ }
+ // A CONNECT target is authority-form, so parse_req() checks its userinfo;
it has no Host for validate_hdr_host().
+ if (!url_is_uri_compliant(strict_uri_parsing, url->user_get()) ||
+ !url_is_uri_compliant(strict_uri_parsing, url->password_get()) ||
+ !url_is_uri_compliant(strict_uri_parsing, this->path_get()) ||
!url_is_uri_compliant(strict_uri_parsing, this->query_get()) ||
+ !url_is_uri_compliant(strict_uri_parsing, this->fragment_get())) {
+ return false;
+ }
+ // Upper bound of the serialized "METHOD URL HTTP/1.1\r\n", so parse_req()
makes the exact call.
+ if (method.size() + static_cast<size_t>(url->length_get()) + 12 >
max_request_line_size) {
+ return false;
+ }
+ for (auto const &field : *this) {
+ auto name{field.name_get()};
+ auto value{field.value_get()};
+
+ // parse_req() drops or rejects a name with any non-field-name character,
and trims values.
+ if (name.empty() || name.size() + value.size() > max_hdr_field_size ||
+ !std::all_of(name.begin(), name.end(),
&ParseRules::is_http_field_name) ||
+ (!value.empty() && (ParseRules::is_ws(value.front()) ||
ParseRules::is_ws(value.back())))) {
+ return false;
+ }
+ }
+ return validate_hdr_host(m_http) == ParseResult::DONE &&
validate_hdr_content_length(m_heap, m_http) == ParseResult::DONE;
Review Comment:
Fixed in 54e35de5b2. The gate now falls back before
`validate_hdr_content_length()` can delete anything: duplicate Content-Length
fields, or Content-Length together with Transfer-Encoding, go through
`parse_req()`, so `request_header_max_size` counts their bytes. Covered by "a
duplicate Content-Length" and "a Content-Length with Transfer-Encoding".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]