# GHSA-rcx8-48pc-v9q8: mail-internals use-after-free vulnerability in `vec_insert_bytes`

> A use-after-free in the mail-internals Rust library allows attackers to execute arbitrary code or cause denial of service via crafted email data.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** No
- **Published:** 7 Aug 2023
- **Also known as:** RUSTSEC-2023-0054

## What is GHSA-rcx8-48pc-v9q8?

GHSA-rcx8-48pc-v9q8 is an use after free vulnerability in mail-internals, published on 7 Aug 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Incorrect reallocation logic in the function [`vec_insert_bytes`](https://docs.rs/mail-internals/0.2.3/mail_internals/utils/fn.vec_insert_bytes.html) causes a use-after-free.

This function does not have to be called directly to trigger the vulnerability because many methods on [`EncodingWriter`](https://docs.rs/mail-internals/0.2.3/mail_internals/encoder/struct.EncodingWriter.html) call this function internally.

The mail-\* suite is unmaintained and the upstream sources have been actively vandalised.
A fixed `mail-internals-ng` (and `mail-headers-ng` and `mail-core-ng`) crate has been published which fixes this, and a dependency on another unsound crate.

## Which versions are affected by GHSA-rcx8-48pc-v9q8?

3 open source packages ship an affected version, including mail-internals.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `mail-internals` | crates.io | From 0.0.0-0 | None |
| `mail-internals` | crates.io | From 0.2.0 to 0.2.3 | None |
| `mail-internals` | crates.io | From 0.2.0 to 0.2.3 | None |

## How do I fix GHSA-rcx8-48pc-v9q8?

No fix has been published for GHSA-rcx8-48pc-v9q8 yet. Limit exposure of the affected software until one is available.

## Is GHSA-rcx8-48pc-v9q8 being exploited?

There is no known exploitation of GHSA-rcx8-48pc-v9q8 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-rcx8-48pc-v9q8 and fix it if it is affected.

What it is: GHSA-rcx8-48pc-v9q8 is an use after free vulnerability in mail-internals, published on 7 Aug 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-rcx8-48pc-v9q8 in the wild and no public exploit code.

Affected packages and fixed versions:
- mail-internals (crates.io): affected from 0.0.0-0; no fix listed
- mail-internals (crates.io): affected from 0.2.0 up to 0.2.3; no fix listed
- mail-internals (crates.io): affected from 0.2.0 up to 0.2.3; no fix listed

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/GHSA-rcx8-48pc-v9q8/ (Markdown: https://insights.sbomify.com/GHSA-rcx8-48pc-v9q8/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-rcx8-48pc-v9q8

---
From sbomify Insights: https://insights.sbomify.com/GHSA-rcx8-48pc-v9q8/
Summaries are generated and may contain mistakes; the official description above is the record.
