SessionsPythonPlugin bug fix - #14374
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new allow-list check should be made case-insensitive (and redirect behavior should be addressed/documented) to ensure the security boundary is reliable in typical configurations.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR tightens outbound request allow-listing for the .NET SessionsPythonPlugin (Azure Container Apps dynamic sessions code interpreter) so requests are denied unless the session endpoint host is explicitly permitted, and updates tests/samples accordingly.
Changes:
- Make
SessionsPythonPlugindeny requests unlessSessionsPythonSettings.AllowedDomainscontains the endpoint host (including whenAllowedDomainsisnull/empty). - Update unit tests to assert allow/deny behavior and add coverage for
AllowedDomains == nullandAllowedDomainsempty. - Update integration tests and the demo sample to configure
AllowedDomainsbased on the configured endpoint host.
File summaries
| File | Description |
|---|---|
| dotnet/src/Plugins/Plugins.UnitTests/Core/SessionsPythonPluginTests.cs | Adjusts allow-list tests and adds explicit deny tests for null/empty AllowedDomains. |
| dotnet/src/Plugins/Plugins.Core/CodeInterpreter/SessionsPythonSettings.cs | Updates AllowedDomains XML docs to reflect deny-by-default semantics. |
| dotnet/src/Plugins/Plugins.Core/CodeInterpreter/SessionsPythonPlugin.cs | Enforces deny-by-default allow-list check before sending requests. |
| dotnet/src/IntegrationTests/Plugins/Core/SessionsPythonPluginTests.cs | Configures AllowedDomains in integration test settings. |
| dotnet/samples/Demos/CodeInterpreterPlugin/Program.cs | Configures AllowedDomains in the demo for the configured session endpoint host. |
Review details
Suppressed comments (2)
dotnet/src/Plugins/Plugins.Core/CodeInterpreter/SessionsPythonPlugin.cs:275
- Domain/host comparisons should be case-insensitive. Using the default
ContainsonIEnumerable<string>is case-sensitive, so an entry likeEXAMPLE.COMwill not matchexample.comeven though hostnames are case-insensitive. Align this with the repository’s other allow-list plugins (e.g., HttpPlugin/WebFileDownloadPlugin) by using anOrdinalIgnoreCasecomparer.
if (this._settings.AllowedDomains?.Contains(uri.Host) != true)
dotnet/src/Plugins/Plugins.Core/CodeInterpreter/SessionsPythonPlugin.cs:277
- The exception message is hard to scan and doesn’t clearly state what was denied. Including the blocked host and using
nameofmakes it more actionable and less brittle if types/properties are renamed.
throw new InvalidOperationException("Sending requests to the provided location is not allowed, add allowed domains to the AllowedDomains property on the SessionsPythonSettings.");
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): df581ff6eae8
Model: claude-opus-4.8
Overview
This PR fixes an insecure-default in SessionsPythonPlugin: the allowlist gate
previously evaluated to "allow" when AllowedDomains was null (the common
default), so it enforced nothing. The rewrite at
SessionsPythonPlugin.cs:275 (AllowedDomains?.Contains(uri.Host) != true) is
fail-closed on every branch — null, empty, and non-matching hosts all throw —
and SendAsync is the single choke point for all four HTTP operations, so no
path bypasses it. The change is well covered by new deny tests for the null
and empty cases (against the 169.254.169.254 metadata endpoint) and a rewritten
theory that asserts exact-host semantics. The one notable side effect is that
this is a deliberate, source-compatible but behavior-breaking change for callers
who never set AllowedDomains; that is the intended hardening and is documented
in the updated XML doc, sample, and tests, so it is captured as a release-note
follow-up rather than a code defect.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Motivation and Context
Description
Contribution Checklist