Commit 3e2ff2b
Fix GHSA-873f-pvrv-4x83: warn before executing a bundle's config in load()/run() (#9057)
## Summary
Fixes GHSA-873f-pvrv-4x83:
GHSA-873f-pvrv-4x83
`monai.bundle.load()`, with its default `model=None`, builds a bundle's
network by parsing the bundle's own config through `create_workflow()`.
That parsing resolves any `"_target_"` value to an importable callable
with no allow list, and passes any `"$"`-prefixed value to Python
`eval()`. `monai.bundle.run()` reaches the same code path via a
caller-supplied `config_file`. Either way, this means loading or running
a bundle whose config you haven't reviewed can execute arbitrary code.
### Design
An earlier version of this fix added an opt-in `trust_remote_code` flag
to `load()`. Per review discussion, that was dropped: MONAI has no
mechanism to actually establish whether a bundle is trustworthy (unlike,
say, a per-repo "has custom code" check), so a flag like that mostly
teaches people to set it once and forget about it, without giving them a
real basis to decide.
Instead:
- `create_workflow()` — the shared path both `load()` and `run()` use to
parse a config file — now raises a `UserWarning` immediately before
doing so, spelling out exactly what `"_target_"`/`"$"`-expression
content can do and linking this advisory.
- No behavior is blocked. Default behavior is unchanged other than the
added warning: `load()`/`run()` still parse and execute the config
exactly as before.
- The warning applies uniformly to every caller of `create_workflow()`,
not just `load()`.
### Changes
- `monai/bundle/scripts.py`: warning added in `create_workflow()`;
docstrings on `load()`, `run()`, and `create_workflow()` updated to
describe the risk and point at the advisory.
- `tests/bundle/test_bundle_download.py`:
`TestLoadWarnsOnConfigExecution` — default `load()` warns and still
executes the config (no flag needed), explicit `model=` still skips
config parsing entirely (and warns about nothing), and `run()` warns via
the same `create_workflow()` path.
## Test plan
- [x] `python3 -m unittest
tests.bundle.test_bundle_download.TestLoadWarnsOnConfigExecution -v`
- [x] Full `tests/bundle/test_bundle_download.py`,
`tests/bundle/test_config_parser.py` — no new failures vs. `dev`
(remaining failures are pre-existing environment gaps: missing
`requests`/`nibabel`, one `pdb`/`bdb` quirk)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Signed-off-by: R. Garcia-Dias <rafaelagd@gmail.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>1 parent 6644898 commit 3e2ff2b
2 files changed
Lines changed: 104 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
651 | 659 | | |
652 | 660 | | |
653 | 661 | | |
| |||
935 | 943 | | |
936 | 944 | | |
937 | 945 | | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
938 | 952 | | |
939 | 953 | | |
940 | 954 | | |
| |||
1929 | 1943 | | |
1930 | 1944 | | |
1931 | 1945 | | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
1932 | 1952 | | |
1933 | 1953 | | |
1934 | 1954 | | |
| |||
1966 | 1986 | | |
1967 | 1987 | | |
1968 | 1988 | | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
1969 | 1996 | | |
1970 | 1997 | | |
1971 | 1998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
98 | 108 | | |
99 | 109 | | |
100 | 110 | | |
| |||
488 | 498 | | |
489 | 499 | | |
490 | 500 | | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
491 | 567 | | |
492 | 568 | | |
0 commit comments