feat!: BREAKING CHANGE: Add configurable trusted model allowlist to prevent trust_remote_code RCE #4602
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.
Implement server-level trusted_model_prefixes configuration that controls which model organizations can execute custom code via trust_remote_code.
Changes:
o Add trusted_model_prefixes to ServerConfig with default trusted orgs o Create TrustedModelConfig mixin with is_trusted_model() method o Update inference providers to use configurable allowlist o Update post_training provider to dynamically set trust_remote_code o Models not in allowlist load with trust_remote_code=False o Add unit tests
Default trusted prefix: nomic-ai/ (default model, requires this)
BREAKING CHANGE:
The default trusted_model_prefixes list has been reduced to only ["nomic-ai/"] for security. Previously, trust_remote_code=True was implicitly allowed for all models.
Impact:
o Post-training: Models not in the trusted list will load with
trust_remote_code=False (previously all loaded with True)
o Inference: Embedding models not in the trusted list will load with
trust_remote_code=False (previously behavior was provider-dependent)
Migration:
Users needing the old behavior can add to their run.yaml:
server:
trusted_model_prefixes:
- "nomic-ai/"
- "your-org/" - "trusted-org/"
This provides centralized security policy while maintaining flexibility for legitimate custom models from trusted sources.
Closes: #4601
--
Note: Code created and iterated over with the assistance of sonnet-4.5-thinking, I've manually and tested the functionality in the inference provider but don't have the setup to verify the code in the post_training providers.