diff options
| author | Colin Watson <cjwatson@debian.org> | 2025-05-07 09:03:40 +0100 |
|---|---|---|
| committer | git-ubuntu importer <ubuntu-devel-discuss@lists.ubuntu.com> | 2025-05-07 16:53:52 +0000 |
| commit | 1262972e79dfd2dbe9de8642c6023efe78ac27aa (patch) | |
| tree | 6311c5b382389b2aef82bf94a011a7f8398eff19 | |
| parent | d02b7057b47c226ce0fa238b7e817411caeda0e8 (diff) | |
| parent | caa93e4e0a9bc2e2d88414d4f0f672e56ba04731 (diff) | |
2.0.5-1 (patches applied)applied/2.0.5-1applied/ubuntu/resolute-develapplied/ubuntu/resoluteapplied/ubuntu/questing-proposedapplied/ubuntu/questing-develapplied/ubuntu/questingapplied/ubuntu/develapplied/debian/sid
Imported using git-ubuntu import.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | NOTES | 4 | ||||
| -rw-r--r-- | PKG-INFO | 2 | ||||
| -rw-r--r-- | debian/changelog | 6 | ||||
| -rw-r--r-- | ev.py | 60 | ||||
| -rwxr-xr-x | evalidate/__init__.py | 2 | ||||
| -rw-r--r-- | x.py | 47 | ||||
| -rw-r--r-- | xx.py | 26 | ||||
| -rw-r--r-- | xx2.py | 27 | ||||
| -rw-r--r-- | xx3.py | 29 | ||||
| -rw-r--r-- | y.py | 9 |
11 files changed, 9 insertions, 204 deletions
@@ -4,3 +4,4 @@ evalidate.egg-info/ *pyc build/ dist/ +.local/ @@ -1,4 +0,0 @@ -add security verification for attrs/nodes ... (test all jailbreaks against configuration) -rebuild __builtins__ ? -make fast filter code? (verify it, extend, and run as fast filter) -try asteval filtering, maybe faster
\ No newline at end of file @@ -1,6 +1,6 @@ Metadata-Version: 2.4 Name: evalidate -Version: 2.0.4 +Version: 2.0.5 Summary: Validation and secure evaluation of untrusted python expressions Project-URL: Homepage, https://github.com/yaroslaff/evalidate Project-URL: Issues, https://github.com/yaroslaff/evalidate/issues diff --git a/debian/changelog b/debian/changelog index 6514023..e7cc0a1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +python-evalidate (2.0.5-1) unstable; urgency=medium + + * New upstream release. + + -- Colin Watson <cjwatson@debian.org> Wed, 07 May 2025 09:03:40 +0100 + python-evalidate (2.0.4-1) unstable; urgency=medium * New upstream release. @@ -1,60 +0,0 @@ -from evalidate import Expr, base_eval_model, ExecutionException -import sys - -my_model = base_eval_model.clone() -my_model.nodes.extend( - [ - "Call", - "Attributes", - "ListComp", - "DictComp", - "comprehension", - "Store", - "ForOfStatement", - "Subscript", - "GeneratorExp", - "For", - ] -) -my_model.allowed_functions.append("sum") -my_model.allowed_functions.append("len") - -my_shelve = { - "height": 200, - "boxes": { - "box1": {"volume": 110}, - "box2": {"volume": 90}, - }, - "column_width": [20, 480, 40], -} - -box_volumes = [my_shelve["boxes"][box]["volume"] for box in my_shelve["boxes"]] -total_volume = sum(box_volumes) -print(total_volume) - -# works fine -exp_string = "sum( my_shelve['column_width'])" -exp = Expr(exp_string, my_model) -print("code:", exp.code) -res = exp.eval({"my_shelve": my_shelve}) -print(res) - - -# throws an Exception: -# evalidate.ExecutionException: name 'my_shelve' is not defined - -# exp_string = "sum([my_shelve['boxes'][box]['volume'] for box in my_shelve['boxes'] ])" -# exp_string = "sum([my_shelve['boxes'][box]['volume'] for box in my_shelve['boxes'] ])" -exp_string = "len(my_shelve)" -exp = Expr(exp_string, my_model) - -#print("basic eval") -#res = eval(exp.code, dict(), {"my_shelve": my_shelve}) -#print("basic res:",res) -# sys.exit(0) -try: - res = exp.eval({"my_shelve": my_shelve}) -except ExecutionException as e: - print(e) - -# print(res) diff --git a/evalidate/__init__.py b/evalidate/__init__.py index d5b4a6c..3042d78 100755 --- a/evalidate/__init__.py +++ b/evalidate/__init__.py @@ -6,7 +6,7 @@ import ast import dataclasses from typing import Callable -__version__ = '2.0.4' +__version__ = '2.0.5' class EvalException(Exception): @@ -1,47 +0,0 @@ -import evalidate - -def eval_expression(input_string): - # Step 1 - allowed_names = {"sum": sum, "int": int, "a":1, "b":2, 'startswith': str.startswith} - # Step 2 - code = compile(input_string, "<string>", "eval") - # Step 3 - print(code.co_names) - for name in code.co_names: - if name not in allowed_names: - # Step 4 - raise NameError(f"Use of {name!r} not allowed") - return eval(code, {"__builtins__": {}}, allowed_names) - -try: - src=""" -(lambda fc=( - lambda n: [ - c for c in - ().__class__.__bases__[0].__subclasses__() - if c.__name__ == n - ][0] - ): - fc("function")( - fc("code")( - 0,0,0,0,0,0,b"BOOM",(),(),(),"","",0,b"" - ),{} - )() -)() -""" - - - #src = "'asdf'.startswith('as')" - #src2 ="""__builtins__['eval']("print(1)")""" - - #node = evalidate.evalidate(src, - # addnodes=['Call', 'Attribute', 'ListComp', 'comprehension', 'Store'], - # attrs=['startswith']) - #code = compile(node, '<test>', 'eval') - #r = eval(code) - #print("eval:", r) - - r = eval_expression(src) - print(r) -except Exception as e: - print(e)
\ No newline at end of file @@ -1,26 +0,0 @@ -import evalidate -from dataclasses import dataclass -from evalidate import Expr, EvalException, base_eval_model - -@dataclass -class Person: - name: str - weight: float - -john = Person(name="John", weight=100) -jack = Person(name="Jack", weight=60) -passengers = {"john": john, "jack": jack} - -sum_expr = "john.weight + jack.weight" - -mymodel = base_eval_model.clone() -mymodel.nodes.append('Attribute') -mymodel.attributes.append('weight') - -validated_expr = evalidate.Expr(sum_expr, model=mymodel) - - -total_weight = eval(validated_expr.code, passengers, None) - -print(total_weight) - @@ -1,27 +0,0 @@ -from dataclasses import dataclass -from evalidate import Expr, EvalException, base_eval_model - -@dataclass -class Person: - name: str - weight: float - - def get_weight(self): - return self.weight - -john = Person(name="John", weight=100) -jack = Person(name="Jack", weight=60) -passengers = {"john": john, "jack": jack} - -sum_expr = "john.get_weight() + jack.get_weight()" - -mymodel = base_eval_model.clone() -mymodel.nodes.extend(['Attribute', 'Call']) -mymodel.attributes.append('get_weight') - -validated_expr = Expr(sum_expr, model=mymodel) - -total_weight = eval(validated_expr.code, passengers, None) - -print(total_weight) - @@ -1,29 +0,0 @@ -import evalidate -from dataclasses import dataclass -from evalidate import Expr, EvalException, base_eval_model - -@dataclass -class Person: - name: str - weight: float - - def get_weight(self): - return self.weight - -john = Person(name="John", weight=100) -jack = Person(name="Jack", weight=60) -passengers = {"john": john, "jack": jack} - -sum_expr = "john.get_weight() + jack.get_weight()" - -mymodel = - -mymodel.nodes.extend(['Attribute', 'Call']) -mymodel.attributes.append('get_weight') - -validated_expr = evalidate.Expr(sum_expr, model=mymodel) - -total_weight = eval(validated_expr.code, {"john": john, "jack": jack}, None) - -print(total_weight) - @@ -1,9 +0,0 @@ -from evalidate import Expr, EvalException - -src = '-a + 40 > b' -# src = "__import__('os').system('clear')" - -try: - print(Expr(src).eval({'a':10, 'b':42})) -except EvalException as e: - print(e) |
