Skip to content

🛡️ Sentinel: [CRITICAL] Fix arbitrary code execution in type evaluation via restricted AST call whitelist#362

Open
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-ace-in-eval-289020645167947115
Open

🛡️ Sentinel: [CRITICAL] Fix arbitrary code execution in type evaluation via restricted AST call whitelist#362
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-ace-in-eval-289020645167947115

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 25, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: The _safe_eval_type function in src/codeweaver/core/di/container.py contained an Arbitrary Code Execution (ACE) vulnerability. The custom TypeValidator loosely permitted any ast.Call nodes when checking type strings before evaluating them with eval(). This allowed the execution of any callable mapped in the globalns parameter.
🎯 Impact: An attacker could potentially inject malicious functions or payloads into type string configurations, resulting in arbitrary code execution within the execution environment.
🔧 Fix: Implemented strict whitelisting for ast.Call nodes inside TypeValidator.generic_visit(). It now only accepts function calls to Depends, depends, Field, PrivateAttr, and Tag. An inline security comment was added addressing the ACE concern, as required.
✅ Verification: Tested against a local script injecting a malicious function (execute_evil) into a type string annotation. It now securely fails with a TypeError instead of allowing the execution. Also ran the test suite locally ensuring no regression.


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

Summary by Sourcery

Harden type string evaluation by restricting allowed AST function calls and document the associated ACE vulnerability and mitigation in the Sentinel security log.

Bug Fixes:

  • Prevent arbitrary code execution in type evaluation by rejecting non-whitelisted ast.Call nodes in the TypeValidator used by _safe_eval_type.

Documentation:

  • Add a Sentinel security log entry describing the ACE vulnerability in eval-based type resolution and the whitelisting-based fix.

…on via restricted AST call whitelist

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 May 25, 2026 17:52
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 25, 2026

Reviewer's Guide

Tightens the AST-based validation in _safe_eval_type to prevent arbitrary code execution by strictly whitelisting allowed function calls in type strings and records the incident and mitigation in the Sentinel security log.

File-Level Changes

Change Details Files
Harden AST validation in _safe_eval_type to block arbitrary function calls during type string evaluation.
  • Extend TypeValidator.generic_visit to detect ast.Call nodes whose callee is not a simple ast.Name or whose name is not in an explicit whitelist
  • Introduce a whitelist of allowed callable names in type strings: Depends, depends, Field, PrivateAttr, Tag
  • Raise TypeError with a clear message when a forbidden function call is encountered during type validation
  • Add an inline security comment documenting the ACE risk and rationale for the strict call whitelist
src/codeweaver/core/di/container.py
Document the newly discovered ACE vulnerability and its remediation in the Sentinel security notes.
  • Append a new dated section describing the ACE vulnerability in _safe_eval_type to the Sentinel markdown log
  • Capture the root cause (overly permissive ast.Call allowance), lesson learned, and prevention guidance emphasizing strict whitelisting of allowed calls 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
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.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

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 (Depends, depends, Field, PrivateAttr, Tag) into a clearly named module-level constant so the whitelist is easier to audit, reuse, and extend without touching the validator logic.
  • The new ast.Call check only permits bare Name calls and will reject patterns like module.Depends(...) or aliased imports; if that is intentional, it might be worth making this explicit in the inline comment or adjusting the logic to handle safe ast.Attribute access patterns where appropriate.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the allowed function names (`Depends`, `depends`, `Field`, `PrivateAttr`, `Tag`) into a clearly named module-level constant so the whitelist is easier to audit, reuse, and extend without touching the validator logic.
- The new `ast.Call` check only permits bare `Name` calls and will reject patterns like `module.Depends(...)` or aliased imports; if that is intentional, it might be worth making this explicit in the inline comment or adjusting the logic to handle safe `ast.Attribute` access patterns where appropriate.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 dependency injection type-string resolution by tightening AST validation before eval() is used in Container._safe_eval_type, preventing arbitrary code execution through untrusted function calls embedded in type strings.

Changes:

  • Restrict ast.Call nodes during type-string AST validation to a small whitelist of permitted call names (Depends, depends, Field, PrivateAttr, Tag).
  • Add an inline security comment in the validator documenting the ACE risk and the mitigation.
  • Record the vulnerability and mitigation in the Sentinel security log.

Reviewed changes

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

File Description
src/codeweaver/core/di/container.py Adds strict ast.Call whitelisting in TypeValidator to prevent eval-based ACE via callable invocation.
.jules/sentinel.md Documents the ACE finding and the whitelisting mitigation in the Sentinel log.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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