π‘οΈ Sentinel: [CRITICAL] Fix arbitrary code execution in AST eval#379
π‘οΈ Sentinel: [CRITICAL] Fix arbitrary code execution in AST eval#379bashandbone wants to merge 1 commit into
Conversation
Added a strict whitelist for function calls allowed within type annotations evaluated by `ast.Call` nodes. This mitigates a potential Arbitrary Code Execution (ACE) vulnerability where `eval()` could be tricked into executing any callable within the `globalns` dictionary. Added the relevant finding to the sentinel journal. 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 guide (collapsed on small PRs)Reviewer's GuideRestricts the AST-based safe eval mechanism for type strings to only allow calls to a small, explicit whitelist of functions and documents the security issue and mitigation in the Sentinel security notes. 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:
- The
allowed_funcsset is hardcoded insidegeneric_visit; consider centralizing this whitelist as a module-level constant or shared configuration so it can be reused and updated consistently across the codebase. - For
ast.Attributecalls you currently only checknode.func.attr, which ignores the full attribute path; if calls likesome_module.Dependsshould be allowed or disallowed differently, you may want to validate the fully qualified name instead of just the final attribute. - When
func_namecannot be resolved (e.g., non-Name/Attributecallables), you raise aTypeErrorwithfunc_nameasNone; consider emitting a more explicit error message in this case to make debugging rejected type strings clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `allowed_funcs` set is hardcoded inside `generic_visit`; consider centralizing this whitelist as a module-level constant or shared configuration so it can be reused and updated consistently across the codebase.
- For `ast.Attribute` calls you currently only check `node.func.attr`, which ignores the full attribute path; if calls like `some_module.Depends` should be allowed or disallowed differently, you may want to validate the fully qualified name instead of just the final attribute.
- When `func_name` cannot be resolved (e.g., non-`Name`/`Attribute` callables), you raise a `TypeError` with `func_name` as `None`; consider emitting a more explicit error message in this case to make debugging rejected type strings clearer.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 application was using
eval()to dynamically resolve type annotations from strings. It validated the AST structure to only permit safe nodes. However, it blindly allowed genericast.Callnodes. This created an Arbitrary Code Execution (ACE) vulnerability, because any valid callable existing in theglobalnsdictionary (or builtins) could be executed during evaluation if present in the type string.π― Impact: An attacker who could control or inject a malicious type string could potentially execute arbitrary code on the host machine.
π§ Fix: Implemented strict whitelisting within
TypeValidator.generic_visit(). When anast.Callnode is encountered, the code now explicitly checks that the function being called is specifically one of the intended whitelisted functions (Depends,depends,Field,PrivateAttr,Tag,Parameter). If the function call does not match the whitelist, aTypeErroris raised, preventing the evaluation.β Verification: Verified by code review, unit tests (
tests/unit/core/), and integration tests (tests/integration/providers/).PR created automatically by Jules for task 17667289194909456202 started by @bashandbone
Summary by Sourcery
Harden type-string evaluation by restricting callable usage in AST-based validation and document the resolved arbitrary code execution vulnerability in Sentinel notes.
Bug Fixes:
Callnodes.Documentation: