fix(validators): don't flag quoted URL schemes (://) as polyglot attacks - #6418
Open
YMahut wants to merge 1 commit into
Open
fix(validators): don't flag quoted URL schemes (://) as polyglot attacks#6418YMahut wants to merge 1 commit into
YMahut wants to merge 1 commit into
Conversation
The polyglot detection pattern ['"].*//['"] in SecurityValidator matched any quoted string containing "//", including legitimate URLs. Tool descriptions with connection-string examples (e.g. "postgresql://", "mysql://") were rejected during registration with "contains potentially dangerous character sequences". Add a negative lookbehind (?<!:) so a URL scheme separator (://) is not treated as a polyglot. A bare "//" before a closing quote (JS line-comment polyglot) is still detected. Adds regression tests. Signed-off-by: YouriM <youri.mahut@bjtmail.com>
YMahut
requested review from
Lang-Akshay,
brian-hussey,
crivetimihai,
ja8zyjits and
msureshkumar88
as code owners
August 26, 2026 11:04
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.
📌 Summary
SecurityValidator.sanitize_display_textrejects any display text in which a quoted string contains//(via the_POLYGLOT_PATTERNSentry["'].*//["']). Legitimate URLs get caught: a tool whose description enumerates connection-string examples such as"postgresql://"/"mysql://"fails validation with<field> contains potentially dangerous character sequences, which blocks tool registration.🔁 Reproduction Steps
Closes #6419
Observed in practice with a Superset "create connection" tool whose description lists the supported DB URL schemes.
🐞 Root Cause
The
//of a URL scheme separator (://) is treated as a JS line-comment polyglot by["'].*//["']inmcpgateway/common/validators.py.💡 Fix Description
Add a negative lookbehind so a scheme
://is not matched, while a bare//before a closing quote (a genuine JS line-comment polyglot) is still caught:The HTML/JS patterns and the other polyglot patterns are unchanged, so real XSS/polyglot payloads remain blocked.
📏 Reviewability
triage🧪 Verification
Two regression tests added in
tests/unit/mcpgateway/validation/test_validators.py:test_sanitize_display_text_url_scheme_allowed— quoted URL schemes are accepted;test_sanitize_display_text_polyglot_double_slash_still_blocked— a bare//before a quote is still rejected.make lintmake testmake coveragerecheck"postgresql://"/"mysql://"no longer flagged and"a//"still flagged; existing HTML/JS/polyglot checks unaffected — relying on project CI for the full suite📐 MCP Compliance (if relevant)
N/A — input-validation refinement, no change to the MCP protocol or client behavior.
✅ Checklist
make black isort pre-commit) — not run locally; change is a 1-line regex + tests (formatting-neutral)