# GHSA-5w5r-mf82-595p: Unsound APIs of public `constant::Reader` and `StructSchema`

> Unsound APIs in the Rust library allow safe code to trigger undefined behavior, potentially leading to crashes or arbitrary code execution.

- **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:** 24 Dec 2025
- **Also known as:** RUSTSEC-2025-0143

## What is GHSA-5w5r-mf82-595p?

GHSA-5w5r-mf82-595p is a memory corruption vulnerability in capnp, published on 24 Dec 2025. 

### Official description

The safe API functions `constant::Reader::get` and `StructSchema::new` rely on `PointerReader::get_root_unchecked`, which can cause undefined behavior (UB) by constructing arbitrary words or schemas.

## `Reader::get`

```rust
pub fn get(&self) -> Result<<T as Owned>::Reader<'static>> {
    // ...
    // UNSAFE: access `words` without validation
}
```

## `StructSchema::new`

```rust
pub fn new(builder: RawBrandedStructSchema) -> StructSchema {
    // ...
    // UNSAFE: access encoded nodes without validation
}
```

This vulnerability allows safe Rust code to trigger UB, which violates Rust's safety guarantees.

The issue is resolved in version `0.24.0` by making constructor functions unsafe and mark the fields of struct as visible only in the crate.

## Which versions are affected by GHSA-5w5r-mf82-595p?

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


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

## How do I fix GHSA-5w5r-mf82-595p?

Upgrade capnp to 0.24.0 or later.

## Is GHSA-5w5r-mf82-595p being exploited?

There is no known exploitation of GHSA-5w5r-mf82-595p in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-5w5r-mf82-595p and fix it if it is affected.

What it is: GHSA-5w5r-mf82-595p is a memory corruption vulnerability in capnp, published on 24 Dec 2025. 
Exploitation: There is no known exploitation of GHSA-5w5r-mf82-595p in the wild and no public exploit code.

Affected packages and fixed versions:
- capnp (crates.io): affected all versions; fixed in 0.24.0
- capnp (crates.io): affected all versions; fixed in 0.24.0
- capnp (crates.io): affected from 0.0.0-0; fixed in 0.24.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-5w5r-mf82-595p/ (Markdown: https://insights.sbomify.com/GHSA-5w5r-mf82-595p/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-5w5r-mf82-595p

---
From sbomify Insights: https://insights.sbomify.com/GHSA-5w5r-mf82-595p/
Summaries are generated and may contain mistakes; the official description above is the record.
