[ICACF-15] Restrict gateway test endpoint to approved hosts - SSRF protection#4329
Open
MohanLaksh wants to merge 3 commits intomainfrom
Open
[ICACF-15] Restrict gateway test endpoint to approved hosts - SSRF protection#4329MohanLaksh wants to merge 3 commits intomainfrom
MohanLaksh wants to merge 3 commits intomainfrom
Conversation
Implement SSRF protection for /admin/gateways/test endpoint to prevent open proxy abuse and internal service access. **Changes:** - Add gateway_test_allowed_hosts config for host allowlist enforcement - Add SecurityValidator.validate_host_allowlist() with wildcard support - Fix critical FQDN trailing-dot bypass in _validate_ssrf() normalization - Enforce allowlist in admin_test_gateway() before outbound requests - Add comprehensive security tests (unit + E2E) **Security Impact:** - Fixes CVE-level trailing-dot FQDN bypass vulnerability - Prevents SSRF attacks via explicit allowlist enforcement - Blocks private IPs, loopback, and link-local unconditionally - Returns generic 400 errors (no internal details disclosed) **Tests:** - 8 new unit tests in TestGatewayTestEndpointSecurity - 13 E2E tests for SSRF scenarios - All tests passing (17/17) **Acceptance Criteria Met:** ✅ Server-side allowlist enforced ✅ URL canonicalization/normalization (trailing-dot fixed) ✅ Private IPs blocked unconditionally ✅ Generic 400 error messages ✅ Regression test for trailing-dot bypass ✅ OOB callback blocking test Closes #4314 Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com>
- Add 3 E2E tests to cover gateway test endpoint allowlist enforcement - test_admin_test_gateway_allowlist_blocks_non_allowlisted: Verifies non-allowlisted hosts return 400 error - test_admin_test_gateway_allowlist_allows_allowlisted: Verifies allowlisted hosts work correctly - test_admin_test_gateway_empty_allowlist_uses_ssrf: Verifies empty allowlist falls back to SSRF protection - Tests cover missing lines 13827-13830 in mcpgateway/admin.py for CI/CD coverage requirements - All tests use camelCase field names (statusCode, latencyMs) per BaseModelWithConfigDict serialization Addresses ICACF-15 CI/CD coverage failure Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com>
824cc03 to
c33e428
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements SSRF protection for endpoint to prevent open proxy abuse and internal service access.
JIRA: https://jsw.ibm.com/browse/ICACF-15
GitHub Issue: Closes #4314
Problem
The
/admin/gateways/testendpoint accepted arbitrary user-supplied URLs without proper validation, creating an SSRF vulnerability where attackers could:evil.com.)Changes
1. Configuration (
mcpgateway/config.py)gateway_test_allowed_hostssetting for allowlist enforcement*.example.com) and exact matches2. Validator Enhancement (
mcpgateway/common/validators.py)SecurityValidator.validate_host_allowlist()with wildcard support_validate_ssrf()now uses normalized hostname (strips trailing dots) for IP parsing and DNS resolution3. Endpoint Hardening (
mcpgateway/admin.py)4. Test Coverage
tests/security/test_input_validation.py::TestGatewayTestEndpointSecuritytests/e2e/test_admin_apis.py::TestAdminGatewayAPIsSecurity Impact
Before:
After:
Testing
Test Results:
Manual Verification:
Acceptance Criteria
Configuration
Development (Permissive):
GATEWAY_TEST_ALLOWED_HOSTS=[] # Empty = SSRF blocking only SSRF_PROTECTION_ENABLED=true SSRF_ALLOW_LOCALHOST=true SSRF_ALLOW_PRIVATE_NETWORKS=trueProduction (Strict - Recommended):
Deployment Notes
GATEWAY_TEST_ALLOWED_HOSTSpreserves existing SSRF-only behavior/admin/gateways/testafter deploymentFiles Changed
.env.example- Added GATEWAY_TEST_ALLOWED_HOSTS documentationmcpgateway/admin.py- Allowlist enforcement in admin_test_gateway()mcpgateway/common/validators.py- Added validate_host_allowlist() + fixed trailing-dot bugmcpgateway/config.py- Added gateway_test_allowed_hosts settingtests/security/test_input_validation.py- Added 8 comprehensive unit teststests/e2e/test_admin_apis.py- Added 3 E2E integration tests for coverageChecklist