Skip to content

Rust unsafe-deserialization: guidance for byte-bounded serde_json input #23372

Backlog

Description

@jatinkray

The Rust rust/unsafe-deserialization rule recommends validating input size before deserialization. Its good example checks a byte limit before calling serde_json::from_slice.

With CodeQL CLI 2.27.6 and codeql/rust-queries@0.1.48, I observed that the query still reports this call pattern when the input is a modeled remote source and the oversized branch returns before parsing. The public example illustrates the guard I mean. I am not including application source or alert URLs.

The current query extension appears to handle modeled and type-based barriers, but does not appear to recognize dominating byte-length checks by default. Is the continued report intentional because a size check alone is insufficient? If so, what additional validation does the rule expect, and can the help clarify what the query recognizes? If this is a modeling gap, could you add a query test covering the documented pattern with a modeled remote source?

I am not asking to treat all bounded JSON as safe: a byte limit is not a bound on every downstream allocation or operation. The goal is to distinguish what the documented check actually mitigates from the risk that the rule still intends to report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions