fix(security): respect global ssrf_protection_enabled flag in gateway test endpoint#5023
Open
bogdanmariusc10 wants to merge 1 commit into
Open
Conversation
…oint The /admin/gateways/test endpoint was unconditionally blocking private IPs regardless of the global ssrf_protection_enabled configuration flag. This created inconsistency with other endpoints and prevented testing internal services even when SSRF protection was intentionally disabled. Changes: - Modified validate_gateway_test_url() to check ssrf_protection_enabled before applying private IP blocking (both direct and DNS-resolved IPs) - Allowlist enforcement remains active regardless of SSRF flag (defense in depth) - Added comprehensive test suite with 18 tests covering all scenarios - Created bug report documenting the issue and fix This ensures consistent behavior across all endpoints while maintaining security through layered protections (SSRF + allowlist enforcement). Fixes: Gateway test endpoint SSRF flag bypass Signed-off-by: Bogdan-Marius-Catanus <bogdan-marius.catanus@ibm.com>
7 tasks
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.
🔗 Related Issue
Closes #5022
📝 Summary
Fixed an inconsistency where the
/admin/gateways/testendpoint was unconditionally blocking private IPs regardless of the globalssrf_protection_enabledconfiguration flag. This prevented testing internal services even when SSRF protection was intentionally disabled for development/testing purposes.The Problem:
ssrf_protection_enabledflagThe Solution:
validate_gateway_test_url()to checksettings.ssrf_protection_enabledbefore applying private IP blockingSecurity Impact:
ssrf_protection_enabled=true(default): Behavior unchanged - private IPs are blockedssrf_protection_enabled=false: Private IPs are allowed (consistent with other endpoints)🏷️ Type of Change
🧪 Verification
make lintmake testmake coverageTests Cover:
✅ Checklist
make black isort pre-commit)📓 Notes
Files Changed:
mcpgateway/common/validators.py- Added conditional SSRF checkstests/security/test_gateway_test_ssrf_protection.py- New comprehensive test suiteDesign Decision:
Implemented Option 1 from the bug analysis: Respect the global SSRF flag for consistency. This was chosen over creating a separate gateway-test-specific flag because:
Integration Tests:
Three tests are marked as
@pytest.mark.integrationbecause they perform real DNS resolution (mocking async executor DNS calls is complex). These tests validate wildcard matching, DNS rebinding protection, and FQDN normalization with actual network calls.Security Considerations:
ssrf_protection_enabled=trueby default)