🛡️ Sentinel: [CRITICAL] Secure dynamic imports in get_agent_model_capabilities#353
🛡️ Sentinel: [CRITICAL] Secure dynamic imports in get_agent_model_capabilities#353bashandbone wants to merge 1 commit into
Conversation
Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis 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_capabilitiesflowchart 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]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
🤖 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. |
|
🤖 I'm sorry @bashandbone, but I was unable to process your request. Please see the logs for more details. |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The provider whitelist check is duplicated in both
_attempt_to_get_profileandget_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_PROVIDERSthe 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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
provideragainstPYDANTIC_AI_MODEL_CAPABILITIES_PROVIDERSin_attempt_to_get_profilebefore importing. - Validate
provideringet_agent_model_capabilities's loop and skip non-whitelisted providers. - Append a 2026-04-21 journal entry to
.jules/sentinel.mddocumenting 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.
Secures the dynamic module import (
importlib.import_module) insrc/codeweaver/providers/agent/capabilities.pyby validating theproviderstring 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:
Documentation: