Skip to content

fix(security): block URL-encoded injection patterns in SecurityValidator.validate_url()#4335

Merged
jonpspri merged 2 commits intomainfrom
4318-icacf-19-securitypen-testingtighten-url-and-path-input-validation-on-the-gateway-test-endpoint
Apr 26, 2026
Merged

fix(security): block URL-encoded injection patterns in SecurityValidator.validate_url()#4335
jonpspri merged 2 commits intomainfrom
4318-icacf-19-securitypen-testingtighten-url-and-path-input-validation-on-the-gateway-test-endpoint

Conversation

@bogdanmariusc10
Copy link
Copy Markdown
Collaborator

🔗 Related Issue

Closes #4318
Jira Issue: https://jsw.ibm.com/browse/ICACF-19


📝 Summary

This PR fixes a security vulnerability in SecurityValidator.validate_url() where URL-encoded injection patterns could bypass security checks. The gateway test endpoint and 6 other endpoints were vulnerable to CRLF injection, XSS, and JavaScript protocol injection via percent-encoding.

Root Cause: Security pattern checks operated on the original URL string before decoding, allowing attackers to hide malicious patterns using URL encoding (e.g., %0d%0a for CRLF, %3Cscript%3E for XSS).

Fix: Added urllib.parse.unquote() to decode URLs before all pattern-based security checks while preserving structural validation on the original URL.

Impact: Protects all 7 endpoints using SecurityValidator.validate_url() across the codebase from injection attacks.


🏷️ Type of Change

  • Bug fix
  • Feature / Enhancement
  • Documentation
  • Refactor
  • Chore (deps, CI, tooling)
  • Other (describe below)

🧪 Verification

Check Command Status
Lint suite make lint
Unit tests make test
Coverage ≥ 80% make coverage

Security Testing: All 27 injection test vectors now blocked:

  • ✅ CRLF injection (literal \r\n and encoded %0d%0a)
  • ✅ XSS attacks (<script> and %3Cscript%3E)
  • ✅ JavaScript protocol (javascript: and javascript%3A)
  • ✅ Credential injection (user:pass and user%3Apass)
  • ✅ Space injection and IPv6 bypasses
  • ✅ All valid URLs still accepted

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • Tests added/updated for changes
  • Documentation updated (if applicable)
  • No secrets or credentials committed

📓 Notes

Security Impact: This vulnerability allowed attackers to bypass URL validation using percent-encoding. For example:

  • http://example.com/%0d%0aInjected-Header:Exploit (CRLF injection)
  • http://example.com/%3Cscript%3Ealert(1)%3C/script%3E (XSS)

Protected Endpoints:

  1. Gateway test endpoint (/admin/gateways/test)
  2. Tool URL validation
  3. LLM provider service URLs
  4. OpenAPI spec URLs
  5. LLM chat router URLs
  6. Plugin framework URLs
  7. LLM proxy service URLs

Implementation Details:

  • Decode once at start of validate_url() using urllib.parse.unquote()
  • Use decoded_value for all pattern-based security checks
  • Keep structural checks (scheme, IPv6, length) on original value
  • Return original URL (not decoded) for actual use

Backward Compatibility: ✅ No breaking changes - all valid URLs continue to work as before.

@bogdanmariusc10 bogdanmariusc10 added security Improves security SHOULD P2: Important but not vital; high-value items that are not crucial for the immediate release labels Apr 20, 2026
@bogdanmariusc10 bogdanmariusc10 added api REST API Related item MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe release-fix Critical bugfix required for the release pentesting and removed SHOULD P2: Important but not vital; high-value items that are not crucial for the immediate release labels Apr 20, 2026
@jonpspri jonpspri force-pushed the 4318-icacf-19-securitypen-testingtighten-url-and-path-input-validation-on-the-gateway-test-endpoint branch from 77e5b5b to 6c454e2 Compare April 26, 2026 07:12
Bogdan-Marius-Catanus and others added 2 commits April 26, 2026 08:28
…te_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>
…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>
@jonpspri jonpspri force-pushed the 4318-icacf-19-securitypen-testingtighten-url-and-path-input-validation-on-the-gateway-test-endpoint branch from 6c454e2 to 9d3d113 Compare April 26, 2026 07:28
@jonpspri jonpspri merged commit feda268 into main Apr 26, 2026
30 checks passed
@jonpspri jonpspri deleted the 4318-icacf-19-securitypen-testingtighten-url-and-path-input-validation-on-the-gateway-test-endpoint branch April 26, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api REST API Related item MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe pentesting release-fix Critical bugfix required for the release security Improves security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICACF-19] [Security][Pen Testing]Tighten URL and path input validation on the gateway test endpoint

2 participants