# GHSA-ghc8-5cgm-5rpf: Inventory fails to prohibit standard library access prior to initialization of Rust standard library runtime

> Attackers can execute arbitrary code before main initialization, potentially causing undefined behavior or crashes in Rust applications using the inventory crate.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 10 Sep 2023
- **Also known as:** RUSTSEC-2023-0057

## What is GHSA-ghc8-5cgm-5rpf?

GHSA-ghc8-5cgm-5rpf is a code injection vulnerability in inventory, published on 10 Sep 2023. 

### Official description

Affected versions allow arbitrary caller-provided code to execute before the lifetime of `main`.

If the caller-provided code accesses particular pieces of the standard library that require an initialized Rust runtime, such as `std::io` or `std::thread`, these may not behave as documented. Panics are likely; UB is possible.

The flaw was corrected by enforcing that only code written within the `inventory` crate, which is guaranteed not to access runtime-dependent parts of the standard library, runs before `main`. Caller-provided code is restricted to running at compile time.

## Which versions are affected by GHSA-ghc8-5cgm-5rpf?

3 open source packages ship an affected version, including inventory.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `inventory` | crates.io | All versions | 0.2.0 |
| `inventory` | crates.io | All versions | 0.2.0 |
| `inventory` | crates.io | From 0.0.0-0 | 0.2.0 |

## How do I fix GHSA-ghc8-5cgm-5rpf?

Upgrade inventory to 0.2.0 or later.

## Is GHSA-ghc8-5cgm-5rpf being exploited?

There is no known exploitation of GHSA-ghc8-5cgm-5rpf in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-ghc8-5cgm-5rpf and fix it if it is affected.

What it is: GHSA-ghc8-5cgm-5rpf is a code injection vulnerability in inventory, published on 10 Sep 2023. 
Exploitation: There is no known exploitation of GHSA-ghc8-5cgm-5rpf in the wild and no public exploit code.

Affected packages and fixed versions:
- inventory (crates.io): affected all versions; fixed in 0.2.0
- inventory (crates.io): affected all versions; fixed in 0.2.0
- inventory (crates.io): affected from 0.0.0-0; fixed in 0.2.0

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-ghc8-5cgm-5rpf/ (Markdown: https://insights.sbomify.com/GHSA-ghc8-5cgm-5rpf/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-ghc8-5cgm-5rpf

---
From sbomify Insights: https://insights.sbomify.com/GHSA-ghc8-5cgm-5rpf/
Summaries are generated and may contain mistakes; the official description above is the record.
