Repository navigation
fix(trl): disable inline GRPO reward code by default (RCE, #11015) - #11068
Merged
Merged
Conversation
wuisabel-gif
force-pushed
the
fix/trl-inline-reward-rce
branch
from
July 23, 2026 05:59
f1d73e1 to
9585d5b
Compare
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
force-pushed
the
fix/trl-inline-reward-rce
branch
from
July 23, 2026 06:12
9585d5b to
af293ce
Compare
Contributor
Author
|
Thanks — both addressed and force-pushed:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
POST /api/fine-tuning/jobsacceptsreward_functions[].code, an inline Python body, whichcompile_inline_reward()(backend/python/trl/reward_functions.py)execs against a hand-rolled_SAFE_BUILTINSallowlist. That allowlist is not a security boundary — the classic escapereaches the real
osmodule 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:
LOCALAI_TRL_ALLOW_INLINE_REWARD=trueon the backend — an informed choice to allow authorized API callers to execute code on that host.build_reward_functions(), the single chokepoint all inline specs pass through.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):"",0,false,no,off) stay disabledFixes #11015