Commit feda268
fix(security): block URL-encoded injection patterns in SecurityValidator.validate_url() (#4335)
* fix: block URL-encoded injection patterns in SecurityValidator.validate_url()
Decode URLs before security checks to prevent bypasses via URL encoding.
Addresses CRLF injection, XSS, JavaScript protocol, and other attack vectors
that could be hidden using percent-encoding (%0d%0a, %3Cscript%3E, etc.).
Changes:
- Add urllib.parse.unquote() at start of validate_url()
- Use decoded_value for all pattern-based security checks:
- CRLF injection detection
- XSS/HTML tag detection
- JavaScript protocol detection
- Space validation
- Dangerous URL pattern matching
Structural checks (scheme, IPv6, protocol-relative, length) remain on
original value as they validate URL structure, not content.
All 27 injection test vectors now blocked. Fixes ICACF-19.
Signed-off-by: Jonathan Springer <jps@s390x.com>
* fix(security): harden validators against double-encoding and encoded injection bypass
Extend percent-encoding defense to all SecurityValidator entry points
(validate_no_xss, validate_uri, sanitize_display_text, validate_sql_parameter)
and mirror hardening in the plugin framework standalone validator. Block
double-encoded payloads, IIS %uXXXX escapes, JS \uXXXX/\xXX escapes, and
invalid UTF-8 overlong sequences. Add _parse_ip_network_cached for CIDR
parsing performance. Comprehensive regression tests for both core and plugin
validators.
Closes #4318
Signed-off-by: Jonathan Springer <jps@s390x.com>
---------
Signed-off-by: Jonathan Springer <jps@s390x.com>
Co-authored-by: Bogdan-Marius-Catanus <bogdan-marius.catanus@ibm.com>
Co-authored-by: Jonathan Springer <jps@s390x.com>1 parent 7cc16a4 commit feda268
3 files changed
Lines changed: 823 additions & 46 deletions
File tree
- mcpgateway/common
- tests/unit/mcpgateway/validation
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
4844 | 4844 | | |
4845 | 4845 | | |
4846 | 4846 | | |
4847 | | - | |
| 4847 | + | |
4848 | 4848 | | |
4849 | 4849 | | |
4850 | 4850 | | |
| |||
0 commit comments