Skip to content

mcp: enforce URL policy after variable resolution - #336849

Merged
Dmitriy Vasyura (dmitrivMS) merged 7 commits into
mainfrom
fix/mcp-resolved-url-policy
Sep 20, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 7 commits into
mainfrom
fix/mcp-resolved-url-policy

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

MCP URL rules must be enforced against the fully resolved launch, even if the resulting URL still contains text that resembles a configuration variable. Policy updates must also recheck existing connections and keep blocked servers from exposing cached tools or prompts.

  • Separate preliminary definition checks from authoritative runtime URL allow/deny checks. Defer only URL/command rules whose fields contain syntactically complete configuration variables, using a shared linear-time detector that preserves the configuration resolver's balanced/nested-variable syntax.
  • Recheck the local resolved connection immediately before starting its transport, even when reactive policy enforcement has already cleared the stored connection.
  • Re-evaluate policy changes and stop connections that become blocked. Retain the last resolved identity after disposal while the server definition remains unchanged, so the block and cached-metadata suppression remain effective. Invalidate that identity on the first non-equivalent definition change, so reverting a definition cannot resurrect a stale destination.
  • Allow interactive retries to re-resolve edited or reset inputs while keeping cached metadata hidden until the new resolved identity passes policy. Cancellation and repeat denial retain the block; quiet starts do not bypass it. Access and name restrictions are checked before provider activation or input/command resolution, for both initial starts and retries.
  • Settle pending startup on explicit stop or disposal, allowing a retry after policy restoration without regressing normal transport restarts. Do not start a disposed connection.
  • Cover resolved allow/deny enforcement, permitted variable-based definitions, literal incomplete markers, access/name restrictions, cached metadata, definition changes, and policy revocation during both running and starting states. Include input edit/reset recovery, cancelled and repeatedly denied retries, and repeated-incomplete-marker performance regressions.

Distinguish preliminary definition checks from authoritative resolved launch checks. Validate the local resolved connection before starting its transport, and re-evaluate active connections whenever policy changes.

Add regression coverage for literal variable markers, resolved URL allow/deny rules, permitted unresolved definitions, and policy changes affecting running servers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Preliminary checks still defer literal markers, and reactive denial loses its blocked state after clearing unresolved connections.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Enforces MCP URL policy against resolved runtime connections and reacts to policy changes.

Changes:

  • Separates definition-time and resolved-runtime policy checks.
  • Rechecks resolved connections before transport startup.
  • Adds regression coverage for URL resolution and policy updates.
File Description
allowedMcpServersService.ts Splits preliminary and authoritative checks.
mcpManagement.ts Documents policy-check phases.
mcpServer.ts Adds resolver-aware checks and reactive enforcement.
allowedMcpServersService.test.ts Tests URL policy semantics.
mcpService.test.ts Tests runtime resolution and policy updates.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/vs/workbench/contrib/mcp/common/mcpServer.ts
Comment thread src/vs/platform/mcp/common/allowedMcpServersService.ts Outdated
roblourens
roblourens previously approved these changes Sep 18, 2026
Comment thread src/vs/workbench/contrib/mcp/common/mcpServer.ts
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as draft September 18, 2026 22:27
Keep resolved policy blocks effective after disposing a connection, including suppression of cached tools and prompts. Settle startup waits on explicit stop or disposal so policy restoration permits a retry without regressing normal transport restarts.

Share configuration-variable parsing with preliminary MCP checks so literal incomplete markers do not defer allow/deny enforcement. Add regression coverage for retained blocks, definition changes, preliminary checks, and cancelled startup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Definition updates can revive stale identities, bypass renamed-server policies, and leave cached metadata exposed under access or name restrictions.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment thread src/vs/workbench/contrib/mcp/common/mcpServer.ts
Discard the retained resolved launch identity on the first non-equivalent definition change, including while a connection is live. Returning from definition B to A must not revive A's stale policy result or prevent its variables from being resolved again.

Reuse the existing policy-enforcement observer and preserve the equivalent-definition and resolved-launch checks. Add failing-first regressions for stopped and live connection histories.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/vs/workbench/contrib/mcp/common/mcpServer.ts
Comment thread src/vs/workbench/contrib/mcp/common/mcpServer.ts Outdated
Allow interactive retries to resolve current inputs after a retained policy denial without clearing the block that hides cached metadata. Quiet starts remain blocked, and cancellation or repeated denial keeps the cache hidden until a resolved destination is permitted.

Use one shared linear-time, constant-space balanced-variable detector for preliminary checks and workbench discovery instead of repeatedly parsing unmatched suffixes. Preserve the existing nested-variable syntax and avoid constructing resolver expressions just to detect variables.

Add failing-first edit/reset, cancellation, repeated-denial and 64 KiB discovery regressions, plus differential grammar coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Interactive retries can perform variable-resolution side effects despite access or name-based policy denial.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread src/vs/workbench/contrib/mcp/common/mcpServer.ts Outdated
Reject access and name restrictions before provider activation or variable resolution, including interactive retries that retain a previous URL denial.

Expose the shared preliminary identity check and apply it at rest and before allowing re-resolution. Defer only rules for unresolved URL/command fields; keep the resolved runtime check authoritative. Update test doubles for the internal service contract.

Add failing-first coverage for initial starts and retained-identity retries with input/command variables, plus command-policy deferral controls.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation addresses the prior findings and includes comprehensive focused coverage for policy resolution and connection lifecycle edge cases.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit a24c5eb into main Sep 20, 2026
34 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the fix/mcp-resolved-url-policy branch September 20, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants