Commit df330e3
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 36520c2 commit df330e3
4 files changed
Lines changed: 102 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
271 | | - | |
| 270 | + | |
| 271 | + | |
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
| 280 | + | |
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| |||
| 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 | |
|---|---|---|---|
| |||
2636 | 2636 | | |
2637 | 2637 | | |
2638 | 2638 | | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
2639 | 2646 | | |
2640 | 2647 | | |
2641 | | - | |
| 2648 | + | |
2642 | 2649 | | |
2643 | 2650 | | |
2644 | 2651 | | |
| |||
8352 | 8359 | | |
8353 | 8360 | | |
8354 | 8361 | | |
| 8362 | + | |
| 8363 | + | |
| 8364 | + | |
| 8365 | + | |
| 8366 | + | |
| 8367 | + | |
| 8368 | + | |
8355 | 8369 | | |
8356 | 8370 | | |
8357 | | - | |
| 8371 | + | |
8358 | 8372 | | |
8359 | 8373 | | |
8360 | 8374 | | |
| |||
13966 | 13980 | | |
13967 | 13981 | | |
13968 | 13982 | | |
| 13983 | + | |
| 13984 | + | |
| 13985 | + | |
| 13986 | + | |
| 13987 | + | |
| 13988 | + | |
| 13989 | + | |
| 13990 | + | |
| 13991 | + | |
| 13992 | + | |
| 13993 | + | |
| 13994 | + | |
| 13995 | + | |
| 13996 | + | |
| 13997 | + | |
| 13998 | + | |
| 13999 | + | |
| 14000 | + | |
| 14001 | + | |
| 14002 | + | |
| 14003 | + | |
| 14004 | + | |
| 14005 | + | |
| 14006 | + | |
| 14007 | + | |
| 14008 | + | |
| 14009 | + | |
| 14010 | + | |
| 14011 | + | |
| 14012 | + | |
| 14013 | + | |
| 14014 | + | |
13969 | 14015 | | |
| 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