🛡️ Sentinel: [CRITICAL] Fix arbitrary code execution vulnerability in AST evaluation#385
🛡️ Sentinel: [CRITICAL] Fix arbitrary code execution vulnerability in AST evaluation#385bashandbone wants to merge 1 commit into
Conversation
… AST evaluation Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's GuideRestricts AST-based type string evaluation to a small, explicit set of safe callables to close an arbitrary code execution vulnerability, and documents the incident in the Sentinel security log. Sequence diagram for restricted AST call validation in type evaluationsequenceDiagram
participant ClientCode
participant ast
participant TypeValidator
ClientCode->>ast: parse(type_str, mode=eval)
ast-->>ClientCode: ast.AST tree
ClientCode->>TypeValidator: generic_visit(ast_tree)
loop visit_nodes
TypeValidator->>TypeValidator: generic_visit(node)
alt node is ast.Call
alt node.func is ast.Name and id in {Depends, depends, Field, PrivateAttr, Tag, Parameter}
TypeValidator-->>TypeValidator: is_allowed = True
else node.func is ast.Attribute and attr in {Depends, depends, Field, PrivateAttr, Tag, Parameter}
TypeValidator-->>TypeValidator: is_allowed = True
else forbidden callable
TypeValidator-->>ClientCode: raise TypeError(Forbidden function call in type string.)
end
else non_call_node
TypeValidator-->>TypeValidator: super().generic_visit(node)
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
🤖 Hi @bashandbone, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
|
🤖 I'm sorry @bashandbone, but I was unable to process your request. Please see the logs for more details. |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider extracting the allowed callable names into a single shared constant or set so that
ast.Nameandast.Attributechecks don’t duplicate hardcoded string lists and are easier to maintain. - You might want to make the error message include the attempted function name (where available) to aid debugging when a forbidden call is encountered, while still keeping it generic enough not to leak unnecessary details.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the allowed callable names into a single shared constant or set so that `ast.Name` and `ast.Attribute` checks don’t duplicate hardcoded string lists and are easier to maintain.
- You might want to make the error message include the attempted function name (where available) to aid debugging when a forbidden call is encountered, while still keeping it generic enough not to leak unnecessary details.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
🚨 Severity: CRITICAL
💡 Vulnerability: The type validation logic using
ast.parse(type_str, mode="eval")allowed genericast.Callnodes to pass. Even though standard Python literal types were blocked, any accessible callable within the execution environment's scope could be arbitrarily executed, leading to a critical Arbitrary Code Execution (ACE) vulnerability during type resolution.🎯 Impact: An attacker could potentially inject unvalidated configuration strings into the dependency container to achieve arbitrary code execution.
🔧 Fix: Explicitly restrict allowed callables in the
TypeValidatorto a predefined whitelist instead of broadly allowing theast.Callclass. Implemented rigorous AST node visitation checks that explicitly validate bothnode.func.idandnode.func.attr. Allowed specific, required functions likeDepends,depends,Field,PrivateAttr,Tag, andParameter.✅ Verification: Ran format, lint (
mise //:format,mise //:check), and the test suite (uv run pytest tests/unit/ tests/di/ --no-cov) to ensure correct validation logic and no regressions.PR created automatically by Jules for task 4402007923819433601 started by @bashandbone
Summary by Sourcery
Restrict dynamic AST-evaluated type strings to a small whitelist of safe callable names to close an arbitrary code execution vulnerability in the DI container.
Bug Fixes:
TypeValidator.Documentation: