Commit fd84dcf
committed
fix(rust): Address all reviewer concerns on PR #4111
This commit fixes 5 issues identified in code review:
**Issue #1 - Default config inconsistency (CRITICAL):**
- Changed SSRF_ALLOW_LOCALHOST default from false to true
- Fixes immediate failure on fresh installs where backend_rpc_url defaults to 127.0.0.1
- Updated README.md to reflect new defaults and clarify production vs development modes
- Location: tools_rust/mcp_runtime/src/config.rs:208
**Issue #2 - SSRF bypass in two functions (CRITICAL):**
- Added URL validation to backend_authenticate_url() before HTTP call
- Added URL validation to backend_tools_call_resolve_url() before HTTP call
- Both functions now use url_validator.validate_url() with SSRF protection
- Locations: tools_rust/mcp_runtime/src/lib.rs:2564, 8158
**Issue #3 - Malformed CIDR fails open (HIGH):**
- Changed CIDR parsing from fail-open (warn + continue) to fail-closed (return error)
- Invalid CIDR in SSRF_BLOCKED_NETWORKS now fails runtime startup
- Invalid CIDR in SSRF_ALLOWED_NETWORKS now fails runtime startup
- Location: tools_rust/mcp_runtime/src/url_validator.rs:186-210
**Issue #4 - DNS re-resolution overhead (MEDIUM):**
- Implemented DNS result caching with 5-minute TTL
- Added Arc<RwLock<HashMap<String, (Vec<IpAddr>, Instant)>>> cache
- Reduces DNS lookups on hot paths while maintaining security
- Cache prevents DNS rebinding attacks with short TTL
- Location: tools_rust/mcp_runtime/src/url_validator.rs:58-68, 486-530
**Issue #5 - Missing body-size limit test (LOW):**
- Added integration test: request_body_size_limit_rejects_large_payloads()
- Verifies 413 Payload Too Large response for >10MB request bodies
- Tests the DefaultBodyLimit middleware enforcement
- Location: tools_rust/mcp_runtime/src/lib.rs:13309-13338
All changes maintain backward compatibility except for stricter CIDR validation (fail-closed is more secure).
Addresses reviewer feedback from lucarlig on PR #4111
Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com>1 parent 33107f4 commit fd84dcf
4 files changed
Lines changed: 102 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
262 | | - | |
| 261 | + | |
| 262 | + | |
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
| 271 | + | |
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
| 290 | + | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
| 298 | + | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
| 208 | + | |
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2561 | 2561 | | |
2562 | 2562 | | |
2563 | 2563 | | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
2564 | 2571 | | |
2565 | 2572 | | |
2566 | | - | |
| 2573 | + | |
2567 | 2574 | | |
2568 | 2575 | | |
2569 | 2576 | | |
| |||
8148 | 8155 | | |
8149 | 8156 | | |
8150 | 8157 | | |
| 8158 | + | |
| 8159 | + | |
| 8160 | + | |
| 8161 | + | |
| 8162 | + | |
| 8163 | + | |
| 8164 | + | |
8151 | 8165 | | |
8152 | 8166 | | |
8153 | | - | |
| 8167 | + | |
8154 | 8168 | | |
8155 | 8169 | | |
8156 | 8170 | | |
| |||
13287 | 13301 | | |
13288 | 13302 | | |
13289 | 13303 | | |
| 13304 | + | |
| 13305 | + | |
| 13306 | + | |
| 13307 | + | |
| 13308 | + | |
| 13309 | + | |
| 13310 | + | |
| 13311 | + | |
| 13312 | + | |
| 13313 | + | |
| 13314 | + | |
| 13315 | + | |
| 13316 | + | |
| 13317 | + | |
| 13318 | + | |
| 13319 | + | |
| 13320 | + | |
| 13321 | + | |
| 13322 | + | |
| 13323 | + | |
| 13324 | + | |
| 13325 | + | |
| 13326 | + | |
| 13327 | + | |
| 13328 | + | |
| 13329 | + | |
| 13330 | + | |
| 13331 | + | |
| 13332 | + | |
| 13333 | + | |
| 13334 | + | |
| 13335 | + | |
13290 | 13336 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
65 | 67 | | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
| |||
168 | 171 | | |
169 | 172 | | |
170 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
171 | 181 | | |
172 | 182 | | |
173 | 183 | | |
| |||
183 | 193 | | |
184 | 194 | | |
185 | 195 | | |
186 | | - | |
| 196 | + | |
187 | 197 | | |
188 | 198 | | |
189 | 199 | | |
190 | 200 | | |
191 | 201 | | |
192 | | - | |
193 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
194 | 206 | | |
195 | 207 | | |
196 | 208 | | |
197 | 209 | | |
198 | | - | |
| 210 | + | |
199 | 211 | | |
200 | 212 | | |
201 | 213 | | |
202 | 214 | | |
203 | 215 | | |
204 | | - | |
205 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
206 | 220 | | |
207 | 221 | | |
208 | 222 | | |
| |||
248 | 262 | | |
249 | 263 | | |
250 | 264 | | |
| 265 | + | |
| 266 | + | |
251 | 267 | | |
252 | 268 | | |
253 | 269 | | |
| |||
464 | 480 | | |
465 | 481 | | |
466 | 482 | | |
467 | | - | |
| 483 | + | |
468 | 484 | | |
| 485 | + | |
469 | 486 | | |
470 | 487 | | |
471 | | - | |
472 | | - | |
473 | | - | |
| 488 | + | |
474 | 489 | | |
475 | 490 | | |
476 | 491 | | |
477 | 492 | | |
478 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
479 | 507 | | |
480 | 508 | | |
481 | 509 | | |
482 | 510 | | |
483 | 511 | | |
| 512 | + | |
484 | 513 | | |
485 | 514 | | |
486 | 515 | | |
487 | 516 | | |
488 | 517 | | |
489 | 518 | | |
490 | 519 | | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
491 | 527 | | |
492 | 528 | | |
493 | 529 | | |
| |||
0 commit comments