Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Secure CodeBlock: close MatchClass policy bypass, default-deny child seccomp (SKY-15318) (#8377)
Aaron Perez90a98b6f4f91
diff --git a/skyvern/forge/sdk/workflow/code_block_safety.py b/skyvern/forge/sdk/workflow/code_block_safety.pyindex 8058b12cb..f04fb5730 100644--- a/skyvern/forge/sdk/workflow/code_block_safety.py+++ b/skyvern/forge/sdk/workflow/code_block_safety.py@@ -439,6 +439,18 @@ def _validate_tree()if not is_allowed_read and not is_self_super_private:raise error_factory("Not allowed to access private methods or attributes")+ # MatchClass keyword patterns read attributes without creating ast.Attribute nodes.+ if isinstance(node, ast.MatchClass):+ for attr in node.kwd_attrs:+ if attr in blocked_private_attrs:+ raise error_factory(f"Not allowed to access '{attr}'")+ if attr.startswith("_") and attr not in allowed_dunder_reads and attr not in allowed_private_reads:+ raise error_factory("Not allowed to access private methods or attributes")+ if attr in blocked_attrs:+ raise error_factory(f"Not allowed to access '{attr}'")+ # Positional patterns hide attribute names behind runtime-defined __match_args__.+ if node.patterns:+ raise error_factory("Not allowed to use positional patterns in match statements")if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Load) and node.id in blocked_names:raise error_factory(f"Not allowed to use '{node.id}'")if (diff --git a/tests/unit/test_code_block_sandbox.py b/tests/unit/test_code_block_sandbox.pyindex 8acd3933b..7bf375121 100644--- a/tests/unit/test_code_block_sandbox.py+++ b/tests/unit/test_code_block_sandbox.py@@ -84,6 +84,54 @@ class TestIsSafeCodeRejectsDunderAccess:CodeBlock.is_safe_code("x.__builtins__")+_MATCH_CLASS_POSITIONAL_BYPASS_CODE = (+ 'M = type("M", (type,), {"__instancecheck__": lambda s, o: True})\n'+ 'R = M("R", (), {"__match_args__": ("__globals__",)})\n'+ "match sleep:\n case R(g):\n result = g\n"+)+_MATCH_CLASS_CHECKERS = (CodeBlock.is_safe_code, is_safe_script_code)+++ ("checker", "error"),+ [(CodeBlock.is_safe_code, "private"), (is_safe_script_code, "globals")],+ ids=["codeblock", "script"],+)+def test_match_class_private_keyword_attribute_is_rejected(checker, error: str) -> None:+ with pytest.raises(InsecureCodeDetected, match=error):+ checker("match obj:\n case type(__globals__=g):\n result = g\n")++[email protected]("checker", _MATCH_CLASS_CHECKERS, ids=["codeblock", "script"])+ ("code", "error"),+ [+ ("match obj:\n case Session(_nonce=n):\n result = n\n", "private"),+ ("match obj:\n case Thing(popen=p):\n result = p\n", "popen"),+ (_MATCH_CLASS_POSITIONAL_BYPASS_CODE, "positional"),+ ("match obj:\n case Thing(x, y):\n result = x\n", "positional"),+ ("match obj:\n case Thing(x, attr=y):\n result = x\n", "positional"),+ ],+ ids=["private-keyword", "blocked-keyword", "dynamic-positional", "positional", "mixed-positional"],+)+def test_match_class_attribute_bypasses_are_rejected(checker, code: str, error: str) -> None:+ with pytest.raises(InsecureCodeDetected, match=error):+ checker(code)++[email protected]("checker", _MATCH_CLASS_CHECKERS, ids=["codeblock", "script"])+ "code",+ [+ "match point:\n case Point(x=0, y=0):\n result = 1\n",+ "match obj:\n case Thing():\n result = 1\n",+ ],+ ids=["keyword", "bare"],+)+def test_safe_match_class_patterns_are_accepted(checker, code: str) -> None:+ checker(code)++class TestIsSafeCodeRejectsBareDunderIdentifiers:"""Bare dunder names (not attribute access) must also be blocked."""