All rules
CA2262Usage Enabled by default: As suggestion

Set MaxResponseHeadersLength properly

Set MaxResponseHeadersLength properly

Microsoft docs

Description

The System.Net.Http.HttpClientHandler.MaxResponseHeadersLength property is measured in kilobytes, not bytes. The default maximum length is 64 KB, which should be large enough for a majority of use cases. If you set the property to a value greater than 128 kilobytes, it might be due to a misunderstanding of the units of this property.

Cause

The System.Net.Http.HttpClientHandler.MaxResponseHeadersLength property is set to a value greater than 128.

How to fix violations

If you intended to set a smaller value, update it to the desired value measured in kilobytes.

Example

HttpClientHandler handler = new()
{
    // Violation
    MaxResponseHeadersLength = 512

    // Fix (it is not possible to specify a limit lower than 1 KB)
    MaxResponseHeadersLength = 1
};

When to suppress

It's safe to suppress this warning if the large value is intended.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0