Non-ASCII bearer token returns 500 instead of 401

Open Beginner friendly
#229 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
90/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start in kubeflow_mcp/core/auth.py at APIKeyVerifier.verify_token, especially line 64, and inspect the existing authentication tests in auth_test.py. Reproduce verification with a non-ASCII bearer token and confirm the completed change returns HTTP 401 with invalid_token rather than 500, while preserving the wrong ASCII token behavior.

Written by the indexing model from the issue text.

Description

Description

APIKeyVerifier.verify_token compares two str values with hmac.compare_digest (kubeflow_mcp/core/auth.py L64). Python raises TypeError when either string has non-ASCII characters, so the request fails with 500 instead of being rejected.

Steps to Reproduce
  1. kubeflow-mcp serve --transport http --auth-token s3cret
  2. POST an initialize request to /mcp with header Authorization: Bearer café (UTF-8)
  3. See 500
Expected Behavior

401 with invalid_token, same as a wrong ASCII token.

Actual Behavior

500 Internal Server Error. Log ends with:

TypeError: comparing strings with non-ASCII characters is not supported

(from auth.py line 64, in verify_token)

MCP Server Version

0.1.1 (main at 0f90ca6)

Python Version

3.12

Kubernetes Version

n/a

MCP Client

Custom / Other

References

MCP authorization spec, invalid or expired tokens get HTTP 401. Fix is to compare bytes, hmac.compare_digest(token.encode(), self._expected.encode()), plus a test in auth_test.py.

Dominant language
Python
Stars
44
Forks
54
Avg merge
2d 18h
Merged PRs (30d)
31

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from kubeflow/mcp-server

All issues in kubeflow/mcp-server

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.