Zennoxa Shield
Rules / Rust
SHIELD-RUST-007

Insecure deserialization of untrusted bytes

mediumRustCWE-502CVSS 6.5

What it detects

Deserializing attacker-controlled bytes with bincode/rmp without validation is risky.

How to fix

Validate and bound input, and prefer self-describing formats with strict schemas.

Vulnerable — Shield flags thisjobs.rs
use serde::Deserialize;

#[derive(Deserialize)]
pub struct Job {
    pub id: u64,
    pub payload: Vec<u8>,
}

pub fn parse_job(bytes: &[u8]) -> Result<Job, Box<bincode::ErrorKind>> {
    // bytes arrive straight off the network queue
    bincode::deserialize(bytes)
}
Fixed — scans cleanjobs.rs
use serde::Deserialize;

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Job {
    pub id: u64,
    pub payload: String,
}

pub fn parse_job(bytes: &[u8]) -> serde_json::Result<Job> {
    // Self-describing format with a strict schema; input bounded upstream.
    serde_json::from_slice(bytes)
}

Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-RUST-007, the fixed one does not.

SHIELD-RUST-007: Insecure deserialization of untrusted bytes — Zennoxa Shield