Commit 3c75b2e
fix(security): CSRF origin validation and forwarded-header pass-through for reverse-proxy deployments (#3431)
Behind layered reverse proxies, X-Forwarded-Proto / X-Forwarded-Host
headers may reflect internal hops rather than the external scheme,
causing the strict same-origin CSRF check to reject legitimate admin
mutations.
- Extend _request_origin_matches() to fall back to settings.allowed_origins
when the forwarded-header comparison fails; wildcard entries (*, null, "")
are excluded to preserve fail-closed behavior
- Normalize allowed_origins entries (strip whitespace, case-insensitive null)
- Add map block to nginx.conf and Helm nginx configmap to preserve upstream
X-Forwarded-Proto instead of overwriting with $scheme; pass X-Forwarded-Host
Closes #3431
Signed-off-by: Jonathan Springer <jps@s390x.com>1 parent 8cf7bc8 commit 3c75b2e
File tree
4 files changed
+215
-23
lines changed- charts/mcp-stack/templates
- infra/nginx
- mcpgateway
- tests/unit/mcpgateway
4 files changed
+215
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
54 | | - | |
| 61 | + | |
55 | 62 | | |
56 | 63 | | |
57 | | - | |
| 64 | + | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
188 | 195 | | |
189 | 196 | | |
190 | 197 | | |
| |||
285 | 292 | | |
286 | 293 | | |
287 | 294 | | |
288 | | - | |
| 295 | + | |
| 296 | + | |
289 | 297 | | |
290 | 298 | | |
291 | 299 | | |
| |||
313 | 321 | | |
314 | 322 | | |
315 | 323 | | |
316 | | - | |
| 324 | + | |
| 325 | + | |
317 | 326 | | |
318 | 327 | | |
319 | 328 | | |
| |||
361 | 370 | | |
362 | 371 | | |
363 | 372 | | |
364 | | - | |
| 373 | + | |
| 374 | + | |
365 | 375 | | |
366 | 376 | | |
367 | 377 | | |
| |||
384 | 394 | | |
385 | 395 | | |
386 | 396 | | |
387 | | - | |
| 397 | + | |
| 398 | + | |
388 | 399 | | |
389 | 400 | | |
390 | 401 | | |
| |||
450 | 461 | | |
451 | 462 | | |
452 | 463 | | |
453 | | - | |
| 464 | + | |
| 465 | + | |
454 | 466 | | |
455 | 467 | | |
456 | 468 | | |
| |||
477 | 489 | | |
478 | 490 | | |
479 | 491 | | |
480 | | - | |
| 492 | + | |
| 493 | + | |
481 | 494 | | |
482 | 495 | | |
483 | 496 | | |
| |||
500 | 513 | | |
501 | 514 | | |
502 | 515 | | |
503 | | - | |
| 516 | + | |
| 517 | + | |
504 | 518 | | |
505 | 519 | | |
506 | 520 | | |
| |||
518 | 532 | | |
519 | 533 | | |
520 | 534 | | |
521 | | - | |
| 535 | + | |
| 536 | + | |
522 | 537 | | |
523 | 538 | | |
524 | 539 | | |
| |||
534 | 549 | | |
535 | 550 | | |
536 | 551 | | |
537 | | - | |
| 552 | + | |
| 553 | + | |
538 | 554 | | |
539 | 555 | | |
540 | 556 | | |
| |||
564 | 580 | | |
565 | 581 | | |
566 | 582 | | |
567 | | - | |
| 583 | + | |
| 584 | + | |
568 | 585 | | |
569 | 586 | | |
570 | 587 | | |
| |||
596 | 613 | | |
597 | 614 | | |
598 | 615 | | |
599 | | - | |
| 616 | + | |
| 617 | + | |
600 | 618 | | |
601 | 619 | | |
602 | 620 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
1083 | 1091 | | |
1084 | 1092 | | |
1085 | 1093 | | |
1086 | 1094 | | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
| 1095 | + | |
| 1096 | + | |
1093 | 1097 | | |
1094 | 1098 | | |
1095 | 1099 | | |
| |||
1117 | 1121 | | |
1118 | 1122 | | |
1119 | 1123 | | |
1120 | | - | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
1121 | 1147 | | |
1122 | 1148 | | |
1123 | 1149 | | |
| |||
0 commit comments