Commit 36bb5a0
committed
security: close cron + SQL-ident injection paths in backup/db tools
Two findings from the security review, both require adversarial input to
reach (MCP caller controls the args), but the blast radius exceeds what
the tool is supposed to allow:
1. **ssh_backup_schedule: cron injection via newline**
The cron validator counted whitespace-separated tokens, so a value like
"0 0 * * *\n* * * * * rm -rf ~" passed. shQuote preserves newlines
inside single-quoted strings, so `printf '%s\n' ${shQuote(cronLine)}`
installed a multi-line crontab. Fix: reject cron with any \r\n\t and
any shell metacharacter ($, `), then split on spaces only.
2. **ssh_db_{query,list,dump,import}: SQL ident injection via database/user**
`database` and `user` were shQuote'd for the shell but interpolated into
SQL strings like `SHOW TABLES FROM 'name'` and `pg_database_size('name')`.
A database name of `app'; DROP DATABASE x; --` shell-unquotes to a valid
SQL injection payload. Fix: validate database/user against
[A-Za-z0-9_][A-Za-z0-9_.-]{0,63} (the conservative intersection of
MySQL/PG/Mongo identifier rules) at handler entry.
+4 regression tests (651 -> 653 passing). No existing behavior changed for
well-formed inputs.1 parent 4ba9d85 commit 36bb5a0
4 files changed
Lines changed: 131 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
650 | | - | |
| 650 | + | |
651 | 651 | | |
652 | 652 | | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
653 | 674 | | |
654 | 675 | | |
655 | 676 | | |
| |||
696 | 717 | | |
697 | 718 | | |
698 | 719 | | |
699 | | - | |
| 720 | + | |
700 | 721 | | |
701 | 722 | | |
702 | 723 | | |
703 | 724 | | |
704 | 725 | | |
705 | 726 | | |
706 | | - | |
| 727 | + | |
707 | 728 | | |
708 | 729 | | |
709 | 730 | | |
| |||
745 | 766 | | |
746 | 767 | | |
747 | 768 | | |
748 | | - | |
| 769 | + | |
749 | 770 | | |
750 | 771 | | |
751 | 772 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
29 | 55 | | |
30 | 56 | | |
31 | 57 | | |
| |||
284 | 310 | | |
285 | 311 | | |
286 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
287 | 319 | | |
288 | 320 | | |
289 | 321 | | |
| |||
428 | 460 | | |
429 | 461 | | |
430 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
431 | 469 | | |
432 | 470 | | |
433 | 471 | | |
| |||
500 | 538 | | |
501 | 539 | | |
502 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
503 | 547 | | |
504 | 548 | | |
505 | 549 | | |
| |||
593 | 637 | | |
594 | 638 | | |
595 | 639 | | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
596 | 646 | | |
597 | 647 | | |
598 | 648 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
259 | 286 | | |
260 | 287 | | |
261 | 288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
129 | 158 | | |
130 | 159 | | |
131 | 160 | | |
| |||
0 commit comments