← back to index

S5693 — HTTP request content length should be limited

Language: VB.NET  |  Type: VULNERABILITY  |  Severity: Major

Tags: cwe, former-hotspot

Enforcing a maximum HTTP request content length limits how much data the server must accept per request, which helps control resource use and reduces the risk of denial-of-service attacks.

Why is this an issue?

Accepting HTTP requests without an upper bound on their content length exposes the application to Denial of Service (DoS) attacks. An attacker can send arbitrarily large requests that exhaust server memory, disk space, or processing capacity before the application can reject them. This rule detects when no maximum content length is configured, or when the configured limit exceeds the recommended thresholds (8 MB for file uploads, 2 MB for other requests).

What is the potential impact?

Denial of Service

An attacker who can send oversized HTTP requests can exhaust server resources—memory, CPU threads, or network bandwidth—causing the application to slow down or become completely unavailable. Even a single large upload can tie up a worker process and prevent other users from being served.

How to fix it in ASP.NET Core

Use RequestSizeLimit or RequestFormLimits attributes to enforce a maximum request body size.

Code examples

Noncompliant code example

Imports Microsoft.AspNetCore.Mvc

Public Class MyController
    Inherits Controller

    <HttpPost>
    <DisableRequestSizeLimit> ' Noncompliant: No size limit
    Public Function UnboundedPost(ByVal model As Model) As IActionResult
    ' ...
    End Function

    <HttpPost>
    <RequestSizeLimit(10485760)> ' Noncompliant
    Public Function PostRequest(ByVal model As Model) As IActionResult
    ' ...
    End Function

    <HttpPost>
    <RequestFormLimits(MultipartBodyLengthLimit = 10485760)> ' Noncompliant
    Public Function MultipartFormRequest(ByVal model As Model) As IActionResult
    ' ...
    End Function

End Class

Compliant solution

Imports Microsoft.AspNetCore.Mvc

Public Class MyController
    Inherits Controller

    <HttpPost>
    <RequestSizeLimit(8388608)>
    Public Function PostRequest(ByVal model As Model) As IActionResult
    ' ...
    End Function

    <HttpPost>
    <RequestFormLimits(MultipartBodyLengthLimit = 8388608)>
    Public Function MultipartFormRequest(ByVal model As Model) As IActionResult
    ' ...
    End Function

End Class

Resources

Documentation

Articles & blog posts

Standards