CVE-2023-40586: Github.com/corazawaf/coraza/v3 Denial of Service Vulnerability

HIGH
Advisory Identifier: GHSA-c2pj-v37r-2p6h
CVSS 7.5
CWE-400
Published
Advisory Summary

CVE-2023-40586 is a HIGH (CVSS 7.5) denial of service vulnerability (CWE-400: Uncontrolled Resource Consumption) affecting Github.com/corazawaf/coraza/v3 libraries in the Go ecosystem. The issue involves coraza has potential denial of service vulnerability. Remediation is available by upgrading affected packages to version 3.0.1.

CVE-2023-40586 at a Glance

CVE Identifier CVE-2023-40586
GHSA Identifier GHSA-c2pj-v37r-2p6h
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-400: Uncontrolled Resource Consumption
Affected Product Github.com/corazawaf/coraza/v3
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 7.5

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

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

How to Fix CVE-2023-40586

To remediate this vulnerability, upgrade all affected Github.com/corazawaf/coraza/v3 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/corazawaf/coraza/v3 fixed: 3.0.1
Upgrade github.com/corazawaf/coraza/v3 to 3.0.1
github.com/corazawaf/coraza/v2 fixed: Latest secure release
Upgrade github.com/corazawaf/coraza/v2 to Latest secure release
Verify Direct and Transitive Dependencies

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

inspect dependencies for github.com/corazawaf/coraza/v3

How to Check if You Are Affected

To determine whether your application is affected by CVE-2023-40586, inspect your project dependencies for Github.com/corazawaf/coraza/v3:

inspect dependencies for github.com/corazawaf/coraza/v3

Analyze the terminal output to locate any version of Github.com/corazawaf/coraza/v3 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.0.1), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-400: Uncontrolled Resource Consumption, where the product does not properly control the allocation and maintenance of a limited resource. In Github.com/corazawaf/coraza/v3, 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 Due to the misuse of `log.Fatalf`, the application using coraza crashed after receiving crafted requests from attackers. ### Details https://github.com/corazawaf/coraza/blob/82157f85f24c6107667bf0f686b71a72aafdf8a5/internal/bodyprocessors/multipart.go#L26-L29 The bodyprocessors of multipart uses `log.Fatalf` to handle errors from the `mime.ParseMediaType`, but `log.Fatalf` calls `os.Exit` directly after logging the error. https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/log/log.go#L288-L291 This means that the application will immediately crash after receiving a malicious request that triggers an error in `mime.ParseMediaType`. ### PoC The server can be demonstrated by https://github.com/corazawaf/coraza/tree/main/examples/http-server After sending this request ``` POST / HTTP/1.1 Host: 127.0.0.1:8090 User-Agent: curl/8.1.2 Accept: */* Content-Length: 199 Content-Type: multipart/form-data; boundary=------------------------5fa6351b877326a1; a=1; a=2 Connection: close --------------------------5fa6351b877326a1 Content-Disposition: form-data; name="file"; filename="123" Content-Type: application/octet-stream 123 --------------------------5fa6351b877326a1-- ``` The server will crash immediately. The `a=1; a=2` in `Content-Type` makes `mime: duplicate parameter name` error. ### Impact I believe the vulnerability was introduced by the following commit: https://github.com/corazawaf/coraza/commit/24af0c8cf4f10bab558740b595712be3b85493ec. ### Mitigation The error from `mime.ParseMediaType` should return directly.

CVE-2023-40586 Affected Github.com/corazawaf/coraza/v3 Versions

2 component(s)
Fixed Versions:
3.0.1
Product / Package Ecosystem Affected Versions Fixed Version
github.com/corazawaf/coraza/v3
Go
≥ 3.0.0
< 3.0.1
3.0.1
github.com/corazawaf/coraza/v2
Go
≥ 2.0.0
≤ 2.0.1

References

Frequently Asked Questions

