CVE-2024-40642: Netty incubator codec bhttp Absent Input Validation Vulnerability

HIGH
Advisory Identifier: GHSA-q8f2-hxq5-cp4h
CVSS 8.1
CWE-20
Published
Advisory Summary

CVE-2024-40642 is a HIGH (CVSS 8.1) absent input validation vulnerability (CWE-20: Improper Input Validation) affecting Netty incubator codec bhttp libraries in the Maven ecosystem. The issue involves absent input validation in binaryhttpparser. Remediation is available by upgrading affected packages to version 0.0.13.Final.

CVE-2024-40642 at a Glance

CVE Identifier CVE-2024-40642
GHSA Identifier GHSA-q8f2-hxq5-cp4h
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-20: Improper Input Validation
Affected Product Netty incubator codec bhttp
Package Ecosystem Maven
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-40642

To remediate this vulnerability, upgrade all affected Netty incubator codec bhttp dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

io.netty.incubator:netty-incubator-codec-bhttp fixed: 0.0.13.Final
<dependency>
    <groupId>io.netty.incubator</groupId>
    <artifactId>netty-incubator-codec-bhttp</artifactId>
    <version>0.0.13.Final</version>
</dependency>
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

mvn dependency:tree -Dincludes=io.netty.incubator

How to Check if You Are Affected

To determine whether your Java application is affected by CVE-2024-40642, inspect your build dependencies using the Maven Dependency Plugin:

mvn dependency:tree -Dincludes=io.netty.incubator

Analyze the terminal output to locate any version of Netty incubator codec bhttp in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.0.13.Final), your application is affected.

Note: The mvn dependency:tree -Dincludes=io.netty.incubator command inspects the resolved dependency graph declared in your project's POM files; it does not perform automated security scanning or inspect runtime dynamic classpaths. Always verify runtime container classpaths and shaded JARs.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-20: Improper Input Validation, where the product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly. In Netty incubator codec bhttp, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary `BinaryHttpParser` does not properly validate input values thus giving attackers almost complete control over the HTTP requests constructed from the parsed output. Attackers can abuse several issues individually to perform various injection attacks including HTTP request smuggling, desync attacks, HTTP header injections, request queue poisoning, caching attacks and Server Side Request Forgery (SSRF). Attacker could also combine several issues to create well-formed messages for other text-based protocols which may result in attacks beyond the HTTP protocol. ### Details **Path, Authority, Scheme** The BinaryHttpParser class implements the readRequestHead method which performs most of the relevant parsing of the received request. The data structure prefixes values with a variable length integer value. The algorithm to create a variable length integer value is below: ``` def encode_int(n): if n < 64: base = 0x00 l = 1 elif n in range(64, 16384): base = 0x4000 l = 2 elif n in range(16384, 1073741824): base = 0x80000000 l = 4 else: base = 0xc000000000000000 l = 8 encoded = base | n return encoded.to_bytes() ``` The parsing code below first gets the lengths of the values from the prefixed variable length integer. After it has all of the lengths and calculates all of the indices, the parser casts the applicable slices of the ByteBuf to String. Finally, it passes these values into a new `DefaultBinaryHttpRequest` object where no further parsing or validation occurs. ``` //netty-incubator-codec-ohttp/codec-bhttp/src/main/java/io/netty/incubator/codec/bhttp/BinaryHttpParser.java public final class BinaryHttpParser { ... private static BinaryHttpRequest readRequestHead(ByteBuf in, boolean knownLength, int maxFieldSectionSize) { ... final long pathLength = getVariableLengthInteger(in, pathLengthIdx, pathLengthBytes); ... final int pathIdx = pathLengthIdx + pathLengthBytes; ... /*417*/ String method = in.toString(methodIdx, (int) methodLength, StandardCharsets.US_ASCII); /*418*/ String scheme = in.toString(schemeIdx, (int) schemeLength, StandardCharsets.US_ASCII); /*419*/ String authority = in.toString(authorityIdx, (int) authorityLength, StandardCharsets.US_ASCII); /*420*/ String path = in.toString(pathIdx, (int) pathLength, StandardCharsets.US_ASCII); /*422*/ BinaryHttpRequest request = new DefaultBinaryHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method), scheme, authority, path, headers); in.skipBytes(sumBytes); return request; } ... } ``` **Request Method** On line 422 above, the parsed method value is passed into `HttpMethod.valueOf` method. The return value from this is passed to the `DefaultBinaryHttpRequest` constructor. Below is the code for HttpMethod.valueOf: ``` public static HttpMethod valueOf(String name) { // fast-path if (name == HttpMethod.GET.name()) { return HttpMethod.GET; } if (name == HttpMethod.POST.name()) { return HttpMethod.POST; } // "slow"-path HttpMethod result = methodMap.get(name); return result != null ? result : new HttpMethod(name); } ``` If the result of `methodMap.get` is not `null`, then a new arbitrary `HttpMethod` instance will be returned using the provided name value. `methodMap` is an instance of type `EnumNameMap` which is also defined within the `HttpMethod` class: ``` EnumNameMap(Node<T>... nodes) { this.values = (Node[])(new Node[MathUtil.findNextPositivePowerOfTwo(nodes.length)]); this.valuesMask = this.values.length - 1; Node[] var2 = nodes; int var3 = nodes.length; for(int var4 = 0; var4 < var3; ++var4) { Node<T> node = var2[var4]; int i = hashCode(node.key) & this.valuesMask; if (this.values[i] != null) { throw new IllegalArgumentException("index " + i + " collision between values: [" + this.values[i].key + ", " + node.key + ']'); } this.values[i] = node; } } T get(String name) { Node<T> node = this.values[hashCode(name) & this.valuesMask]; return node != null && node.key.equals(name) ? node.value : null; } ``` Note that `EnumNameMap.get()` returns a boolean value, which is not `null`. Therefore, any arbitrary http verb used within a `BinaryHttpRequest` will yield a valid `HttpMethod` object. When the `HttpMethod` object is constructed, the name is checked for whitespace and similar characters. Therefore, we cannot perform complete injection attacks using the HTTP verb alone. However, when combined with the other input validation issues, such as that in the path field, we can construct somewhat arbitrary data blobs that satisfy text-based protocol message formats. ### Impact Method is partially validated while other values are not validated at all. Software that relies on netty to apply input validation for binary HTTP data may be vulnerable to various injection and protocol based attacks.

CVE-2024-40642 Affected Netty incubator codec bhttp Versions

1 component(s)
Fixed Versions:
0.0.13.Final
Product / Package Ecosystem Affected Versions Fixed Version
io.netty.incubator:netty-incubator-codec-bhttp
Maven
< 0.0.13.Final
0.0.13.Final

References

Frequently Asked Questions

What is CVE-2024-40642?
CVE-2024-40642 is a security vulnerability in Netty incubator codec bhttp involving Absent Input Validation in BinaryHttpParser under CWE-20: Improper Input Validation.
Which Netty incubator codec bhttp versions are affected?
Affected versions include releases prior to 0.0.13.Final across affected packages: io.netty.incubator:netty-incubator-codec-bhttp.
What version fixes CVE-2024-40642?
Upgrading to 0.0.13.Final (or the latest patched release for your respective branch) resolves the vulnerability.
Is netty-incubator-codec-bhttp affected?
Yes, io.netty.incubator:netty-incubator-codec-bhttp is affected in releases prior to 0.0.13.Final. Upgrade your dependency to 0.0.13.Final or later.
What is the CVSS score of CVE-2024-40642?
CVE-2024-40642 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-40642?
CVE-2024-40642 is classified under CWE-20: Improper Input Validation (The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly.).
How can I check Maven dependencies for CVE-2024-40642?
Run the dependency tree command: 'mvn dependency:tree -Dincludes=io.netty.incubator'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-q8f2-hxq5-cp4h",
  "modified" : "2024-07-19T14:17:55Z",
  "published" : "2024-07-18T22:14:28Z",
  "aliases" : [ "CVE-2024-40642" ],
  "summary" : "Absent Input Validation in BinaryHttpParser",
  "details" : "### Summary\n`BinaryHttpParser` does not properly validate input values thus giving attackers almost complete control over the HTTP requests constructed from the parsed output. Attackers can abuse several issues individually to perform various injection attacks including HTTP request smuggling, desync attacks, HTTP header injections, request queue poisoning, caching attacks and Server Side Request Forgery (SSRF). Attacker could also combine several issues to create well-formed messages for other text-based protocols which may result in attacks beyond the HTTP protocol.\n\n### Details\n\n**Path, Authority, Scheme**\nThe BinaryHttpParser class implements the readRequestHead method which performs most of the relevant parsing of the received request. The data structure prefixes values with a variable length integer value. The algorithm to create a variable length integer value is below:\n\n```\ndef encode_int(n):\n    if n < 64:\n        base = 0x00\n        l = 1\n    elif n in range(64, 16384):\n        base = 0x4000\n        l = 2\n    elif n in range(16384, 1073741824):\n        base = 0x80000000\n        l = 4\n    else:\n        base = 0xc000000000000000\n        l = 8\n   encoded = base | n\n   return encoded.to_bytes()\n```\n\nThe parsing code below first gets the lengths of the values from the prefixed variable length integer. After it has all of the lengths and calculates all of the indices, the parser casts the applicable slices of the ByteBuf to String. Finally, it passes these values into a new `DefaultBinaryHttpRequest` object where no further parsing or validation occurs.\n\n```\n//netty-incubator-codec-ohttp/codec-bhttp/src/main/java/io/netty/incubator/codec/bhttp/BinaryHttpParser.java\n\npublic final class BinaryHttpParser {\n   ...\n    private static BinaryHttpRequest readRequestHead(ByteBuf in, boolean knownLength, int maxFieldSectionSize) {\n        ...\n        final long pathLength = getVariableLengthInteger(in, pathLengthIdx, pathLengthBytes);\n        ...\n        final int pathIdx = pathLengthIdx + pathLengthBytes;\n        ...\n/*417*/ String method = in.toString(methodIdx, (int) methodLength, StandardCharsets.US_ASCII);\n/*418*/ String scheme = in.toString(schemeIdx, (int) schemeLength, StandardCharsets.US_ASCII);\n/*419*/ String authority = in.toString(authorityIdx, (int) authorityLength, StandardCharsets.US_ASCII);\n/*420*/ String path = in.toString(pathIdx, (int) pathLength, StandardCharsets.US_ASCII);\n\n/*422*/ BinaryHttpRequest request = new DefaultBinaryHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method),\n                scheme, authority, path, headers);\n        in.skipBytes(sumBytes);\n        return request;\n    }\n   ...\n}\n```\n\n**Request Method**\nOn line 422 above, the parsed method value is passed into `HttpMethod.valueOf` method. The return value from this is passed to the `DefaultBinaryHttpRequest` constructor.\n\nBelow is the code for HttpMethod.valueOf:\n\n```\n    public static HttpMethod valueOf(String name) {\n        // fast-path\n        if (name == HttpMethod.GET.name()) {\n            return HttpMethod.GET;\n        }\n        if (name == HttpMethod.POST.name()) {\n            return HttpMethod.POST;\n        }\n        // \"slow\"-path\n        HttpMethod result = methodMap.get(name);\n        return result != null ? result : new HttpMethod(name);\n    }\n```\n\nIf the result of `methodMap.get` is not `null`, then a new arbitrary `HttpMethod` instance will be returned using the provided name value.\n\n`methodMap` is an instance of type `EnumNameMap` which is also defined within the `HttpMethod` class:\n\n```\n        EnumNameMap(Node<T>... nodes) {\n            this.values = (Node[])(new Node[MathUtil.findNextPositivePowerOfTwo(nodes.length)]);\n            this.valuesMask = this.values.length - 1;\n            Node[] var2 = nodes;\n            int var3 = nodes.length;\n\n            for(int var4 = 0; var4 < var3; ++var4) {\n                Node<T> node = var2[var4];\n                int i = hashCode(node.key) & this.valuesMask;\n                if (this.values[i] != null) {\n                    throw new IllegalArgumentException(\"index \" + i + \" collision between values: [\" + this.values[i].key + \", \" + node.key + ']');\n                }\n\n                this.values[i] = node;\n            }\n\n        }\n\n        T get(String name) {\n            Node<T> node = this.values[hashCode(name) & this.valuesMask];\n            return node != null && node.key.equals(name) ? node.value : null;\n        }\n```\n\nNote that `EnumNameMap.get()` returns a boolean value, which is not `null`. Therefore, any arbitrary http verb used within a `BinaryHttpRequest` will yield a valid `HttpMethod` object. When the `HttpMethod` object is constructed, the name is checked for whitespace and similar characters. Therefore, we cannot perform complete injection attacks using the HTTP verb alone. However, when combined with the other input validation issues, such as that in the path field, we can construct somewhat arbitrary data blobs that satisfy text-based protocol message formats.\n\n### Impact\nMethod is partially validated while other values are not validated at all. Software that relies on netty to apply input validation for binary HTTP data may be vulnerable to various injection and protocol based attacks.\n\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "io.netty.incubator:netty-incubator-codec-bhttp"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.0.13.Final"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/netty/netty-incubator-codec-ohttp/security/advisories/GHSA-q8f2-hxq5-cp4h"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-40642"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/netty/netty-incubator-codec-ohttp/commit/b687a0cf6ea1030232ea204d73bce82f2698e571"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/netty/netty-incubator-codec-ohttp"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-20" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-07-18T22:14:28Z",
    "nvd_published_at" : "2024-07-18T23:15:02Z"
  }
}