Skip to content

🛡️ Sentinel: [CRITICAL] Fix Arbitrary Code Execution in dynamic type evaluation#383

Open
bashandbone wants to merge 1 commit into
mainfrom
jules-14565857484303462979-a53d3290
Open

🛡️ Sentinel: [CRITICAL] Fix Arbitrary Code Execution in dynamic type evaluation#383
bashandbone wants to merge 1 commit into
mainfrom
jules-14565857484303462979-a53d3290

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

🚨 Severity: CRITICAL
đź’ˇ Vulnerability: An Arbitrary Code Execution (ACE) vulnerability was found in src/codeweaver/core/di/container.py during dynamic type evaluation. Generic ast.Call nodes were permitted when parsing string-based type annotations using ast.parse and subsequently evaluated via eval().
🎯 Impact: Malicious configuration inputs or strings injected during type resolution could execute arbitrary callable functions in the application's global namespace, severely compromising the system's security.
đź”§ Fix: Implemented an explicit allowlist in the TypeValidator class when traversing ast.Call nodes. Now, only safe, explicitly allowed functions (Depends, Field, PrivateAttr, Tag, Parameter, and cyclopts.Parameter) are permitted to be evaluated. Any unrecognized or malicious function calls will securely raise a TypeError.
âś… Verification: Unit tests covering the dependency injection container and resolution mechanics were executed and passed successfully. No regressions were introduced into the project. The changes were validated against static analysis (Ruff) and security linters.


PR created automatically by Jules for task 14565857484303462979 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 Sentinel notes.

Bug Fixes:

  • Block arbitrary function execution from string-based type annotations by enforcing an allowlist of safe callable names in AST Call nodes during type validation.

Documentation:

  • Document the ACE vulnerability in dynamic type evaluation and its mitigation in the Sentinel security incident log.

…evaluation

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.

Copilot AI review requested due to automatic review settings June 7, 2026 17:39
@sourcery-ai

sourcery-ai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a strict allowlist for function calls in dynamic type annotation evaluation to fix an arbitrary code execution vulnerability, and documents the issue and mitigation in the Sentinel security history.

File-Level Changes

Change Details Files
Harden dynamic type evaluation by whitelisting allowed ast.Call functions to prevent arbitrary code execution.
  • Intercept ast.Call nodes during AST traversal in TypeValidator.generic_visit
  • Allow only specific safe functions referenced by name (Depends, Field, PrivateAttr, Tag, Parameter)
  • Allow cyclopts.Parameter via ast.Attribute when referenced as cyclopts.Parameter
  • Raise TypeError when any other callable or call pattern is encountered in type strings
  • Keep existing checks for forbidden AST nodes and dunder names in place
src/codeweaver/core/di/container.py
Update Sentinel security log with the new ACE vulnerability and mitigation guidance.
  • Add a dated entry describing the ACE vulnerability in dynamic type evaluation
  • Document the learning about risks of generic ast.Call allowance
  • Record prevention guidance recommending strict function whitelisting before eval
.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

github-actions Bot commented Jun 7, 2026

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

github-actions Bot commented Jun 7, 2026

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:

  • Consider extracting the set of allowed function names (and the cyclopts.Parameter rule) into a shared constant or helper so it’s easier to reuse and extend without touching the AST walk logic.
  • The error message Forbidden function call in type string. could include the offending function name (node.func.id/attr) to make debugging misconfigurations or legitimate new use cases easier while still not leaking internal details.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the set of allowed function names (and the cyclopts.Parameter rule) into a shared constant or helper so it’s easier to reuse and extend without touching the AST walk logic.
- The error message `Forbidden function call in type string.` could include the offending function name (`node.func.id`/`attr`) to make debugging misconfigurations or legitimate new use cases easier while still not leaking internal details.

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.

Copilot AI 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.

Pull request overview

Hardens the DI container’s string-based type resolution to prevent arbitrary code execution by restricting which AST function-call nodes are permitted before evaluating type strings.

Changes:

  • Added an explicit allowlist for ast.Call nodes during AST validation of type strings to block unexpected function execution.
  • Documented the dynamic type-evaluation ACE vulnerability and the mitigation in the Sentinel incident log.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/codeweaver/core/di/container.py Adds an allowlist gate for ast.Call nodes during AST validation prior to eval() in _safe_eval_type().
.jules/sentinel.md Records the ACE vulnerability and the high-level prevention strategy for future reference.

đź’ˇ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +133 to +137
# Prevent Arbitrary Code Execution (ACE) vulnerability by strictly whitelisting allowed function calls
if isinstance(node, ast.Call):
is_allowed = False
# Allow standard function names
if (isinstance(node.func, ast.Name) and node.func.id in {
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.

2 participants