What is CVE-2023-40586?
CVE-2023-40586 is a security vulnerability in Github.com/corazawaf/coraza/v3 involving Coraza has potential denial of service vulnerability under CWE-400: Uncontrolled Resource Consumption.
Which Github.com/corazawaf/coraza/v3 versions are affected?
Affected versions include releases prior to 3.0.1 across affected packages: github.com/corazawaf/coraza/v3, github.com/corazawaf/coraza/v2.
What version fixes CVE-2023-40586?
Upgrading to 3.0.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/corazawaf/coraza/v3 affected?
Yes, github.com/corazawaf/coraza/v3 is affected in releases prior to 3.0.1. Upgrade your dependency to 3.0.1 or later.
Is github.com/corazawaf/coraza/v2 affected?
Yes, github.com/corazawaf/coraza/v2 is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
What is the CVSS score of CVE-2023-40586?
CVE-2023-40586 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2023-40586?
CVE-2023-40586 is classified under CWE-400: Uncontrolled Resource Consumption (The product does not properly control the allocation and maintenance of a limited resource.).
How can I check Go dependencies for CVE-2023-40586?
Run the dependency tree command: 'inspect dependencies for github.com/corazawaf/coraza/v3'. 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-c2pj-v37r-2p6h",
  "modified" : "2023-08-25T21:35:14Z",
  "published" : "2023-06-26T15:48:33Z",
  "aliases" : [ "CVE-2023-40586" ],
  "summary" : "Coraza has potential denial of service vulnerability",
  "details" : "### Summary\n\nDue to the misuse of `log.Fatalf`, the application using coraza crashed after receiving crafted requests from attackers.\n\n### Details\n\nhttps://github.com/corazawaf/coraza/blob/82157f85f24c6107667bf0f686b71a72aafdf8a5/internal/bodyprocessors/multipart.go#L26-L29\nThe bodyprocessors of multipart uses `log.Fatalf` to handle errors from the `mime.ParseMediaType`, but `log.Fatalf` calls `os.Exit` directly after logging the error.\nhttps://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/log/log.go#L288-L291\nThis means that the application will immediately crash after receiving a malicious request that triggers an error in `mime.ParseMediaType`.\n\n### PoC\n\nThe server can be demonstrated by https://github.com/corazawaf/coraza/tree/main/examples/http-server\n\nAfter sending this request\n```\nPOST / HTTP/1.1\nHost: 127.0.0.1:8090\nUser-Agent: curl/8.1.2\nAccept: */*\nContent-Length: 199\nContent-Type: multipart/form-data; boundary=------------------------5fa6351b877326a1; a=1; a=2\nConnection: close\n\n--------------------------5fa6351b877326a1\nContent-Disposition: form-data; name=\"file\"; filename=\"123\"\nContent-Type: application/octet-stream\n\n123\n\n--------------------------5fa6351b877326a1--\n\n```\nThe server will crash immediately. The `a=1; a=2` in `Content-Type` makes `mime: duplicate parameter name` error.\n\n### Impact\n\nI believe the vulnerability was introduced by the following commit: https://github.com/corazawaf/coraza/commit/24af0c8cf4f10bab558740b595712be3b85493ec.\n\n### Mitigation\n\nThe error from `mime.ParseMediaType` should return directly.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/corazawaf/coraza/v3"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.0"
      }, {
        "fixed" : "3.0.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/corazawaf/coraza/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "last_affected" : "2.0.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/corazawaf/coraza/security/advisories/GHSA-c2pj-v37r-2p6h"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-40586"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/corazawaf/coraza-caddy/issues/48"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/corazawaf/coraza/commit/24af0c8cf4f10bab558740b595712be3b85493ec"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/corazawaf/coraza/commit/a5239ba3ce839e14d9b4f9486e1b4a403dcade8c"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/corazawaf/coraza/commit/e1b119b83e12c64f0957e00e8cad45a1b5f012f8"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/corazawaf/coraza"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/corazawaf/coraza/blob/82157f85f24c6107667bf0f686b71a72aafdf8a5/internal/bodyprocessors/multipart.go#L26-L29"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/corazawaf/coraza/releases/tag/v3.0.1"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/log/log.go#L288-L291"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-400" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-06-26T15:48:33Z",
    "nvd_published_at" : "2023-08-25T21:15:09Z"
  }
}