Repository navigation
fix: cap integer products, concatenation, nested collections and % formatting in the restricted evaluator - #687
Merged
Conversation
…rmatting in the restricted evaluator The restricted evaluator capped ** and sequence replication with *, but a small untrusted document could still build a huge value: a product of two integers, a sequence concatenation with +, a nested collection that repeats a reference (cheap to build, but compared, hashed or printed item by item), or % string formatting sized by its field width. Cap the integer product, measure every sequence and collection the evaluator builds by the size of its nested items counted per reference, and reject % on str and bytes operands. Signed-off-by: Fernando Macedo <fgmacedo@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #687 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 53 53
Lines 5816 5857 +41
Branches 926 936 +10
=========================================
+ Hits 5816 5857 +41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
The restricted evaluator used by
io.load()with the defaulttrusted=Falsepromises that a small expression cannot exhaust CPU or memory. The caps added in 3.2.1 covered**and sequence replication with*only, so a small untrusted document could still build a huge value through other operators or through collections that repeat a reference.What changes
int * intis capped by result bits, like**.seq * n,seq + seqand every list, tuple, set and dict literal are capped by a reference-expanded size (_value_size): a shared reference counts every time it appears, memoized by identity so the measurement stays cheap.%onstr/bytesoperands (printf-style formatting) is rejected; numeric%is unaffected.docs/io/security.mdand the 3.2.2 release notes describe the caps, including the%formatting change under "Behavior changes".Evidence
tests/test_spec_parser_values.pyandtests/io/test_security.py(SCXML, JSON and YAML) for each rejected form and for ordinary arithmetic and collections that keep working.Not verified
in/iscomparisons in a restricted expression still fail with a rawKeyErrorat load time (pre-existing, the document is still rejected); left for a follow-up.