Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Arbitrary Code Execution in ast.Call dynamic type resolution#389

Open
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-ace-ast-call-3684479189248078740
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Arbitrary Code Execution in ast.Call dynamic type resolution#389
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-ace-ast-call-3684479189248078740

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: Unrestricted dynamic type evaluation eval() allowed arbitrary ast.Call execution. By supplying a maliciously crafted type string to the restricted environment, arbitrary Python functions present in the environment's __builtins__ or global namespace could be executed.
🎯 Impact: High risk of Arbitrary Code Execution (ACE) allowing malicious logic execution within the host environment.
πŸ”§ Fix: Implemented strict whitelisting within TypeValidator to only allow explicit and known ast.Call nodes (Depends, depends, Field, PrivateAttr, Tag, Parameter). Also accommodated explicitly prefixed functions (e.g., cyclopts.Parameter). Rejected unknown functions with a TypeError.
βœ… Verification: Tested against standard unit tests and locally verified that arbitrary functions are rejected. Added a corresponding security journal entry tracking the vulnerability.


PR created automatically by Jules for task 3684479189248078740 started by @bashandbone

Summary by Sourcery

Harden dynamic type evaluation in the DI container to prevent arbitrary code execution and document the security fix in the Sentinel journal.

Bug Fixes:

  • Block arbitrary function execution during type-string evaluation by strictly whitelisting allowed ast.Call targets in the TypeValidator.

Documentation:

  • Add a Sentinel security journal entry describing the ast.Call-based arbitrary code execution vulnerability, its root cause, and the mitigation.

…mic type resolution

Implemented strict whitelisting for `ast.Call` nodes during dynamic type evaluation in `src/codeweaver/core/di/container.py` to prevent Arbitrary Code Execution (ACE) vulnerabilities. Only verified, trusted functions (Depends, depends, Field, PrivateAttr, Tag, Parameter) are allowed.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai

sourcery-ai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Restricts dynamic type evaluation in the DI container by whitelisting allowed ast.Call targets during type-string evaluation and documents the security fix in the Sentinel journal.

Sequence diagram for whitelisted ast.Call validation in _safe_eval_type

sequenceDiagram
    participant Caller
    participant Container
    participant TypeValidator
    participant AST

    Caller->>Container: _safe_eval_type(type_str, globalns)
    Container->>AST: parse(type_str)
    Container->>TypeValidator: visit(parsed_ast)
    loop visit_nodes
        TypeValidator->>TypeValidator: generic_visit(node)
        alt [node is ast.Call]
            TypeValidator->>TypeValidator: extract func_name
            TypeValidator->>TypeValidator: check func_name in allowed_funcs
            alt [func_name not allowed]
                TypeValidator-->>Container: raise TypeError
                Container-->>Caller: TypeError
            else [func_name allowed]
                TypeValidator-->>Container: continue
            end
        else [node not ast.Call]
            TypeValidator-->>Container: continue
        end
    end
    Container-->>Caller: evaluated_type_or_None
Loading

File-Level Changes

Change Details Files
Harden type-string evaluation in the DI container against arbitrary function execution via ast.Call.
  • Extend _safe_eval_type TypeValidator.generic_visit to inspect ast.Call nodes and extract the called function name from ast.Name or ast.Attribute nodes.
  • Introduce an allowed function whitelist for type evaluation (Depends, depends, Field, PrivateAttr, Tag, Parameter).
  • Raise TypeError when a function call in the type string is not in the allowed set, preventing arbitrary function execution.
  • Annotate _safe_eval_type with noqa: C901 to suppress complexity warnings after the added logic.
src/codeweaver/core/di/container.py
Record the ACE vulnerability and mitigation in the Sentinel security journal.
  • Add a new Sentinel journal entry describing the ast.Call-based Arbitrary Code Execution vulnerability in dynamic type evaluation.
  • Document key learning about risks of allowing arbitrary ast.Call in restricted eval environments.
  • Describe prevention guidance emphasizing strict whitelisting of callable nodes in restricted execution contexts.
.jules/sentinel.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown
Contributor

πŸ€– 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.

@github-actions

Copy link
Copy Markdown
Contributor

πŸ€– I'm sorry @bashandbone, but I was unable to process your request. Please see the logs for more details.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The _safe_eval_type method is now complex enough to require # noqa: C901; consider extracting the AST validation logic (e.g., call validation, dunder checks) into smaller helper methods or a dedicated validator class to keep this function simpler and easier to reason about.
  • When rejecting an ast.Call where func_name cannot be determined (non-Name/Attribute), the error message will show func_name as None; consider emitting a clearer, generic error in that case and centralizing the allowed_funcs set (e.g., as a constant) so that future updates to the whitelist are easier and less error-prone.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `_safe_eval_type` method is now complex enough to require `# noqa: C901`; consider extracting the AST validation logic (e.g., call validation, dunder checks) into smaller helper methods or a dedicated validator class to keep this function simpler and easier to reason about.
- When rejecting an `ast.Call` where `func_name` cannot be determined (non-Name/Attribute), the error message will show `func_name` as `None`; consider emitting a clearer, generic error in that case and centralizing the `allowed_funcs` set (e.g., as a constant) so that future updates to the whitelist are easier and less error-prone.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant