safe_eval: sequence repetition (str/list/bytes * int) is not bounded, unlike **
Summary
safe_eval() (core/framework/orchestrator/safe_eval.py) is the sandboxed evaluator for graph edge conditional expressions. It explicitly bounds ** to prevent CPU/memory exhaustion (_safe_pow, capping exponent size and estimating result bit-length before computing), with tests covering it. The same attack works through *: str * int, bytes * int, and list * int go straight to operator.mul with no size limit at all.
Repro
from framework.orchestrator.safe_eval import safe_eval
safe_eval('2 ** 999999999') # raises ValueError: Power exponent exceeds safe limit (1000)
safe_eval('"x" * 10_000_000_000') # NOT blocked -- tries to allocate a 10GB stringWhy it matters
condition_exprvalues are explicitly documented as something a Builder agent can generate dynamically from a goal, i.e. they can originate from LLM output that may itself be influenced by untrusted upstream content.- The module's own per-node timeout (
_check_timeout) only runs between AST node visits, not during the single C-level call that performs the allocation, so it doesn't reliably catch a single large*. - The SIGALRM-based hard timeout in
_execution_timeoutis silently skipped off the main thread, and also silently skipped whenever the process already has an active interval timer owned by something else (if current_delay > 0 or current_interval > 0: yield) -- so in some deployments there is no timeout enforcement at all for this path.
Proposed fix
Add a _safe_mult wrapper mirroring _safe_pow: before delegating to operator.mul, check whether either operand is a bounded-length sequence (str/bytes/list/tuple) being multiplied by an int, and reject it if the resulting length would exceed a safe cap (mirrors the existing MAX_POWER_RESULT_BITS pattern). Wire it into SAFE_OPERATORS[ast.Mult].
I have a working patch (fix + 6 new tests) ready to open as a PR once this is assigned -- ruff check/ruff format --check clean, full core/tests/ suite passes (2506 passed / 15 skipped / 0 failed).
I'd like to work on this!
Source: aden-hive/hive