Repository navigation
test: pin the reported str.format dunder-traversal bypass - #8
Merged
Merged
Conversation
A report received by email showed that on 0.0.3-0.0.6 a dunder name inside a
str.format replacement field is a string literal, not an ast.Attribute node, so
the 0.0.6 'reject all __-prefixed attribute access' rule never saw it:
safe_eval("'{0.__globals__[HOST_SECRET]}'.format(helper)",
allow_attributes=True, allowed_vars={'helper': helper})
returns the host module's secret. The reporter (stilwel) scoped it to 0.0.6;
verification against the published wheels shows 0.0.3 through 0.0.6 all leak,
while 0.0.1/0.0.2 predate allow_attributes and raise TypeError.
No library change is needed: this is the same defect class 0.0.7 already fixed
in _FORMAT_STRING_TRAVERSES_ATTRIBUTES. This commit locks it down with tests.
Severity agrees with the reporter - disclosure, not execution. A replacement
field cannot contain a call, and its value is rendered to str. Confirmed that
the leak reads the helper's own module globals, cannot reach codesafe-internal
names, and does not chain to __builtins__['__import__'] in a callable form.
Also covers computed/concatenated templates (rejected because a non-literal
template cannot be inspected) and the format_map key path, and asserts that a
plain '{k}'.format_map({...}) keeps working since it can only read a mapping
the expression itself supplied.
All three tests fail on the published 0.0.6 and pass on 0.0.7. 114 tests pass.
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
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.
Regression tests for a bypass reported by email (stilwel,
stilwels@gmail.com).The report
On 0.0.3–0.0.6, dunder names inside a
str.formatreplacement field are string literals, notast.Attributenodes, so the 0.0.6 "reject all__-prefixed attribute access" rule never sees them:Verdict
Valid, and already fixed in 0.0.7 — no library change needed. This is the same defect class
_FORMAT_STRING_TRAVERSES_ATTRIBUTESalready closes; this PR locks it down with tests.Verified against the published wheels:
allow_attributes(TypeError)UnsafeExpressionErrorThe reporter scoped it to 0.0.6 only; the real range is 0.0.3 – 0.0.6.
Severity
Agrees with the reporter: disclosure, not RCE. A replacement field cannot contain a call, and its value is rendered to
str. Confirmed the leak reads the helper's own module globals, cannot reach codesafe-internal names (KeyError), and does not chain to a callable__import__.What the tests cover
__builtins__chaining attempts.join,chr()) — non-literal templates cannot be inspected, so they are rejected.format_mapkey path, plus an assertion that plain'{k}'.format_map({...})still works (it can only read a mapping the expression itself supplied).All three tests fail on the published 0.0.6 and pass on 0.0.7. 114 tests pass locally.