Repository navigation
Commit 6d4411f
test: pin the reported str.format dunder-traversal bypass
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>1 parent e10a97d commit 6d4411f
1 file changed
Lines changed: 65 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
838 | 838 | | |
839 | 839 | | |
840 | 840 | | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
841 | 906 | | |
842 | 907 | | |
843 | 908 | | |
| |||
0 commit comments