Skip to content

🛡️ Sentinel: [CRITICAL] Secure dynamic imports in get_agent_model_capabilities#353

Open
bashandbone wants to merge 1 commit into
mainfrom
sentinel-dynamic-import-capabilities-5255885415642014120
Open

🛡️ Sentinel: [CRITICAL] Secure dynamic imports in get_agent_model_capabilities#353
bashandbone wants to merge 1 commit into
mainfrom
sentinel-dynamic-import-capabilities-5255885415642014120

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 17, 2026

Secures the dynamic module import (importlib.import_module) in src/codeweaver/providers/agent/capabilities.py by validating the provider string against a known whitelist (PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS) before execution, thereby preventing arbitrary code execution. Also adds a journal entry to .jules/sentinel.md.


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

Summary by Sourcery

Validate agent capability provider names against a known whitelist before performing dynamic imports to harden security around model profile loading and document the change in the Sentinel security journal.

Bug Fixes:

  • Prevent potential arbitrary code execution by rejecting untrusted provider strings before using them in importlib-based dynamic imports in agent capability resolution.

Documentation:

  • Add a Sentinel journal entry describing the unvalidated dynamic import vulnerability in agent capabilities and its remediation via whitelist validation.

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

sourcery-ai Bot commented May 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR secures dynamic imports in the agent capabilities provider by enforcing a whitelist of allowed providers before calling importlib.import_module, and documents the security improvement in the Sentinel journal.

Flow diagram for secured dynamic imports in get_agent_model_capabilities

flowchart TD
    A[Start get_agent_model_capabilities] --> B[Iterate model_names]
    B --> C[_parse_model_name]
    C --> D{provider in
PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS?}
    D -- No --> E[Skip provider, continue loop]
    D -- Yes --> F[importlib.import_module
pydantic_ai.profiles.provider]
    F --> G[getattr provider_model_profile]
    G --> H[Build AgentModelCapabilities]
    H --> I[profiles dict updated]
    I --> B
    B --> J[Return profiles]
Loading

File-Level Changes

Change Details Files
Harden dynamic import in _attempt_to_get_profile by validating provider against a whitelist before importing.
  • Add a guard that returns None if provider is not in PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS before attempting dynamic import.
  • Retain existing ImportError suppression and profile getter lookup logic without further behavior change.
src/codeweaver/providers/agent/capabilities.py
Harden dynamic import in get_agent_model_capabilities by skipping unapproved providers before importing.
  • Insert a provider whitelist check at the start of the loop to continue if provider is not in PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS.
  • Leave existing import, attribute lookup, and profile assignment logic intact for valid providers.
src/codeweaver/providers/agent/capabilities.py
Document the removal of an unvalidated dynamic import vulnerability in the Sentinel security journal.
  • Append a dated entry describing the previous unvalidated dynamic import in capabilities.py.
  • Record the security learning and prevention guidance emphasizing strict whitelisting for dynamic imports.
.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 provider whitelist check is duplicated in both _attempt_to_get_profile and get_agent_model_capabilities; consider centralizing the validation (e.g., via a small helper or by always going through _attempt_to_get_profile) to keep the logic consistent and easier to maintain.
  • When a provider is not in PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS the code now silently returns/continues; if unexpected providers indicate a misconfiguration, consider emitting a debug log or warning to make these cases visible during operation.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The provider whitelist check is duplicated in both `_attempt_to_get_profile` and `get_agent_model_capabilities`; consider centralizing the validation (e.g., via a small helper or by always going through `_attempt_to_get_profile`) to keep the logic consistent and easier to maintain.
- When a provider is not in `PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS` the code now silently returns/continues; if unexpected providers indicate a misconfiguration, consider emitting a debug log or warning to make these cases visible during operation.

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

Adds a whitelist validation guard to two dynamic importlib.import_module call sites in capabilities.py so that only provider names present in PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS can be passed to the import. Also records the remediation in the Sentinel security journal.

Changes:

  • Validate provider against PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS in _attempt_to_get_profile before importing.
  • Validate provider in get_agent_model_capabilities's loop and skip non-whitelisted providers.
  • Append a 2026-04-21 journal entry to .jules/sentinel.md documenting the vulnerability and prevention.

Reviewed changes

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

File Description
src/codeweaver/providers/agent/capabilities.py Adds whitelist checks against PYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERS before each dynamic import_module call.
.jules/sentinel.md Adds a journal entry recording the dynamic-import hardening.

💡 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