Skip to content

🛡️ Sentinel: [CRITICAL] Fix arbitrary code execution in AST evaluation#370

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

🛡️ Sentinel: [CRITICAL] Fix arbitrary code execution in AST evaluation#370
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-ast-call-ace-8641445407182060014

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 30, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: Unrestricted generic ast.Call nodes were allowed during safe evaluation of type definitions using eval(), which permitted execution of any callable within the module's global namespace, breaking out of the intended sandbox.
🎯 Impact: This allowed arbitrary code execution (ACE) if an attacker could control the type string passed to _safe_eval_type.
🔧 Fix: Added strict whitelist validation for ast.Call nodes inside TypeValidator.generic_visit restricting it to explicitly safe functions (Depends, depends, Field, PrivateAttr, Tag, Parameter) supporting both direct names and cyclopts. attributes. Added # noqa: C901 to ignore Ruff cyclomatic complexity failures due to the addition of if logic. Added the vulnerability finding and learning to .jules/sentinel.md.
✅ Verification: Ran mise //:check to ensure no linting/formatting errors. Ran targeted unit testing uv run pytest tests/unit/core/ --no-cov to ensure no functionality regressions were introduced.


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

Summary by Sourcery

Harden safe type evaluation to prevent arbitrary code execution and document the security finding in Sentinel.

Bug Fixes:

  • Block arbitrary code execution by restricting evaluated AST call nodes in _safe_eval_type to a small set of explicitly allowed dependency/field helpers.

Enhancements:

  • Mark _safe_eval_type with a linter exclusion for cyclomatic complexity to accommodate the additional security checks.

Documentation:

  • Add a Sentinel entry documenting the AST-based arbitrary code execution vulnerability, its cause, and recommended prevention via whitelisting allowed function calls.

* Fixed arbitrary code execution (ACE) vulnerability in `src/codeweaver/core/di/container.py` during AST validation for type evaluation using `eval()`.
* Whitelisted allowed `ast.Call` nodes to specifically permitted safe functions (`Depends`, `depends`, `Field`, `PrivateAttr`, `Tag`, `Parameter`).
* Added `noqa: C901` to safely bypass cyclomatic complexity limits.
* Documented critical finding in `.jules/sentinel.md` journal.

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 30, 2026 17:42
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 30, 2026

Reviewer's Guide

Tightens the AST-based type evaluation sandbox by whitelisting allowed function calls in ast.Call nodes within _safe_eval_type and documents the new ACE vulnerability and mitigation in the Sentinel security log.

File-Level Changes

Change Details Files
Harden AST validation in _safe_eval_type to prevent arbitrary function calls during eval-based type evaluation.
  • Marked _safe_eval_type with noqa: C901 to bypass cyclomatic complexity checks after adding new validation logic.
  • Extended TypeValidator.generic_visit to inspect ast.Call nodes and reject any call whose target is not a whitelisted safe function name.
  • Supported both bare function names and attribute-style calls (e.g., cyclopts.Depends) by validating ast.Name.id and ast.Attribute.attr against the same whitelist, raising TypeError for any non-conforming call or unexpected call shape before evaluation.
src/codeweaver/core/di/container.py
Record the newly discovered AST-based ACE vulnerability and remediation details in the Sentinel security documentation.
  • Documented the ACE via unrestricted ast.Call during type evaluation, including file context and risk.
  • Captured the key security learning around generic ast.Call usage breaking sandboxed eval environments.
  • Added prevention guidance to strictly whitelist function calls when validating ASTs for safe evaluation scenarios.
.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:

  • The allowed function names for ast.Call are duplicated for both ast.Name and ast.Attribute; consider extracting this set to a shared constant and/or helper to keep the logic maintainable as the whitelist evolves.
  • For ast.Attribute calls you currently only check the attribute name (node.func.attr), which would also allow some_obj.Depends; if the intent is to only allow cyclopts.Depends-style calls, add validation of node.func.value to restrict which objects/modules can expose those attributes.
  • Instead of suppressing C901 on _safe_eval_type, consider moving the new ast.Call validation into a small dedicated helper or visitor method to keep cyclomatic complexity and readability under control.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The allowed function names for `ast.Call` are duplicated for both `ast.Name` and `ast.Attribute`; consider extracting this set to a shared constant and/or helper to keep the logic maintainable as the whitelist evolves.
- For `ast.Attribute` calls you currently only check the attribute name (`node.func.attr`), which would also allow `some_obj.Depends`; if the intent is to only allow `cyclopts.Depends`-style calls, add validation of `node.func.value` to restrict which objects/modules can expose those attributes.
- Instead of suppressing C901 on `_safe_eval_type`, consider moving the new `ast.Call` validation into a small dedicated helper or visitor method to keep cyclomatic complexity and readability under control.

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 dependency type-string evaluation by restricting callable AST nodes before eval() is used, and records the vulnerability in Sentinel documentation.

Changes:

  • Adds call-name validation in Container._safe_eval_type.
  • Documents the arbitrary-code-execution finding in .jules/sentinel.md.
  • Suppresses Ruff complexity for the expanded evaluator.

Reviewed changes

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

File Description
src/codeweaver/core/di/container.py Adds whitelist validation for ast.Call nodes during safe type evaluation.
.jules/sentinel.md Adds a Sentinel entry describing the AST evaluation ACE vulnerability and prevention.

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

Comment on lines +151 to +160
elif isinstance(node.func, ast.Attribute):
if node.func.attr not in {
"Depends",
"depends",
"Field",
"PrivateAttr",
"Tag",
"Parameter",
}:
raise TypeError(f"Forbidden function call: {node.func.attr}")
raise TypeError(f"Forbidden dunder attribute: {node.attr}")

# Security: Restrict ast.Call nodes to prevent Arbitrary Code Execution (ACE)
if isinstance(node, ast.Call):
Comment on lines +151 to +160
elif isinstance(node.func, ast.Attribute):
if node.func.attr not in {
"Depends",
"depends",
"Field",
"PrivateAttr",
"Tag",
"Parameter",
}:
raise TypeError(f"Forbidden function call: {node.func.attr}")
raise TypeError(f"Forbidden dunder attribute: {node.attr}")

# Security: Restrict ast.Call nodes to prevent Arbitrary Code Execution (ACE)
if isinstance(node, ast.Call):
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