Skip to content

fix(trl): disable inline GRPO reward code by default (RCE, #11015) - #11068

Merged
mudler merged 1 commit into
mudler:masterfrom
wuisabel-gif:fix/trl-inline-reward-rce
Jul 23, 2026
Merged

mudler merged 1 commit into
mudler:masterfrom
wuisabel-gif:fix/trl-inline-reward-rce

Conversation

@wuisabel-gif

@wuisabel-gif wuisabel-gif commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

POST /api/fine-tuning/jobs accepts reward_functions[].code, an inline Python body, which compile_inline_reward() (backend/python/trl/reward_functions.py) execs against a hand-rolled _SAFE_BUILTINS allowlist. That allowlist is not a security boundary — the classic escape

().__class__.__bases__[0].__subclasses__()  # -> os._wrap_close -> os.system

reaches the real os module and yields arbitrary code execution on the host. Execution happens synchronously during a smoke test at job start, and the fine-tuning endpoint is unauthenticated by default, so any caller can run code on the server. (Reported in #11015.)

Fix

Hardening the allowlist against CPython introspection is a losing game, so this doesn't try. Instead:

  • Inline reward code is refused by default. It runs only when the operator explicitly opts in with LOCALAI_TRL_ALLOW_INLINE_REWARD=true on the backend — an informed choice to allow authorized API callers to execute code on that host.
  • Builtin reward functions are unaffected — the common path keeps working with no config.
  • The gate lives in build_reward_functions(), the single chokepoint all inline specs pass through.
  • Docs (docs/content/features/fine-tuning.md) no longer describe the allowlist as a sandbox; they document the opt-in and warn that inline code is arbitrary execution.

Test

Added backend/python/trl/test_reward_functions.py (stdlib only, no gRPC/model deps):

  • inline refused by default
  • builtins still work with no opt-in
  • inline runs when opted in
  • falsey env values ("", 0, false, no, off) stay disabled
Ran 4 tests in 0.000s
OK

Fixes #11015

@wuisabel-gif
wuisabel-gif force-pushed the fix/trl-inline-reward-rce branch from f1d73e1 to 9585d5b Compare July 23, 2026 05:59
POST /api/fine-tuning/jobs accepts reward_functions[].code, an inline Python
body, and compile_inline_reward() execs it against a restricted-builtins
allowlist (_SAFE_BUILTINS). That allowlist is not a security boundary:
().__class__.__bases__[0].__subclasses__() reaches os._wrap_close and thus
os.system, giving arbitrary code execution. The fine-tuning endpoint is
unauthenticated by default, so any caller could run code on the host.

Hardening the allowlist is a losing game against CPython introspection, so
inline reward code is now refused unless the operator explicitly opts in with
LOCALAI_TRL_ALLOW_INLINE_REWARD=true on the backend. Builtin reward functions
are unaffected. The gate lives in build_reward_functions(), the single point
all inline specs flow through. Docs updated to stop describing the allowlist as
a sandbox and to document the opt-in.

Fixes mudler#11015

Signed-off-by: Isabel Wu <[email protected]>
@wuisabel-gif
wuisabel-gif force-pushed the fix/trl-inline-reward-rce branch from 9585d5b to af293ce Compare July 23, 2026 06:12
@wuisabel-gif

Copy link
Copy Markdown
Contributor Author

Thanks — both addressed and force-pushed:

  • Docs now use {{% notice warning %}} / {{% /notice %}} instead of the unsupported alert shortcode.
  • Commit is signed off (DCO).

@mudler
mudler merged commit 977f663 into mudler:master Jul 23, 2026
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug 5: RCE via inline GRPO reward function sandbox escape

2 participants