OpenModels is pre-1.0 (currently in alpha/beta). Only the latest published release is supported with security fixes.
Please do not open a public GitHub issue for security vulnerabilities.
Instead, report it privately via GitHub Security Advisories, or by emailing a.gutierrez@g-npd.com. Include as much detail as you can (affected version, reproduction steps, impact) so we can assess and respond quickly.
OpenModels ships four output formats with very different trust requirements:
-
JSON (
format_name="json", the default): the serialized payload is plain data (numbers, strings, arrays). Loading it doesn't execute code from the file or construct arbitrary objects (see "Functions referenced by a model" below for the one kind of reference it resolves). -
MessagePack (
format_name="msgpack", requires the optionalmsgpackpackage - seepip install openmodels[msgpack]): the same trust profile as JSON. MessagePack has the same data model as JSON (numbers, strings, booleans, arrays, maps) and no mechanism to execute code or construct arbitrary objects on load. -
YAML (
format_name="yaml", requires the optionalPyYAMLpackage - seepip install openmodels[yaml]): the same trust profile as JSON, but only because OpenModels deliberately restricts itself toyaml.safe_load()/yaml.safe_dump(). YAML's defaultLoader/Dumpersupport a!!python/objecttag family that can construct arbitrary Python objects on load - PyYAML's own equivalent of pickle's arbitrary-code-execution risk - andYAMLConverternever uses them. This is a design choiceopenmodelsmakes for you, not a property of YAML files in general: a YAML file loaded some other way (yaml.load()with the default loader) can still be unsafe. -
Pickle (
format_name="pickle"): under the hood this calls Python'spickle.loads(), which can execute arbitrary code as part of deserialization. This is a property of the pickle format itself, not something OpenModels adds or can remove. Only load pickle files from sources you trust, exactly as you would withpickle,joblib, or any other pickle-based tool. Never callSerializationManager.load(..., format_name="pickle")/SerializationManager.deserialize(..., format_name="pickle")on a file received from an untrusted or unauthenticated source.Note that this isn't
pickle.dumps()/joblib.dump()on the fitted estimator itself - OpenModels always converts the model to the same plain dict documented indocs/format.mdfirst (the oneestimator_class/params/attributes/metadatashape the JSON format also uses), and only then hands that dict topickle.dumps(). Choosing the pickle format changes how that dict is encoded on disk, not what gets serialized - the arbitrary-code-execution risk comes entirely from callingpickle.loads()at all, regardless of how harmless the encoded content happens to be.
If you don't have a specific reason to use the pickle format, prefer JSON — it's the default, it's human-readable, and it doesn't carry this risk.
scikit-learn's compiled code uses fitted state (tree nodes, support vectors, cluster centers,
sparse matrices) without bounds checks. Loading checks that this state is consistent and
raises DeserializationError if it isn't. If you find a file that loads and then crashes or
hangs a model, please report it as a vulnerability.
A file that passes is well-formed, not trustworthy: it can describe any model, so treat the predictions of a model from an untrusted source as untrusted.
Some estimators take a function as a parameter, e.g. a FunctionTransformer's func or a
SelectKBest's score_func. The file stores these by module and name. Loading never imports
a module named by the file, and only accepts functions from numpy, scipy, scikit-learn and the
packages of your registered custom_estimators, checked against the module each function is
defined in, so functions those packages merely re-export (e.g. os.makedirs) are refused. Any
other function reference raises DeserializationError.
To load models that use your own functions, list their modules explicitly:
SklearnSerializer(trusted_function_modules=["mypkg"]). Those modules (and their submodules)
may then be imported while loading, so only list code you trust. Functions defined in a script
or notebook (__main__) are never accepted.
Loading a model doesn't call these functions, but using it does: predict/transform/fit on
a model from an untrusted source run whichever allowed function the file chose. Treat such a
model's outputs as untrusted.