GHSA-7gcf-g7xr-8hxj: serde_with KeyValueMap Serialization Panics On Empty Vulnerability
MODERATEGHSA-7gcf-g7xr-8hxj is a MODERATE keyvaluemap serialization panics on empty vulnerability (CWE-20: Improper Input Validation) affecting serde_with libraries in the crates.io ecosystem. The issue involves keyvaluemap serialization panics on empty sequence or map entries. Remediation is available by upgrading affected packages to version 3.21.0.
GHSA-7gcf-g7xr-8hxj at a Glance
How to Fix GHSA-7gcf-g7xr-8hxj
To remediate this vulnerability, upgrade all affected serde_with dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade serde_with to 3.21.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for serde_with
How to Check if You Are Affected
To determine whether your application is affected by GHSA-7gcf-g7xr-8hxj, inspect your project dependencies for serde_with:
inspect dependencies for serde_with
Analyze the terminal output to locate any version of serde_with in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.21.0), 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-20: Improper Input Validation, where the product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly. In serde_with, 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
GHSA-7gcf-g7xr-8hxj Affected serde_with Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
serde_with
|
crates.io |
≥ 2.3.0
< 3.21.0
|
3.21.0
|
References
Frequently Asked Questions
What is GHSA-7gcf-g7xr-8hxj?
Which serde_with versions are affected?
What version fixes GHSA-7gcf-g7xr-8hxj?
Is serde_with affected?
What CWE is associated with GHSA-7gcf-g7xr-8hxj?
How can I check crates.io dependencies for GHSA-7gcf-g7xr-8hxj?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-7gcf-g7xr-8hxj",
"modified" : "2026-08-31T14:18:13Z",
"published" : "2026-07-15T22:41:01Z",
"aliases" : [ ],
"summary" : "serde_with: KeyValueMap serialization panics on empty sequence or map entries",
"details" : "### Summary\n\nThe public `KeyValueMap` serializer assumes that each mapped element has at least one field or item to use as the map key, but it subtracts `1` from the caller-visible length before validating that assumption. An application that serializes attacker-controlled data through `#[serde_as(as = \"KeyValueMap<_>\")]` can be crashed by an empty inner sequence or map entry.\n\n### Details\n\nThe affected public surface includes:\n\n- Serialization of `#[serde_as(as = \"KeyValueMap<_>\")]` values through `serde_json::to_string` or any other Serde serializer`\n- Public `KeyValueMap` conversions for sequence and map-backed entries`\n\nThe root cause is: The `KeyValueMap` serializer preallocating `Vec::with_capacity(len - 1)` or `Vec::with_capacity(len.unwrap_or(17) - 1)` before checking that the element actually contains the required first key field or item.\n\nThe vulnerable data/control flow is: attacker-controlled empty entry -> `serde_json::to_string` -> `KeyValueMap<TAs>::serialize_as` -> `SeqAsMapSerializer::{serialize_seq,serialize_map}` -> `Vec::with_capacity(len - 1)` or `Vec::with_capacity(len.unwrap_or(17) - 1)` -> panic\n\nRelevant source locations:\n\n- `serde_with/src/key_value_map.rs:590`\n- `serde_with/src/key_value_map.rs:599`\n- `serde_with/src/key_value_map.rs:613`\n- `serde_with/src/key_value_map.rs:632`\n- `serde_with/src/key_value_map.rs:648`\n\n### PoC\n\n```rust\n/*\n[dependencies]\nserde = {version = \"*\", features = [\"derive\"]}\nserde_with = \"*\"\nserde_json = \"*\"\n*/\n\nuse serde::Serialize;\nuse serde_with::{serde_as, KeyValueMap};\n\n#[derive(Serialize)]\n#[serde(transparent)]\nstruct Seq(Vec<String>);\n\n#[serde_as]\n#[derive(Serialize)]\n#[serde(transparent)]\nstruct KVMap {\n #[serde_as(as = \"KeyValueMap<_>\")]\n foo: Vec<Seq>,\n}\n\nfn main() {\n let value = KVMap {\n foo: vec![Seq(Vec::new())],\n };\n let _ = serde_json::to_string(&value).unwrap();\n}\n```\n\n### Impact\n\nA local attacker who can trigger serialization of attacker-controlled data through `KeyValueMap` can terminate the process, causing a denial of service.",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "crates.io",
"name" : "serde_with"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.3.0"
}, {
"fixed" : "3.21.0"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/jonasbb/serde_with/security/advisories/GHSA-7gcf-g7xr-8hxj"
}, {
"type" : "WEB",
"url" : "https://github.com/jonasbb/serde_with/pull/966"
}, {
"type" : "WEB",
"url" : "https://github.com/jonasbb/serde_with/commit/c8a1d820ea25df01692b367058d587343e199389"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/jonasbb/serde_with"
}, {
"type" : "WEB",
"url" : "https://github.com/jonasbb/serde_with/compare/v2.2.0...v2.3.0"
}, {
"type" : "WEB",
"url" : "https://github.com/jonasbb/serde_with/releases/tag/v3.21.0"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-20" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2026-07-15T22:41:01Z",
"nvd_published_at" : null
}
}