Always scan HTTP/1.x header lines for lone CR and invalid characters in BalsaFrame

go/balsa-hardening-gfe

BalsaFrame only ran `CheckHeaderLinesForInvalidChars` when the invalid chars level was `kError`, so parsers at `kOff` (such as GFE2 backend responses) never recorded defects or code counts for lone CRs or invalid header characters.

Run the check unconditionally, so both are detected at any level. Enforcement is unchanged: nothing is rejected at `kOff`.
- Lone CR is now detected at any level. It is still only rejected at `kError`, when `disallow_lone_cr_in_request_headers` is set.
- Invalid header characters are now detected at any level, recording a new `invalid_header_value_character` protocol defect and an `invalid_header_value_character_detected` code count. They are still only rejected at `kError`, which now also records an `invalid_header_value_character_enforced` code count.
- At `kOff`, the scan continues past an invalid header character, so a later lone CR is still detected.

The new defect is logged as `HttpProtocolDefects.invalid_header_value_character` (new field in `gfe_log.proto`). `LogsProtocolErrorsForResponses` in `logging_test` covers the response case.

PiperOrigin-RevId: 1026447913
diff --git a/quiche/balsa/balsa_frame.cc b/quiche/balsa/balsa_frame.cc
index 4340cac..6a82140 100644
--- a/quiche/balsa/balsa_frame.cc
+++ b/quiche/balsa/balsa_frame.cc
@@ -800,14 +800,21 @@
   const char* stream_end =
       headers->OriginalHeaderStreamBegin() + lines.back().second;
 
+  const bool check_invalid_chars = invalid_chars_error_enabled();
   for (const char* c = stream_begin; c < stream_end; c++) {
     if (header_properties::IsInvalidHeaderChar(*c)) {
-      return true;
+      if (check_invalid_chars) {
+        return true;
+      }
+      continue;
     }
     if (*c == '\r' && c + 1 < stream_end && *(c + 1) != '\n') {
-      QUICHE_CODE_COUNT(lone_cr_in_request_headers_detected);
-      protocol_defects_.lone_cr_in_request_headers = true;
-      if (http_validation_policy().disallow_lone_cr_in_request_headers) {
+      if (!protocol_defects_.lone_cr_in_request_headers) {
+        QUICHE_CODE_COUNT(lone_cr_in_request_headers_detected);
+        protocol_defects_.lone_cr_in_request_headers = true;
+      }
+      if (check_invalid_chars &&
+          http_validation_policy().disallow_lone_cr_in_request_headers) {
         QUICHE_CODE_COUNT(disallow_lone_cr_in_request_headers_enforced);
         return true;
       }
@@ -822,8 +829,7 @@
   QUICHE_DCHECK(!lines.empty());
   QUICHE_DVLOG(1) << "******@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@**********\n";
 
-  if (invalid_chars_error_enabled() &&
-      CheckHeaderLinesForInvalidChars(lines, headers)) {
+  if (CheckHeaderLinesForInvalidChars(lines, headers)) {
     HandleError(BalsaFrameEnums::INVALID_HEADER_CHARACTER);
     return;
   }
diff --git a/quiche/balsa/balsa_frame.h b/quiche/balsa/balsa_frame.h
index 99b1e2f..ab25019 100644
--- a/quiche/balsa/balsa_frame.h
+++ b/quiche/balsa/balsa_frame.h
@@ -216,7 +216,8 @@
   void ProcessHeaderLines(const Lines& lines, bool is_trailer,
                           BalsaHeaders* headers);
 
-  // Returns true if there are invalid characters, false otherwise.
+  // Records protocol defects for invalid header characters and lone CRs.
+  // Returns true if the lines must be rejected because of either.
   bool CheckHeaderLinesForInvalidChars(const Lines& lines,
                                        const BalsaHeaders* headers);