Fix CVE-2026-5843: gate model_file execution behind trust_remote_code#1385
Conversation
Loading a model whose config.json contains a model_file key used to import and execute that Python file from the model directory unconditionally on any load(). Gate it behind an explicit opt-in, mirroring the tokenizer's trust_remote_code convention: - load_model: add trust_remote_code (default False) and raise an actionable ValueError when a config requests model_file without it - honor the MLX_LM_TRUST_REMOTE_CODE env var (1/true/yes) - thread the flag through load() and sharded_load() - add tests: blocked by default with no side effects, enabled via flag, enabled via env var, normal models unaffected
|
Worth flagging though that it's an mlx-lm only change and only covers the |
Yeah, this one's just the model_file path (CVE-2026-5843). The heap overflow in the core loaders is a separate bug and trust_remote_code won't help there. Can't see the advisory tho, happy to help if you can add me. |
angeloskath
left a comment
There was a problem hiding this comment.
Thanks! I removed the env var and added the argument everywhere. Also added it to all scripts and is now shared with the hf tokenizer when passed in the scripts.
If a model's config.json has a
model_filekey,load_modelimports and runsthat Python file straight from the model directory (added in #830). It happens
on a plain
load()with no way to turn it off, so loading a model can executearbitrary code. This is CVE-2026-5843 / GHSA-9m9w-53g9-47c4: it was reported
against Docker Model Runner, which embeds mlx-lm, but the root cause is here in
the library and main is still unguarded. The tokenizer path already puts custom
code behind
trust_remote_code, so this does the same formodel_file.load_modelnow takestrust_remote_code(default False) and raises with aclear message if a config wants a
model_filewithout it. SettingMLX_LM_TRUST_REMOTE_CODE=1works too for the CLI tools. The flag is threadedthrough
load()andsharded_load(), and models without amodel_fileareunchanged.
Tests cover the four cases: blocked by default with the custom file never
executed, enabled by the argument, enabled by the env var, and a normal model
still loading.ed