# GHSA-H89G-R5PC-WXFM: \_get\_fake\_spatial\_shape() ast.Name-only allowlist bypassable via Attribute chains — eval sandbox escape

- Database: GitHub
- Severity: CVSS 7.0 (High)
- Published: 2026-08-18
- Modified: 2026-08-18

## Affected versions

- monai (PyPI): all versions

## Description

# F004 — `_get_fake_spatial_shape` `eval()` sandbox bypass

| | |
|---|---|
| **ID** | securin0days-MONAI-F004 |
| **Severity** | LOW (internal API, requires attacker to influence `shape` parameter) |
| **CVSSv3.1** | `CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H` — Base 6.0 |
| **CVSSv4.0** | `CVSS:4.0/AV:L/AC:H/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H` — Base 6.0 |
| **Exploit maturity** | **CODE-EXEC** (in a non-default flow) |
| **CWE** | CWE-95 Eval Injection |
| **Pattern** | 0day-patterns.md P11 |

## 1. Sink

`monai/bundle/scripts.py:141-167`

```python
def _get_fake_spatial_shape(shape, p=1, n=1, any=1):
    ret = []
    for i in shape:
        if isinstance(i, int):
            ret.append(i)
        elif isinstance(i, str):
            if i == "*":
                ret.append(any)
            else:
                for c in _get_var_names(i):
                    if c not in ["p", "n"]:
                        raise ValueError(...)
                ret.append(eval(i, {"p": p, "n": n}))    # ← sink
```

## 2. Sandbox bypass

`_get_var_names()` walks the AST collecting `ast.Name` nodes only. Expressions whose tokens are `ast.Attribute` / `ast.Subscript` / `ast.Call` on **constants** pass the filter because they have no `ast.Name` references.

PoC strings that bypass the filter:

```python
"(1).__class__.__bases__[0].__subclasses__()"     # leaks all subclasses incl. os module pieces
"(1).__class__.__mro__[1].__subclasses__()[0](...)" # construct via subclass chain
"int.__class__.__init__.__globals__"               # globals leak
```

Each contains zero `ast.Name` references — passes the `c not in ["p", "n"]` check trivially. `eval()` then evaluates the dotted attribute chain, returning a reference to e.g. the `subprocess.Popen` class.

## 3. Reachability

`_get_fake_spatial_shape` is called from:

- `monai/bundle/scripts.py:_get_real_input_data` and `verify_net_in_out` — both invoked through `bundle verify_net_in_out` CLI, with `shape` coming from the metadata file. Bundle metadata is attacker-controlled in the same threat model as F002.

## 4. Recommended fix

Replace the `ast.Name`-only filter with `ast.literal_eval`:

```python
import ast
try:
    expr_ast = ast.parse(i, mode="eval")
    # Only allow Name/Constant/BinOp/UnaryOp with restricted ops
    ALLOWED = (ast.Expression, ast.Name, ast.Load, ast.Constant,
               ast.BinOp, ast.UnaryOp, ast.Add, ast.Sub, ast.Mult, ast.Div,
               ast.Pow, ast.Mod, ast.USub, ast.UAdd)
    if any(not isinstance(node, ALLOWED) for node in ast.walk(expr_ast)):
        raise ValueError("disallowed AST node")
    ret.append(eval(compile(expr_ast, "<shape>", "eval"), {"p": p, "n": n}))
except Exception as e:
    raise ValueError(f"invalid shape expression: {i}") from e
```

## 5. Regression check

**N/A — no git history.**


---

## Reporter

Submitted via SecurinDisclose. Coordinated-disclosure window: 90 days from 2026-05-29 (public disclosure target 2026-08-27).

## References

- https://github.com/Project-MONAI/MONAI/security/advisories/GHSA-h89g-r5pc-wxfm

Page: https://cve.now/GHSA-H89G-R5PC-WXFM

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
