-
Notifications
You must be signed in to change notification settings - Fork 418
Mask auth for gateways APIs reponse #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Keval Mahajan <[email protected]>
Signed-off-by: Keval Mahajan <[email protected]>
Signed-off-by: Keval Mahajan <[email protected]>
Signed-off-by: Keval Mahajan <[email protected]>
Signed-off-by: Keval Mahajan <[email protected]>
Signed-off-by: Keval Mahajan <[email protected]>
Passed:
|
|
This PR implements a security enhancement to mask sensitive authentication fields when returning gateway information through the API. Here's what's being changed: Key Changes:
Purpose:This PR enhances security by ensuring that sensitive authentication credentials (passwords, tokens, API keys) are never exposed through the API responses. When clients request gateway information, they'll see:
This is a common security best practice to prevent accidental exposure of credentials through API responses, logs, or debugging output. |
1. Test Bearer Auth - Check if authValue is Masked# First, create a gateway with bearer auth
curl -X POST http://127.0.0.1:4444/gateways \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "bearer-test",
"url": "http://127.0.0.1:8103/sse",
"transport": "SSE",
"auth_type": "bearer",
"auth_token": "secret-token-12345"
}' | jq
# Get the gateway ID from response, then fetch it
curl -X GET http://127.0.0.1:4444/gateways/{gateway-id} \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" | jq
# BUG: Check if authValue is masked (it should be "*****" per issue #601)
# Expected: "authValue": "*****"
# Actual: "authValue": "ey123123..." (base64 encoded token - NOT MASKED!)2. Test Basic Auth - All Fields Masked# Create gateway with basic auth
curl -X POST http://127.0.0.1:4444/gateways \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "basic-test",
"url": "http://127.0.0.1:8103/sse",
"transport": "SSE",
"auth_type": "basic",
"auth_username": "admin",
"auth_password": "secretpass"
}' | jq
# Fetch and check masking
curl -X GET http://127.0.0.1:4444/gateways/{gateway-id} \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" | jq
# Check these fields:
# - "authPassword": "*****" ✓ (should be masked)
# - "authValue": "ey123123..." ✗ (should be "*****" but isn't)3. Test Custom Headers Auth# Create gateway with custom headers
curl -X POST http://127.0.0.1:4444/gateways \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "headers-test",
"url": "http://127.0.0.1:8103/sse",
"transport": "SSE",
"auth_type": "authheaders",
"auth_header_key": "X-API-Key",
"auth_header_value": "my-secret-api-key"
}' | jq
# Fetch and verify masking
curl -X GET http://127.0.0.1:4444/gateways/{gateway-id} \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" | jq
# Check:
# - "authHeaderValue": "*****" ✓ (should be masked)
# - "authValue": "eyJ..." ✗ (should be "*****" but isn't)4. Test List Endpoints - Multiple Gateways# List all gateways (regular endpoint)
curl -X GET http://127.0.0.1:4444/gateways \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" | jq
# List all gateways (admin endpoint)
curl -X GET http://127.0.0.1:4444/admin/gateways \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" | jq
# Both should mask sensitive fields for ALL gateways in the list5. Test Edit Flow - Masked Values Problem# Step 1: Get a gateway with auth
curl -X GET http://127.0.0.1:4444/admin/gateways/{gateway-id} \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" | jq
# You'll see: "authPassword": "*****"
# Step 2: Try to update the gateway without changing password
curl -X PUT http://127.0.0.1:4444/gateways/{gateway-id} \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "basic-test-updated",
"auth_type": "basic",
"auth_username": "admin",
"auth_password": "*****"
}' | jq
# BUG: This might literally set the password to "*****" instead of keeping the existing one!6. Test Validation Error with Masked Bearer Token# This tests if re-validation works with masked values
# Create a test script to check if the masked response can be re-validated:
echo '{
"name": "test",
"url": "http://test.com",
"auth_type": "bearer",
"auth_value": "eyJBdXRob3JpemF0aW9uIjogIkJlYXJlciBhYmMxMjMifQ==",
"auth_token": "*****"
}' | curl -X POST http://127.0.0.1:4444/test-validation \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d @-
# This would need a test endpoint to verify, but the validation will likely fail7. Quick Test Script - All Auth Types#!/bin/bash
# Test all auth types and check if authValue is properly masked
echo "Testing Bearer Auth..."
BEARER_ID=$(curl -s -X POST http://127.0.0.1:4444/gateways \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "bearer-test-'$(date +%s)'",
"url": "http://127.0.0.1:8103/sse",
"transport": "SSE",
"auth_type": "bearer",
"auth_token": "secret-token"
}' | jq -r '.id')
echo "Fetching Bearer Gateway..."
curl -s -X GET "http://127.0.0.1:4444/gateways/$BEARER_ID" \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" | jq '{
authType: .authType,
authValue_is_masked: (.authValue == "*****"),
authToken_is_masked: (.authToken == "*****"),
authValue: .authValue
}'
echo -e "\nTesting Basic Auth..."
BASIC_ID=$(curl -s -X POST http://127.0.0.1:4444/gateways \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "basic-test-'$(date +%s)'",
"url": "http://127.0.0.1:8103/sse",
"transport": "SSE",
"auth_type": "basic",
"auth_username": "admin",
"auth_password": "secret"
}' | jq -r '.id')
echo "Fetching Basic Gateway..."
curl -s -X GET "http://127.0.0.1:4444/gateways/$BASIC_ID" \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" | jq '{
authType: .authType,
authValue_is_masked: (.authValue == "*****"),
authPassword_is_masked: (.authPassword == "*****"),
authValue: .authValue
}'Expected vs Actual ResultsRun these tests and look for:
The main bug is that PR Checklist: Done ✅ / Missing ❌✅ Done (Partially):
❌ Missing - Critical:
❌ Potential Code Issues:
❌ Not Tested:
Summary:All POST and PUT endpoints still expose sensitive data, and the |
Signed-off-by: Keval Mahajan <[email protected]>
Signed-off-by: Keval Mahajan <[email protected]>
Signed-off-by: Keval Mahajan <[email protected]>
Signed-off-by: Keval Mahajan <[email protected]>
|
* masked auth values in gateways apis Signed-off-by: Keval Mahajan <[email protected]> * linting Signed-off-by: Keval Mahajan <[email protected]> * masked admin-gateways api auth values Signed-off-by: Keval Mahajan <[email protected]> * mask first and convert to the alias values Signed-off-by: Keval Mahajan <[email protected]> * linting Signed-off-by: Keval Mahajan <[email protected]> * flake8 issues resolved Signed-off-by: Keval Mahajan <[email protected]> * improved masking auth values Signed-off-by: Keval Mahajan <[email protected]> * updated test cases Signed-off-by: Keval Mahajan <[email protected]> * updated doctest for masked Signed-off-by: Keval Mahajan <[email protected]> * resolved flake8 issues Signed-off-by: Keval Mahajan <[email protected]> --------- Signed-off-by: Keval Mahajan <[email protected]>
* masked auth values in gateways apis Signed-off-by: Keval Mahajan <[email protected]> * linting Signed-off-by: Keval Mahajan <[email protected]> * masked admin-gateways api auth values Signed-off-by: Keval Mahajan <[email protected]> * mask first and convert to the alias values Signed-off-by: Keval Mahajan <[email protected]> * linting Signed-off-by: Keval Mahajan <[email protected]> * flake8 issues resolved Signed-off-by: Keval Mahajan <[email protected]> * improved masking auth values Signed-off-by: Keval Mahajan <[email protected]> * updated test cases Signed-off-by: Keval Mahajan <[email protected]> * updated doctest for masked Signed-off-by: Keval Mahajan <[email protected]> * resolved flake8 issues Signed-off-by: Keval Mahajan <[email protected]> --------- Signed-off-by: Keval Mahajan <[email protected]>
* masked auth values in gateways apis Signed-off-by: Keval Mahajan <[email protected]> * linting Signed-off-by: Keval Mahajan <[email protected]> * masked admin-gateways api auth values Signed-off-by: Keval Mahajan <[email protected]> * mask first and convert to the alias values Signed-off-by: Keval Mahajan <[email protected]> * linting Signed-off-by: Keval Mahajan <[email protected]> * flake8 issues resolved Signed-off-by: Keval Mahajan <[email protected]> * improved masking auth values Signed-off-by: Keval Mahajan <[email protected]> * updated test cases Signed-off-by: Keval Mahajan <[email protected]> * updated doctest for masked Signed-off-by: Keval Mahajan <[email protected]> * resolved flake8 issues Signed-off-by: Keval Mahajan <[email protected]> --------- Signed-off-by: Keval Mahajan <[email protected]>
🐛 Bug-fix PR
📌 Summary
Closes #601
Masks all the authentication values in the response of gateways APIs
💡 Fix Description
🧪 Verification
make lintmake testmake coverage📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)