# CVE-2024-29186: Slow String Operations via MultiPart Requests in Event-Driven Functions

> Attackers can cause excessive CPU usage and billing costs in Bref PHP serverless functions by sending crafted multipart requests that trigger slow string operations.

- **Severity:** Medium 5.3 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 22 Mar 2024
- **Updated:** 28 Aug 2024
- **Also known as:** GHSA-j4hq-f63x-f39r

## What is CVE-2024-29186?

CVE-2024-29186 is a medium-severity denial of service vulnerability in brefphp bref, published on 22 Mar 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Bref is an open-source project that helps users go serverless on Amazon Web Services with PHP. When Bref prior to version 2.1.17 is used with the Event-Driven Function runtime and the handler is a `RequestHandlerInterface`, then the Lambda event is converted to a PSR7 object. During the conversion process, if the request is a MultiPart, each part is parsed. In the parsing process, the `Content-Type` header of each part is read using the `Riverline/multipart-parser` library.

The library, in the `StreamedPart::parseHeaderContent` function, performs slow multi-byte string operations on the header value.
Precisely, the `mb_convert_encoding` function is used with the first (`$string`) and third (`$from_encoding`) parameters read from the header value.

An attacker could send specifically crafted requests which would force the server into performing long operations with a consequent long billed duration.

The attack has the following requirements and limitations: The Lambda should use the Event-Driven Function runtime and the `RequestHandlerInterface` handler and should implement at least an endpoint accepting POST requests; the attacker can send requests up to 6MB long (this is enough to cause a billed duration between 400ms and 500ms with the default 1024MB RAM Lambda image of Bref); and if the Lambda uses a PHP runtime <= php-82, the impact is higher as the billed duration in the default 1024MB RAM Lambda image of Bref could be brought to more than 900ms for each request. Notice that the vulnerability applies only to headers read from the request body as the request header has a limitation which allows a total maximum size of ~10KB.

Version 2.1.17 contains a fix for this issue.

Weakness: CWE-400 (Uncontrolled Resource Consumption)

## Which versions are affected by CVE-2024-29186?

2 open source packages ship an affected version, including bref/bref. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `bref/bref` | Packagist | All versions | 2.1.17 |
| `bref/bref` | Packagist | All versions | 2.1.17 |

Products: Mnapoli Bref.

## How do I fix CVE-2024-29186?

Upgrade bref/bref to 2.1.17 or later.

## Is CVE-2024-29186 being exploited?

There is no known exploitation of CVE-2024-29186 in the wild and no public exploit code.

## Other vulnerabilities in brefphp bref

- [CVE-2024-24752](https://insights.sbomify.com/CVE-2024-24752/): Bref Uploaded Files Not Deleted in Event-Driven Functions (medium 6.5)
- [CVE-2024-24753](https://insights.sbomify.com/CVE-2024-24753/): Bref Multiple Value Headers Not Supported in ApiGatewayFormatV2 (medium 4.8)
- [CVE-2024-24754](https://insights.sbomify.com/CVE-2024-24754/): Bref Body Parsing Inconsistency in Event-Driven Functions (low 3.7)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-29186 and fix it if it is affected.

What it is: CVE-2024-29186 is a medium-severity denial of service vulnerability in brefphp bref, published on 22 Mar 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-29186 in the wild and no public exploit code.

Affected packages and fixed versions:
- bref/bref (Packagist): affected all versions; fixed in 2.1.17
- bref/bref (Packagist): affected all versions; fixed in 2.1.17

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-29186/ (Markdown: https://insights.sbomify.com/CVE-2024-29186/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-29186
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-29186
- OSV: https://osv.dev/vulnerability/CVE-2024-29186

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-29186/
Summaries are generated and may contain mistakes; the official description above is the record.
