serde_with: KeyValueMap serialization panics on empty sequence or map entries
Description
The serde_with crate's KeyValueMap serializer has a flaw where it panics when serializing an empty sequence or map entry. This occurs because the serializer incorrectly assumes each mapped element has at least one key field and subtracts one from the length before validation, leading to a panic on empty entries. An attacker able to control serialized data can cause a denial of service by crashing the process during serialization.
CVSS v4.0
Affected software
Run on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.
Weaknesses
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
The KeyValueMap serializer in serde_with versions >=2.3.0 and <3.21.0 assumes that each mapped element contains at least one field or item to serve as the map key. It preallocates a vector with capacity of length minus one before verifying this assumption. If an attacker supplies an empty inner sequence or map entry, this leads to a panic due to Vec::with_capacity being called with an invalid size. This vulnerability can be triggered via serialization through serde_json::to_string or other Serde serializers when using #[serde_as(as = "KeyValueMap<_>")]. The root cause is improper length validation before vector preallocation in key_value_map.rs at multiple source locations.
Potential Impact
An attacker who can supply attacker-controlled data for serialization through the KeyValueMap serializer can cause the process to panic and terminate, resulting in a denial of service. There is no indication of privilege escalation or code execution. The impact is limited to local denial of service via process crash during serialization.
Mitigation Recommendations
A patch is available for this vulnerability. Users of serde_with should upgrade to version 3.21.0 or later where this issue is fixed. Until patched, avoid serializing attacker-controlled data with KeyValueMap or implement input validation to prevent empty sequences or map entries. No vendor advisory content contradicts this guidance.
Technical Details
- Gcve Source
- db.gcve.eu
- Osv Id
- GHSA-7gcf-g7xr-8hxj
- Osv Schema Version
- 1.4.0
- Ecosystems
- ["crates.io"]
- Database Specific Severity
- MODERATE
- Cvss Version
- 4.0
Threat ID: 6a58b40568715ace43d67084
Added to database: 07/16/2026, 10:35:49 UTC
Last enriched: 09/17/2026, 20:05:10 UTC
Last updated: 10/03/2026, 01:47:44 UTC
Views: 134
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.