fix: add Unicode normalization and homoglyph detection to tool name validation#3141
Open
manjunathbhaskar wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
manjunathbhaskar
marked this pull request as draft
July 21, 2026 10:13
manjunathbhaskar
force-pushed
the
fix/unicode-homoglyph-tool-name-validation
branch
from
July 21, 2026 10:29
b034a16 to
7bdaa23
Compare
Closes a spoofing attack vector where tool names containing visually identical but distinct Unicode characters (Cyrillic А vs Latin A, fullwidth a vs ASCII a, Greek Α vs Latin A) or invisible bidirectional formatting characters (U+202E RTL override, U+200F RTL mark, etc.) could bypass the existing ASCII-only regex check undetected. Changes to src/mcp/shared/tool_name_validation.py: - Add BIDIRECTIONAL_FORMATTING_CHARS set (12 Unicode control chars) - Reject names containing any bidi formatting char with a descriptive warning - Reject names whose NFKC-normalized form differs from the original, catching fullwidth look-alikes (a→a) before the regex runs Changes to tests/shared/test_tool_name_validation.py: - Add TestUnicodeHomoglyphDetection (9 tests): Cyrillic А/О/Е/Р, fullwidth, Greek Α, RTL/LTR override characters - Add TestUnicodeNormalizationBypass (2 tests): NFD decomposed forms, NFKC fullwidth normalization - Add TestUnicodeBoundaryConditions (1 test): zero-width space - Add TestValidAsciiStillWorks (5 tests): confirm existing valid names still pass after new checks
manjunathbhaskar
force-pushed
the
fix/unicode-homoglyph-tool-name-validation
branch
from
July 21, 2026 10:44
9825cfa to
ddeb025
Compare
manjunathbhaskar
marked this pull request as ready for review
July 21, 2026 16:43
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.
Problem
Tool name validation accepts Unicode homoglyphs — characters that look visually identical to ASCII but are encoded differently. This allows tool names that appear legitimate but are actually distinct identifiers, enabling spoofing attacks in agentic workflows.
Attack Scenario
verify_սser(ArmenianսU+057D instead of Latins)verify_userin UI, logs, and agent contextverify_usertoolverify_սserexecutes insteadAffected Character Classes (pre-fix)
Solution
Added two complementary checks to
validate_tool_name():unicodedata.normalize('NFKC', name) != name, the name contains confusable or fullwidth characters and is rejectedBoth checks run before the existing regex, so malicious names fail fast with a descriptive error message.
Changes
src/mcp/shared/tool_name_validation.pyimport unicodedataBIDIRECTIONAL_FORMATTING_CHARSconstant (12 Unicode control characters)validate_tool_name()validate_tool_name()tests/shared/test_tool_name_validation.pyTestUnicodeHomoglyphDetection— 9 tests covering Cyrillic, Greek, Fullwidth, RTL/LTR overridesTestUnicodeNormalizationBypass— 2 tests for decomposed and NFKC normalization formsTestUnicodeBoundaryConditions— 1 test for zero-width charactersTestValidAsciiStillWorks— 5 regression tests confirming valid ASCII names are unaffectedTotal: 16 new test cases, 0 breaking changes
Verification
All existing tests continue to pass. New tests confirm:
verify_user,tool-name,DATA_EXPORT_v2.1) are unaffectedReferences