Add proxy logging and code counts for methods that are invalid tokens RFC 9110 specifies that a `method` is a `token` but Balsa does not do proper token validation of the method that it parses. We utilize a newly added `IsValidToken` function that properly enforces this grammar. We exhaustively cover the valid range of US-ASCII input and beyond. There are four primary cases: 1. Graphical characters: currently, Balsa allows 17 characters from this range which it should not, they will all be logged. 2. Control characters (without whitespace): when control characters are found, Balsa properly strips them and does not return them with the method. 3. Extended ASCII characters (i.e. 128 and higher): Balsa currently allows methods with these characters but it should not. These will all be logged as well. 4. Whitespace control characters: all whitespace characters are technically invalid tokens but since their presence changes the flow of parsing, Balsa does not include them with the method so they will not be logged. Relevant grammar: ``` tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA token = 1*tchar method = token ``` Protected by logging only. PiperOrigin-RevId: 827685964
diff --git a/quiche/balsa/balsa_frame_test.cc b/quiche/balsa/balsa_frame_test.cc index a0dfcac..8bdb4d5 100644 --- a/quiche/balsa/balsa_frame_test.cc +++ b/quiche/balsa/balsa_frame_test.cc
@@ -16,6 +16,8 @@ #include <utility> #include <vector> +#include "absl/container/flat_hash_set.h" +#include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" @@ -25,6 +27,8 @@ #include "quiche/balsa/balsa_enums.h" #include "quiche/balsa/balsa_headers.h" #include "quiche/balsa/balsa_visitor_interface.h" +#include "quiche/balsa/header_api.h" +#include "quiche/balsa/header_properties.h" #include "quiche/balsa/http_validation_policy.h" #include "quiche/balsa/noop_balsa_visitor.h" #include "quiche/balsa/simple_buffer.h"