Skip to content

Improve diagnostic message for invalid HTTP header names #33209

@mrsaldana

Description

@mrsaldana

Summary
When an invalid character is detected in an HTTP header name during parsing, the current error message shows only the index:

Header name contained an invalid character 6

This is misleading and can be misread as "character 6 is invalid". For zero migration, the exact prefix for this message can be preserved, but we should append a better diagnostic that identifies the invalid character and its location on the token.

Motivation
During recent testing triage this message caused confusion as the value is not the invalid character, but rather the index within the name token. Adding extra diagnostic to common malformed characters (CR|LF|TAB) will help reduce triaging time as the exact bad actor will be clearly identified.

Example

Before:
Header name contained an invalid character 6

After:
Header name contained an invalid character 6 | char=\u0020(SPACE) code=32(0x20) pos=7 name="Accept -Encoding"

Testing
Included an internal API test for the HttpHeaderKey class that tests this particular validation method.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

General Issues

Relationships

None yet

Development

No branches or pull requests

Issue actions