Skip to content

Add context-aware CORS policy to enhance security#1609

Merged
g2vinay merged 6 commits intomicrosoft:mainfrom
g2vinay:update-cors-policy
Feb 6, 2026
Merged

Add context-aware CORS policy to enhance security#1609
g2vinay merged 6 commits intomicrosoft:mainfrom
g2vinay:update-cors-policy

Conversation

@g2vinay
Copy link
Copy Markdown
Contributor

@g2vinay g2vinay commented Jan 29, 2026

Add context-aware CORS policy for HTTP transport mode

  • Development mode (unauthenticated): Restricts to localhost origins only to prevent CSRF attacks

    • Allows localhost/127.0.0.1/[::1] with any port (supports MCP Inspector, custom ports)
    • Protects against cross-site request forgery when --dangerously-disable-http-incoming-auth is used
    • Prevents malicious websites from accessing developer's Azure credentials via localhost endpoints
  • Production mode (authenticated): Allows all origins safely

    • JWT Bearer authentication validates all requests regardless of origin
    • Required for MCP clients (GitHub Copilot in VS Code/Codespaces) from various origins
    • CORS is a browser mechanism; authenticated API doesn't need origin restrictions

Replaces permissive 'AllowAll' policy with context-aware 'McpCorsPolicy'
Implements ConfigureCors() method shared by both authenticated and unauthenticated HTTP hosts

Copy link
Copy Markdown
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 PR adds a context-aware CORS policy to enhance security for the HTTP transport mode. The policy behaves differently based on the authentication mode: in development mode (unauthenticated), it restricts requests to localhost origins only to prevent CSRF attacks, while in production mode (authenticated), it allows all origins since JWT Bearer authentication validates all requests.

Changes:

  • Introduced a new ConfigureCors() method that configures CORS policy based on the DangerouslyDisableHttpIncomingAuth flag
  • Replaced the permissive "AllowAll" CORS policy with a context-aware "McpCorsPolicy"
  • Updated both CreateHttpHost and CreateIncomingAuthDisabledHttpHost methods to use the new shared CORS configuration

Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Outdated
Copy link
Copy Markdown
Member

@anuchandy anuchandy left a comment

Choose a reason for hiding this comment

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

thanks Vinay, lgtm

@g2vinay g2vinay merged commit 2401099 into microsoft:main Feb 6, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in Azure MCP Server Feb 6, 2026
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants