Skip to content

fix: Disable CA Cert validation on authless MCPs#5075

Open
gcgoncalves wants to merge 1 commit into
mainfrom
5070-ca-cert-validation
Open

fix: Disable CA Cert validation on authless MCPs#5075
gcgoncalves wants to merge 1 commit into
mainfrom
5070-ca-cert-validation

Conversation

@gcgoncalves
Copy link
Copy Markdown
Collaborator

🐛 Bug-fix PR

📌 Summary

Closes #5070

🔁 Reproduction Steps

UI Reproduction Steps

  1. Access the admin UI
  2. Navigate to the Gateways tab
  3. Fill the MCP form with a valid MCP server, with authentication type=none and no CA certificate
  4. Submit the form
  5. Verify the form validation errors

API Reproduction Steps

  1. Generate a valid JWT token for authentication:
    export TOKEN=$(python -m mcpgateway.utils.create_jwt_token --username admin@example.com --exp 10080 --secret your-secret-key)

  2. Attempt to register an authless MCP server via POST /gateways:

curl -X POST http://localhost:4444/gateways \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer $TOKEN" \
 -d '{
   "name": "test-authless-server",
   "url": "http://localhost:9000",
   "auth_type": "none"
 }'
  1. Observe the validation error response:
    {"detail":[{"type":"value_error","loc":["body","auth_value"],"msg":"Value error, Invalid 'auth_type'. Must be one of: basic, bearer, oauth, authheaders, or query_param.","input":null,"ctx":{"error":{}}}]}%

  2. Confirm the same error occurs with explicit null:

# With explicit null
curl -X POST http://localhost:8000/gateways \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "name": "test-authless-server",
    "url": "http://localhost:9000",
    "auth_type": "none",
    "auth_query_param_key": null
  }'
  1. Observe the validation error response:

{"detail":[{"type":"value_error","loc":["body","auth_value"],"msg":"Value error, Invalid 'auth_type'. Must be one of: basic, bearer, oauth, authheaders, or query_param.","input":null,"ctx":{"error":{}}}]}%

  1. Confirm the validation error occurs with an empty string:
# With empty string
curl -X POST http://localhost:8000/gateways \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "name": "test-authless-server",
    "url": "http://localhost:9000",
    "auth_type": "none",
    "auth_query_param_key": ""
  }'
  1. Observe the validation error response:
{"detail":[{"type":"string_pattern_mismatch","loc":["body","auth_query_param_key"],"msg":"String should match pattern '^[a-zA-Z_][a-zA-Z0-9_\\-]*$'","input":"","ctx":{"pattern":"^[a-zA-Z_][a-zA-Z0-9_\\-]*$"}},{"type":"value_error","loc":["body","auth_value"],"msg":"Value error, Invalid 'auth_type'. Must be one of: basic, bearer, oauth, authheaders, or query_param.","input":null,"ctx":{"error":{}}}]}%

🐞 Root Cause

There is a mismatch between the UI form and backend validation: the admin UI's auth_type dropdown sent an empty string value="" for the "None" option, but the Pydantic schemas expected either a valid auth type string or Python None. The schemas lacked a validator to normalize the string "none" to Python None, causing validation failures when users selected "No authentication" in the UI.

💡 Fix Description

This PR solves the issue by adding a Pydantic @field_validator to both GatewayCreate and GatewayUpdate schemas that normalizes empty strings and the literal string "none" (case-insensitive) to Python None, ensuring the backend correctly interprets the UI's "No authentication" selection. The fix includes comprehensive test coverage for all auth_type variations (valid types, None, empty string, "none" string) across both create and update operations.

🧪 Verification

Check Command Status
Lint suite make lint
Unit tests make test
Coverage ≥ 80 % make coverage
Manual regression no longer fails steps / screenshots

📐 MCP Compliance (if relevant)

  • Matches current MCP spec
  • No breaking change to MCP clients

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • No secrets/credentials committed

@gcgoncalves gcgoncalves force-pushed the 5070-ca-cert-validation branch 4 times, most recently from 0ab4563 to 0e70bbf Compare June 5, 2026 14:11
Signed-off-by: Gabriel Costa <gabrielcg@proton.me>
@gcgoncalves gcgoncalves force-pushed the 5070-ca-cert-validation branch from 0e70bbf to 2fb22f8 Compare June 5, 2026 14:46
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.

[BUG]: CA Cert validation is flagging non-existent CA certs.

1 participant