github-advanced-security[bot] commented on code in PR #1154:
URL: https://github.com/apache/tomcat/pull/1154#discussion_r4589936904


##########
java/org/apache/coyote/http2/Http2UpgradeHandler.java:
##########
@@ -918,6 +921,83 @@
         return headerFrameBuffers;
     }
 
+
+    /**
+     * Removes the header fields that cannot be sent in a valid HTTP/2 
message, as HTTP/1.1 does. A header field with a
+     * name that is not a token, or with a value that contains a character 
that is not in the range 0 to 255, would
+     * otherwise make the encoder fail after it had updated its dynamic table. 
Control characters in a value are
+     * replaced with a space and leading and trailing whitespace is removed 
(RFC 9113, section 8.2.1).
+     *
+     * @param stream  the stream the headers are written to
+     * @param headers the headers to check. Invalid header fields are removed 
and invalid values are corrected.
+     */
+    private void removeInvalidHeaders(Stream stream, MimeHeaders headers) {
+        for (int i = 0; i < headers.size(); i++) {
+            String name = headers.getName(i).toString();
+            if (name.startsWith(":")) {
+                // Pseudo header fields are always generated by Tomcat
+                continue;
+            }
+            String value = headers.getValue(i).toString();
+            String validValue = HttpParser.isToken(name) ? 
sanitizeHeaderValue(value) : null;
+            if (validValue == null) {
+                log.warn(sm.getString("upgradeHandler.response.invalidHeader", 
connectionId, stream.getIdAsString(),
+                        name, value));
+                headers.removeHeader(i--);
+            } else if (validValue != value) {

Review Comment:
   ## CodeQL / Reference equality test on strings
   
   String values compared with !=.
   
   [Show more 
details](https://github.com/apache/tomcat/security/code-scanning/1293)



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to