Skip to content

Cap SPDX envelope unwrap depth to prevent quadratic re-parse#1

Merged
andrew merged 1 commit intomainfrom
fix/envelope-unwrap-depth
May 2, 2026
Merged

Cap SPDX envelope unwrap depth to prevent quadratic re-parse#1
andrew merged 1 commit intomainfrom
fix/envelope-unwrap-depth

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 2, 2026

parseSPDX recursively unwrapped {"sbom":...} and {"predicate":...} envelopes with no depth limit. Each level re-ran json.Unmarshal on the full nested raw bytes, so a deeply nested input like {"sbom":{"sbom":{"sbom":...}}} produced quadratic parse work and could be used as a DoS vector.

The recursion is now a bounded loop capped at maxEnvelopeDepth = 3, which is enough for the real-world cases (GitHub dependency-graph wraps once under sbom, in-toto attestations wrap once under predicate, and at most you'd see one inside the other). Anything deeper falls through to ErrUnrecognized.

Added TestSPDXGitHubEnvelope to confirm 1-2 levels of sbom wrapping still parse correctly, and TestSPDXEnvelopeDepthLimit to confirm a 100-level nest is rejected immediately.

@andrew andrew merged commit 58e4af0 into main May 2, 2026
2 checks passed
@andrew andrew deleted the fix/envelope-unwrap-depth branch May 2, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant