Skip to content

🛡️ Sentinel: [CRITICAL] Prevent arbitrary code execution in AST type validation#378

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

🛡️ Sentinel: [CRITICAL] Prevent arbitrary code execution in AST type validation#378
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-ast-call-ace-9016044890702513400

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🚨 Severity: CRITICAL
đź’ˇ Vulnerability: Found an Arbitrary Code Execution (ACE) vulnerability during dynamic type evaluation via safe eval(). The AST validation didn't restrict ast.Call nodes, allowing any arbitrary callable in the module's global namespace to be executed during type string resolution.
🎯 Impact: A malicious type annotation string could invoke arbitrary functions that are available in the module's globalns, resulting in arbitrary code execution.
đź”§ Fix: Implemented a strict whitelist for ast.Call nodes. Now, only specific required functions like Depends, depends, Field, PrivateAttr, Tag, and Parameter can be called within type annotations during validation.
âś… Verification: Ensure tests pass locally using uv run pytest tests/unit/core/di.


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

Summary by Sourcery

Harden AST-based type string evaluation to prevent arbitrary code execution from malicious type annotations.

Bug Fixes:

  • Block arbitrary function calls in type-annotation ASTs by whitelisting only approved call targets such as Depends/depends, Field, PrivateAttr, Tag, and Parameter.

Documentation:

  • Document the newly discovered AST-based arbitrary code execution vulnerability and its mitigation in the Sentinel security log.

…validation

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 17:26
@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 3, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR hardens the safe type-string evaluation in the DI container by whitelisting allowable function calls in the AST (preventing arbitrary code execution), and documents the new security finding in the Sentinel security log.

File-Level Changes

Change Details Files
Harden AST-based type string evaluation to prevent arbitrary function calls and arbitrary code execution.
  • Extend the AST validator in _safe_eval_type to detect ast.Call nodes and extract the underlying function name from ast.Name or ast.Attribute nodes.
  • Introduce a strict allowlist of permitted callables in type strings (Depends, depends, Field, PrivateAttr, Tag, Parameter) and raise TypeError for any other function calls.
  • Annotate _safe_eval_type with noqa: C901 to silence complexity warnings introduced by the added validation logic.
src/codeweaver/core/di/container.py
Document the newly discovered AST arbitrary code execution vulnerability and its remediation in the Sentinel security history.
  • Add a new dated entry describing the ACE vulnerability in type evaluation, the associated risks, and the prevention strategy based on strict whitelisting of ast.Call nodes.
.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 3, 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 3, 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 allowed function names for ast.Call into a shared constant (e.g., _ALLOWED_TYPE_CALLS) so it’s easier to reuse, audit, and extend in one place.
  • When func_name cannot be resolved (e.g., more complex call expressions), the error message will show Forbidden function call in type string: None; you might want to special‑case this to give a clearer message about unsupported call shapes rather than printing None.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the allowed function names for `ast.Call` into a shared constant (e.g., `_ALLOWED_TYPE_CALLS`) so it’s easier to reuse, audit, and extend in one place.
- When `func_name` cannot be resolved (e.g., more complex call expressions), the error message will show `Forbidden function call in type string: None`; you might want to special‑case this to give a clearer message about unsupported call shapes rather than printing `None`.

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

This PR hardens CodeWeaver’s DI container’s AST-based “safe eval” path for resolving string type annotations, addressing an arbitrary code execution risk caused by allowing unrestricted ast.Call evaluation during type string resolution.

Changes:

  • Adds an ast.Call whitelist to the _safe_eval_type() AST validator to block arbitrary function calls during type evaluation.
  • Updates the Sentinel security log with details of the vulnerability, impact, and mitigation.

Reviewed changes

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

File Description
src/codeweaver/core/di/container.py Restricts which call expressions are allowed in type-annotation AST validation to reduce ACE risk during string type resolution.
.jules/sentinel.md Documents the newly identified AST-call-based ACE vector and the mitigation approach.

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

Comment on lines +141 to +157
if isinstance(node, ast.Call):
func_name = None
if isinstance(node.func, ast.Name):
func_name = node.func.id
elif isinstance(node.func, ast.Attribute):
func_name = node.func.attr

if func_name not in {
"Depends",
"depends",
"Field",
"PrivateAttr",
"Tag",
"Parameter",
}:
raise TypeError(f"Forbidden function call in type string: {func_name}")

Comment on lines +148 to +152
if func_name not in {
"Depends",
"depends",
"Field",
"PrivateAttr",
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