fix(validators): allow brackets in query parameters while blocking IPv6 addresses#4584
Open
bogdanmariusc10 wants to merge 2 commits intomainfrom
Conversation
Signed-off-by: Bogdan-Marius-Catanus <bogdan-marius.catanus@ibm.com>
…rl-encoded-brackets-in-query-params
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.
🔗 Related Issue
Closes #4580
📝 Summary
Fixed an overly broad IPv6 validation check in
SecurityValidator.validate_url()that incorrectly rejected URLs containing[or]characters anywhere in the URL, including legitimate query parameters.Problem: The validator scanned the entire decoded URL for brackets, causing false positives on common API patterns like:
?filter[name]=value(Laravel/Spatie)?sort[0]=name&sort[1]=created_at(array notation)?include[]=relation(JSON:API)Root Cause: IPv6 addresses only appear in the netloc (hostname) with brackets per RFC 3986, but the check was applied to the entire URL.
Solution:
Security Impact: ✅ No vulnerabilities introduced
[::1]and encoded%5B::1%5D) are still blocked🏷️ Type of Change
🧪 Verification
make lintmake testmake coverageTest Results:
test_brackets_in_query_params_allowedverifies the fix✅ Checklist
make black isort pre-commit)📓 Notes
Example URLs now working:
Security verification performed:
Code changes:
mcpgateway/common/validators.py: Removed broad check, added netloc-specific decoded bracket validationtests/unit/mcpgateway/validation/test_validators_advanced.py: Added test for legitimate bracket usage