Skip to content

Fix MSRC security vulnerabilities#61

Merged
llxu1 merged 3 commits intomainfrom
fix/msrc-security-vulnerabilities
Apr 16, 2026
Merged

Fix MSRC security vulnerabilities#61
llxu1 merged 3 commits intomainfrom
fix/msrc-security-vulnerabilities

Conversation

@llxu1
Copy link
Copy Markdown
Contributor

@llxu1 llxu1 commented Apr 8, 2026

Fix MSRC security vulnerabilities, internal ticket for more info.

This pull request introduces several security and reliability improvements across the Kubernetes deployment configuration, the .NET backend, and the tool definition provider. The most significant updates include stricter network policies for Kubernetes deployments, secure handling of Redis credentials, validation of container image references, improved HTTP proxy header handling, and enhanced caching for tool definitions.

Kubernetes Deployment and Security Enhancements:

  • Added multiple NetworkPolicy resources to both cloud-deployment-template.yml and local-deployment.yml to restrict ingress traffic:

    • Default deny-all policy for the adapter namespace.
    • Only allow specific services (mcpgateway, toolgateway) to access certain pods and Redis.
    • Allow external traffic only to the mcpgateway service. [1] [2]
  • Introduced a Secret for Redis credentials and updated Redis, mcpgateway, and toolgateway deployments to use this secret for secure password injection and connection string configuration. [1] [2] [3] [4]

Backend Validation and Security:

  • Enforced validation of container image names and versions in both the API contract (AdapterData) and deployment manager using regular expressions to prevent path traversal and invalid image references. [1] [2] [3] [4] [5] [6]

HTTP Proxy Improvements:

  • Improved the HTTP proxy logic to:
    • Only forward a safe subset of response headers to clients.
    • Exclude identity headers from being proxied, ensuring they are only set from the authenticated principal.
    • Correctly detect when to forward the request body. [1] [2] [3]

Tool Definition Provider Caching:

  • Replaced the custom in-memory caching logic in StorageToolDefinitionProvider with IMemoryCache for thread-safe, efficient caching, and updated related tests and dependency injection. [1] [2] [3] [4] [5] [6]

likms
likms previously approved these changes Apr 8, 2026
Copy link
Copy Markdown

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 addresses MSRC-reported security/reliability gaps by tightening Kubernetes network exposure, hardening backend validation and proxying behavior, and improving tool definition caching behavior in the .NET services.

Changes:

  • Added Kubernetes NetworkPolicy resources (cloud + local) to restrict ingress paths to gateway/tool/adapter pods.
  • Hardened .NET services: validated container image references, tightened HTTP proxy header/body handling, and replaced custom tool-definition caching with IMemoryCache.
  • Updated local Kubernetes manifests to inject Redis credentials via a Secret and to require Redis AUTH.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
dotnet/Microsoft.McpGateway.Tools/test/StorageToolDefinitionProviderTests.cs Updates tests for new IMemoryCache dependency in the provider.
dotnet/Microsoft.McpGateway.Tools/src/Services/StorageToolDefinitionProvider.cs Switches to IMemoryCache + locking for tool resource caching.
dotnet/Microsoft.McpGateway.Tools/src/Program.cs Registers AddMemoryCache() for the tools service DI container.
dotnet/Microsoft.McpGateway.Service/src/HttpProxy.cs Adjusts request body forwarding logic and restricts proxied response headers.
dotnet/Microsoft.McpGateway.Management/src/Deployment/KubernetesAdapterDeploymentManager.cs Adds regex-based validation for image name/tag before creating/updating K8s workloads.
dotnet/Microsoft.McpGateway.Management/src/Contracts/AdapterData.cs Adds regex validation attributes for image name/tag in the API contract.
deployment/k8s/local-deployment.yml Adds Redis Secret, enables Redis AUTH, and introduces local NetworkPolicy rules.
deployment/k8s/cloud-deployment-template.yml Adds namespace default-deny ingress + explicit allow policies for gateway/adapter access.
Comments suppressed due to low confidence (1)

dotnet/Microsoft.McpGateway.Tools/test/StorageToolDefinitionProviderTests.cs:556

  • A new required constructor dependency (IMemoryCache) was introduced, but there’s no constructor test asserting it throws when cache is null (similar to the other null-guard tests). Add a test to cover the ArgumentNullException path for the cache parameter.
        [TestMethod]
        public void Constructor_ShouldThrowArgumentNullException_WhenToolResourceStoreIsNull()
        {
            // Act
            var act = () => new StorageToolDefinitionProvider(
                null!,
                _permissionProviderMock.Object,
                _httpContextAccessorMock.Object,
                new MemoryCache(new MemoryCacheOptions()),
                _loggerMock.Object);

            // Assert
            act.Should().Throw<ArgumentNullException>();
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deployment/k8s/local-deployment.yml Outdated
Comment thread deployment/k8s/local-deployment.yml Outdated
Comment thread deployment/k8s/local-deployment.yml
Comment thread deployment/k8s/cloud-deployment-template.yml Outdated
Comment thread dotnet/Microsoft.McpGateway.Management/src/Contracts/AdapterData.cs
Comment thread dotnet/Microsoft.McpGateway.Tools/src/Services/StorageToolDefinitionProvider.cs Outdated
Comment thread dotnet/Microsoft.McpGateway.Service/src/HttpProxy.cs
adnapibar
adnapibar previously approved these changes Apr 13, 2026
Copy link
Copy Markdown

@adnapibar adnapibar left a comment

Choose a reason for hiding this comment

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

Approved

- Harden ForwardedIdentityHeaders and SimplePermissionProvider authorization
- Add security headers to Kubernetes deployment templates
- Add input validation in HttpProxy
- Add security configuration in Tools Program.cs
- Update README with security guidance
@llxu1 llxu1 merged commit 4b77fff into main Apr 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants