Skip to content

Update endpoint validator to handle IPv6#2066

Open
xiangyan99 wants to merge 7 commits intomainfrom
EndpointValidatorIPv6
Open

Update endpoint validator to handle IPv6#2066
xiangyan99 wants to merge 7 commits intomainfrom
EndpointValidatorIPv6

Conversation

@xiangyan99
Copy link
Member

What does this PR do?

[Provide a clear, concise description of the changes]

Update endpoint validator to handle IPv6

[Any additional context, screenshots, or information that helps reviewers]

GitHub issue number?

[Link to the GitHub issue this PR addresses]

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes using script at eng/scripts/Process-PackageReadMe.ps1. See Package README
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

Copy link
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

Strengthens EndpointValidator SSRF protections by expanding detection of IPv6-based and wildcard-DNS based bypass techniques, and adds/updates unit tests plus a changelog entry to document the security hardening.

Changes:

  • Block common wildcard DNS services (nip.io, sslip.io, xip.io) as reserved hostnames in ValidatePublicTargetUrl.
  • Harden IsPrivateOrReservedIP to normalize IPv4-mapped IPv6 and detect additional IPv6 non-routable/reserved cases (multicast, discard prefix, documentation prefix, 6to4, Teredo, IPv4-compatible IPv6).
  • Add unit tests covering IPv4-mapped IPv6, IPv6 reserved ranges, 6to4/Teredo embedding cases, and wildcard DNS blocking; add changelog entry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
servers/Azure.Mcp.Server/changelog-entries/1773685856512.yaml Documents SSRF hardening for IPv4-mapped IPv6 bypass handling.
core/Microsoft.Mcp.Core/src/Helpers/EndpointValidator.cs Expands reserved hostname blocking and strengthens IP range classification for SSRF prevention.
core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Core.UnitTests/Helpers/EndpointValidatorTests.cs Adds/updates tests for new SSRF bypass protections and broader reserved IP detection.

jongio and others added 4 commits March 16, 2026 13:30
Add NAT64 (64:ff9b::/96) and NAT64v2 (64:ff9b:1::/48) checks with
RFC 6052 Section 2.2 correct byte extraction for embedded IPv4.

Fix trailing-dot FQDN bypass where 'nip.io.' evaded the reserved
hostname blocklist by normalizing with TrimEnd('.').

Add missing IPv6 ranges: BMWG benchmarking (2001:2::/48),
site-local (fec0::/10).

Add missing IPv4 ranges: TEST-NET-1/2/3, benchmarking (198.18/15),
IANA special (192.0.0/24), 6to4 relay (192.88.99/24).

157 EndpointValidator tests, all passing.

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

Findings from MQ triple-model analysis (Opus + Codex + test coverage):

- CWE-209: Sanitize SecurityException messages to not leak resolved
  private IP addresses or DNS resolver internals to callers
- CWE-697: Remove duplicate BMWG check that over-blocked /32 instead
  of correct /48 (RFC 5180); the second correct /48 check was dead code
- CWE-770: Move reservedHosts array to static readonly field to avoid
  per-call allocation on validation hot path
- Add 48 new test cases: public IPv4/IPv6 baselines, IPv4-mapped and
  IPv4-compatible public address tests, link-local IPv6, IPv4 range
  boundary tests, multicast/reserved IPv4, trailing-dot for all reserved
  hosts, IPv6 transition mechanism URLs via ValidatePublicTargetUrl,
  subdomain-of-reserved-host blocking, error message sanitization
  verification
- Fix misleading Teredo test comment (described wrong bytes/IP)

205 tests passing (up from 157).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Finding: MQ-HACK-002 (Codex adversarial pass)
Severity: Medium
CWE: CWE-184 (Incomplete List of Disallowed Inputs), CWE-703
Persona: Bug Bounty Hunter
Fix class: AUTO-FIX

ISATAP (RFC 5214) embeds IPv4 in the last 4 bytes of an IPv6 address
with the interface ID marker 0:5efe (or 02:00:5efe with u/l bit set).
Link-local ISATAP (fe80::5efe:...) was already blocked by the fe80::/10
check, but global-prefix ISATAP addresses (e.g., 2001:db8::5efe:a9fe:a9fe)
could bypass all checks and tunnel to IMDS.

Also adds fail-closed guard for empty DNS AddressList — if GetHostEntry
returns zero addresses, the hostname is now rejected instead of silently
passing validation.

211 tests passing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
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

This pull request strengthens EndpointValidator SSRF defenses (notably around IPv6 transition mechanisms, wildcard DNS services, and error-message sanitization) and expands unit test coverage to validate the new protection behavior.

Changes:

  • Harden ValidatePublicTargetUrl by enforcing HTTP/HTTPS schemes, blocking wildcard DNS/reserved hostnames (with trailing-dot normalization), failing closed on empty DNS results, and sanitizing exception messages.
  • Expand IsPrivateOrReservedIP to detect additional private/reserved IPv4/IPv6 ranges and IPv6 transition-mechanism embeddings (IPv4-mapped, 6to4, Teredo, NAT64, SIIT/translated, ISATAP, etc.).
  • Add extensive unit tests covering the new reserved-range logic and SSRF bypass vectors; add changelog entries for the fix.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
servers/Azure.Mcp.Server/changelog-entries/ssrf-ipv6-hardening.yaml Adds release note describing the expanded SSRF hardening.
servers/Azure.Mcp.Server/changelog-entries/1773685856512.yaml Adds an additional (potentially duplicate) release note about IPv4-mapped IPv6 SSRF bypass.
core/Microsoft.Mcp.Core/src/Helpers/EndpointValidator.cs Implements SSRF hardening: scheme enforcement, reserved host blocklist + trailing-dot normalization, sanitized DNS errors, expanded reserved/private IP detection for IPv6 transition mechanisms.
core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Core.UnitTests/Helpers/EndpointValidatorTests.cs Adds many tests covering IPv6 transition mechanisms, additional reserved ranges, wildcard DNS blocking, trailing-dot normalization, and sanitized errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants