microsoft/mcp/harden-tool-url-inputs

Claude Code and agent skill by microsoft/mcp

Trust tier 4
  • vendor
Source check pending

Checking that the SKILL.md file is still in the repository.

Audit and harden one or more tool directories against URL hijacking and SSRF by tracing MCP inputs to URL construction and using IAzureService or injectable IEndpointValidator with cloud-specific Azure endpoint allow-lists. Use when: validate URL inputs, secure endpoints, prevent URL hijacking, SSRF hardening, audit tool directories, apply EndpointValidator.

Install

npx vskill@latest install microsoft/mcp/harden-tool-url-inputs

SKILL.md

The same SKILL.md was published earlier as microsoft/mcp/harden-tool-url-inputs.

Harden Tool URL Inputs

Audit and update every requested directory so MCP-influenced values cannot hijack a URL, URI, host, or client endpoint. Use IAzureService forwarding methods or the host's injectable IEndpointValidator at the final URL boundary, with the configured Azure cloud and the narrowest appropriate allow-list.

This is a scoped implementation skill, not a report-only audit. Make the fixes and add tests unless the user explicitly requests analysis only.

Required Input and Scope

  1. Accept one or many repository-relative directories under tools/.
  2. Resolve every path and confirm it is inside the repository's tools/ directory. Reject files or directories outside that boundary.
  3. If no directory is supplied, ask the user for at least one. If a supplied path does not exist or its intended scope is ambiguous, ask before editing.
  4. Treat each supplied directory as an exhaustive scope. Do not stop after finding the first vulnerable URL flow.
  5. Do not modify other tool directories. Shared changes to core/Microsoft.Mcp.Core/src/Helpers/EndpointValidator.AllowLists.cs and its tests are allowed when a scoped tool needs a new Azure service allow-list.
  6. Preserve unrelated worktree changes. Read the repository and nearest scoped instructions before editing.

Pattern Sources

Before implementing, inspect the current versions of:

  • core/Microsoft.Mcp.Core/src/Helpers/IEndpointValidator.cs
  • core/Microsoft.Mcp.Core/src/Helpers/EndpointValidator.cs
  • core/Microsoft.Mcp.Core/src/Helpers/EndpointValidator.AllowLists.cs
  • core/Azure.Mcp.Core/src/Services/Azure/IAzureService.cs
  • core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Core.Tests/Helpers/EndpointValidatorTests.cs
  • core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Helpers/AzureServiceTestHelpers.cs

When wiring dependencies or testing namespace overrides, also inspect SsrfProtectionPolicy.cs, EndpointValidationServiceCollectionExtensions.cs, ICommandContextAccessor.cs, and EndpointValidationRegistrationTests.cs in their corresponding core projects. Read the executing-command-context guidance in CONTRIBUTING.md and transport boundaries in docs/design/HttpClientFactory.md.

Use current implementations as the API and pattern source of truth. Do not copy obsolete static policy-dependent calls or explicit namespace arguments from historical examples. Representative current cases include:

  • ACR: validate the exact Uri passed to the data-plane SDK through a small static helper that receives IAzureService for focused tests.
  • App Configuration and Communication: validate a discovered or user-supplied endpoint immediately before client construction.
  • Compute: distinguish URL input from a resource ID and validate only the URL branch with the storage-blob allow-list.
  • Cosmos and Foundry Extensions: try a small explicit set of acceptable Azure service types, then fail closed; an early any-cloud option check never replaces the authoritative configured-cloud service check.
  • Load Testing: use ValidatePublicTargetUrl for a deliberately arbitrary public target.
  • Service Bus: reject URL-component characters in a bare host and still validate the completed endpoint.

Threat Model

  • Treat every MCP option as untrusted, including values named account, cluster, endpoint, host, namespace, registry, resource, server, url, uri, or workspace.
  • Track derived values. Validation is required when an untrusted name is interpolated into a host even if the option itself is not described as a URL.
  • Treat endpoint-like Azure resource metadata as a trust boundary before using it in a data-plane client. Resource Graph or ARM returning a string does not make that string safe for network use.
  • Validate the completed absolute endpoint, not only the resource name or one string fragment.
  • Treat path, query, and "relative" inputs as potential authority changes. APIs such as new Uri(baseUri, value) accept absolute and network-path references that can replace the base host.
  • URL parsing, escaping, encoding, or rejecting a few special characters is not a replacement for host allow-list validation.
  • EndpointValidator authorizes the scheme and host; it does not make untrusted path or query syntax safe. Build those components with typed SDK APIs or correctly escaped path/query helpers.
  • A successful Uri parse proves syntax, not authorization to contact the host.

Workflow

1. Establish the baseline
  1. Inspect git status and the scoped diff before editing.
  2. Read command registration, options, commands, services, helpers, and tests in every supplied directory.
  3. Identify the top-level MCP tool namespace from registration code. Do not infer it only from the directory name.
  4. Check whether each Azure service endpoint already has a key in EndpointValidator.AllowLists.cs.
  5. Identify the existing IAzureService dependency or, where unavailable, the IEndpointValidator dependency and its DI registration. Do not create a separate validator or policy at the tool boundary.
2. Inventory input-to-URL flows

Search the full scope for both sources and sinks. Useful candidates include:

  • [Option] properties and legacy option definitions
  • http://, https://, Endpoint, Host, Url, and Uri
  • new Uri, target-typed new(...), UriBuilder, and connection strings
  • base-plus-relative combinations such as new Uri(baseUri, value) and HttpClient methods called with string request targets
  • Azure SDK or other client constructors that accept a URI, endpoint, namespace, or host
  • HttpClient.BaseAddress, HttpRequestMessage, RequestUri, GetAsync, PostAsync, PutAsync, and SendAsync
  • interpolated REST paths, request URLs, callback URLs, webhook URLs, and upload/download sources
  • helpers that append paths, ports, queries, or fragments

Search results are only candidates. Trace each MCP option through command, service, and helper calls to its final network sink. Also inspect URL construction that uses endpoint-like values returned from ARM, Resource Graph, configuration, files, or prior service calls.

For every candidate, determine one disposition:

URL flowRequired disposition
Azure data-plane endpointIAzureService.ValidateAzureServiceEndpoint or injected IEndpointValidator.ValidateAzureServiceEndpoint
Known non-Azure service with an exact host setStatic EndpointValidator.ValidateExternalUrl
Deliberately arbitrary public HTTP(S) targetIAzureService.ValidatePublicTargetUrl or injected IEndpointValidator.ValidatePublicTargetUrl
Input-derived path or query on an allowed baseReject absolute/network-path replacement, construct or escape the component with an appropriate API, then validate the final absolute URL
Typed Azure control-plane operationUse the typed ARM SDK and ResourceIdentifier through shared ARM client creation; its pipeline validates each final request URI rather than requiring a redundant tool-level check
Compile-time fixed URL with no influenced componentDocument as not input-derived; no runtime validation needed

Do not classify an Azure endpoint as an arbitrary public target merely to avoid defining a service allow-list.

Shared ARM clients created through AzureHelper.CreateArmClientAsync call IAzureService.ConfigureArmClientOptions and retain a configured-cloud arm validation policy before transport. It validates every attempt, including retries, paging, and long-running-operation polling, even without an active command context. Do not assume raw ARM HTTP calls or independently constructed SDK clients have this policy. Trace those paths and validate their final URLs against the configured-cloud arm allow-list before sending, including subsequent request URLs.

3. Implement Azure service validation

For an Azure data-plane endpoint, validate the exact absolute URL before the SDK client, request, or other network-capable object can use it:

csharp
Uri uri = new Uri($"https://{resource}.{serviceDomain}");
AzureService.ValidateAzureServiceEndpoint(
endpoint: uri.AbsoluteUri,
serviceType: "service-key");
var client = new ServiceClient(uri, credential, options);

Apply these rules:

  1. Use named arguments to distinguish the endpoint and service allow-list key. Direct IEndpointValidator calls also supply the Azure cloud.
  2. serviceType is the exact key for the endpoint domain in EndpointValidator.AllowLists.cs.
  3. The executing tool namespace is resolved by the validator through ICommandContextAccessor.CurrentContext.ToolNamespaceName, not supplied by the caller. It is the original registered IAreaSetup.Name, even in consolidated or single-tool mode, and is independent of serviceType; for example, compute may consume storage-blob, and foundryextensions may consume foundry or azure-openai. Never infer it from request arguments, an endpoint, a routing name, or telemetry.
  4. IAzureService.ValidateAzureServiceEndpoint always uses its own CloudConfiguration.ArmEnvironment; callers supply only the endpoint and service key. Direct IEndpointValidator calls must pass the configured cloud at an authoritative service boundary. Do not hardcode public cloud when configured cloud context is available.
  5. If option validation cannot access the configured cloud, it may accept endpoints valid in any explicitly supported cloud for early feedback, but the service must validate again against the configured cloud before use.
  6. When several Azure service endpoint families are intentionally accepted, try only a small explicit service-type set in the configured cloud. Catch only the expected validation exceptions and fail closed when none match.
  7. Validate every endpoint-producing branch. A safe default branch does not protect an alternate branch.
  8. Additional service-specific checks may restrict paths, ports, resource-name structure, or bare-host syntax, but they do not replace validation of the completed endpoint. Document why each bespoke check is necessary as described below.
  9. When combining a trusted base URI with user input, do not pass the input directly to base-plus-relative URI resolution. Prove it is relative, reject //, \\, schemes, rooted paths, fragments, and other authority-changing forms as appropriate, then add escaped path segments or query parameters with a purpose-built API.
  10. Validate the final absolute URL after combining its components so alternate-authority behavior cannot bypass the allow-list.
  11. Constructing a Uri solely to canonicalize and then validating its AbsoluteUri is acceptable. Do not perform credential acquisition, client creation, DNS access, or a network call before validation.
  12. Do not configure or bypass SSRF protections, open command scopes, or assign namespaces from tool code. Command loaders establish the scope around the complete awaited command execution, including option validation. Discovery, learn/sampling callbacks, direct CLI execution, and external proxy forwarding do not populate the accessor; a real command selected through sampling receives its own scope.
Dependency and policy ownership

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 2 Oct 2026.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
3,724
Repository forks
630
7-day trend score
46

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill CERTIFIED badge
[![vskill CERTIFIED](https://verified-skill.com/api/v1/skills/microsoft/mcp/harden-tool-url-inputs/badge)](https://verified-skill.com/skills/microsoft/mcp/harden-tool-url-inputs)

Something wrong with this skill or its page? Tell us.