Summary
Mend SAST scan (April 8, 2026) identified several code quality improvements for the Rust MCP runtime (tools_rust/mcp_runtime/src/lib.rs).
Scan Details:
- Date: 2026-04-08 06:52am
- Total Rust Findings: 25
- File:
tools_rust/mcp_runtime/src/lib.rs (13,319 lines)
Findings Breakdown
🔵 URL Validation (19 findings)
Recommendation: Add validation layer for backend HTTP requests
Affected Functions:
send_to_backend_url() (line 4422)
send_sampling_to_backend() (line 7891)
send_prompts_get_to_backend() (line 7978)
- 16+ additional backend dispatch functions
Root Cause: Backend URL construction from configuration without validation
Recommended Implementation:
- Add URL validation module with hostname resolution
- Implement network range checking
- Add configuration for allowed destinations
- Apply validation to all backend HTTP calls
🔵 Query Parameter Binding (2 findings)
Status: FALSE POSITIVE (verified)
Analysis: All database queries use parameterized statements with proper parameter binding. No changes needed.
Example (line 4841):
client.query(
"SELECT t.name FROM tools t WHERE sta.server_id = $1",
&[&server_id], // ✅ Parameterized - SAFE
)
🔵 Request Size Limits (1 finding)
Recommendation: Add request body size constraints
Current State:
- No size limits on incoming payloads
- No nesting depth limits for JSON parsing
Recommended Mitigation:
- Limit payload size (e.g., 10MB max)
- Set max JSON nesting depth
- Use size-limited readers for parsing
- Add timeout on parsing operations
Implementation Plan
Phase 1: URL Validation
Create validation module: tools_rust/mcp_runtime/src/url_validator.rs
Features:
- Length validation (max 2048 chars)
- Scheme allowlist (http, https, ws, wss)
- Pattern validation
- Hostname resolution with network checking
- Configurable allowed/blocked ranges
Dependencies:
[dependencies]
url = "2.5" # URL parsing
ipnetwork = "0.20" # CIDR validation
trust-dns-resolver = "0.24" # DNS resolution
regex = "1.10" # Pattern matching
Configuration (Environment Variables):
SSRF_PROTECTION_ENABLED=true # Enable validation (default: true)
SSRF_BLOCKED_NETWORKS= # CIDR ranges to block (comma-separated)
SSRF_BLOCKED_HOSTS= # Hostnames to block (comma-separated)
SSRF_ALLOW_LOCALHOST=false # Allow localhost access (default: false)
SSRF_ALLOW_PRIVATE_NETWORKS=false # Allow RFC1918 networks (default: false)
SSRF_ALLOWED_NETWORKS= # Allowlist specific CIDR ranges
SSRF_DNS_FAIL_CLOSED=true # Fail closed on DNS errors (default: true)
Default Blocked Networks:
169.254.169.254/32 - AWS/GCP/Azure instance metadata
169.254.169.123/32 - AWS NTP service
fd00::1/128 - IPv6 cloud metadata
169.254.0.0/16 - Link-local IPv4 range
fe80::/10 - IPv6 link-local
Default Blocked Hosts:
metadata.google.internal - GCP metadata hostname
metadata.internal - Generic cloud metadata
Phase 2: Request Size Constraints
Implementation:
// Add Axum middleware
.layer(RequestBodyLimitLayer::new(10 * 1024 * 1024)) // 10MB max
// Size-limited parsing
let parsed: Value = serde_json::from_reader(
std::io::Cursor::new(body).take(10 * 1024 * 1024)
)?;
Phase 3: Testing & Validation
Create: tools_rust/mcp_runtime/tests/security_tests.rs
Test Coverage:
- ✅ URL validation with various inputs
- ✅ Hostname resolution behavior
- ✅ Configuration modes (strict vs permissive)
- ✅ Integration scenarios
Verification Checklist
Implementation Status
Branch: fix/rust-security-vulnerabilities-ssrf-remediation
PR: #4111
Status: ✅ Complete - Ready for Review
Documentation
File: tools_rust/mcp_runtime/README.md
Added configuration section:
## Configuration
### URL Validation
The Rust MCP runtime includes URL validation for backend requests.
**Environment Variables:**
- `SSRF_PROTECTION_ENABLED=true` - Enable validation (default: true)
- `SSRF_ALLOW_LOCALHOST=false` - Allow localhost (default: false)
- See README for full list
**Example - Development Mode:**
```bash
SSRF_ALLOW_LOCALHOST=true ./mcp-runtime
Example - Production Mode:
SSRF_PROTECTION_ENABLED=true \
SSRF_ALLOW_LOCALHOST=false \
./mcp-runtime
---
**Labels:** `enhancement`, `rust`, `code-quality`, `mend-scan`
---
**Related:** PR #4111
**Estimated Effort:** 3-4 weeks → Complete
Summary
Mend SAST scan (April 8, 2026) identified several code quality improvements for the Rust MCP runtime (
tools_rust/mcp_runtime/src/lib.rs).Scan Details:
tools_rust/mcp_runtime/src/lib.rs(13,319 lines)Findings Breakdown
🔵 URL Validation (19 findings)
Recommendation: Add validation layer for backend HTTP requests
Affected Functions:
send_to_backend_url()(line 4422)send_sampling_to_backend()(line 7891)send_prompts_get_to_backend()(line 7978)Root Cause: Backend URL construction from configuration without validation
Recommended Implementation:
🔵 Query Parameter Binding (2 findings)
Status: FALSE POSITIVE (verified)
Analysis: All database queries use parameterized statements with proper parameter binding. No changes needed.
Example (line 4841):
🔵 Request Size Limits (1 finding)
Recommendation: Add request body size constraints
Current State:
Recommended Mitigation:
Implementation Plan
Phase 1: URL Validation
Create validation module:
tools_rust/mcp_runtime/src/url_validator.rsFeatures:
Dependencies:
Configuration (Environment Variables):
Default Blocked Networks:
169.254.169.254/32- AWS/GCP/Azure instance metadata169.254.169.123/32- AWS NTP servicefd00::1/128- IPv6 cloud metadata169.254.0.0/16- Link-local IPv4 rangefe80::/10- IPv6 link-localDefault Blocked Hosts:
metadata.google.internal- GCP metadata hostnamemetadata.internal- Generic cloud metadataPhase 2: Request Size Constraints
Implementation:
Phase 3: Testing & Validation
Create:
tools_rust/mcp_runtime/tests/security_tests.rsTest Coverage:
Verification Checklist
Implementation Status
Branch:
fix/rust-security-vulnerabilities-ssrf-remediationPR: #4111
Status: ✅ Complete - Ready for Review
Documentation
File:
tools_rust/mcp_runtime/README.mdAdded configuration section:
Example - Production Mode: