# model-loading-v1

> model-loading-v1: 14 Keryn rules for python (11 error, 3 warning).

Source: https://keryn.dev/rules/model-loading-v1/

14 rules · Keryn Software Licence · rules 0.8.0 · [all packs](https://keryn.dev/rules/)

**How to read a rule**

- **Severity**: How bad the finding is if it is real: `error` fails a default gate, `warning` and `info` do not.

- **Confidence**: **P0** exploitable as written; **P1** dangerous in context; **P2** a heuristic or a posture check: confirm by reading the code.

- **False-positive risk**: **low**: an exact API or flag, so hits are almost always real; **medium**: the pattern is legitimate in many programs, so check each hit; **high**: it finds a lead to confirm, so expect benign hits.

- **Edge**: The relationship the finding sits on. **reaches**: content or traffic gets to a thing; **calls**: one thing invokes another; **reads**: one thing reads from another; **writes**: one thing writes to another; **sends**: data leaves for another party; **grants**: authority is given or left unchecked; **depends_on**: something relies on a component it does not verify; **trusts**: one party believes another without evidence. The boundary it crosses, when there is one: **user->prompt** (untrusted input reaching a prompt); **model->code** (model output reaching code, a shell, a query or a page); **secret->outside** (a secret leaving the trusted side); **supply-chain** (code, models or prompts pulled in from outside).

- **Taxonomy chips**: References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.

## keryn.modelload.keras-load-model-safe-mode-disabled-py

`error` python keras, tensorflow

Keras load\_model is called with safe\_mode=False on a path that is not a literal. In the .keras format a Lambda layer is stored as Python bytecode and safe\_mode is the only switch that stops it from being rebuilt, so a model file from outside your build runs code the moment it loads; keep safe\_mode at its default and load only files you produced.

Confidence **P0**: exploitable as written. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Remove safe\_mode=False. If the model genuinely needs custom layers, register them with keras.saving.register\_keras\_serializable and pass custom\_objects, or export weights only (model.save\_weights / load\_weights) and rebuild the architecture in code. Verify a checksum or signature of the file before loading.

**References:** [https://keras.io/api/models/model_saving_apis/model_saving_and_loading/](https://keras.io/api/models/model_saving_apis/model_saving_and_loading/)

**Try it: a snippet that triggers this rule**

Written for this page, not taken from any project. Save it as `ml/predict.py` and scan it with `keryn scan ml --verbose`; the finding below appears.

```python
import tensorflow as tf

def load(path):
    model = tf.keras.models.load_model(path, safe_mode=False)
    model.summary()
    return model
```

Checked with Keryn's browser engine when this page was built: it reports `keryn.modelload.keras-load-model-safe-mode-disabled-py` at line 5 (error, proof 1). The rule's own logic is not published, so it cannot run in this tab; the pack list in the [playground](https://keryn.dev/playground/) shows what does.

## keryn.modelload.numpy-load-allow-pickle-py

`error` python numpy

numpy.load is called with allow\_pickle=True on a path that is not a literal. NumPy stores object arrays with pickle and documents that this is not secure against maliciously constructed data, so a swapped or downloaded .npy/.npz file can execute code at load time; keep allow\_pickle=False and store plain numeric arrays (or safetensors).

Confidence **P0**: exploitable as written. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Drop allow\_pickle=True and re-save the data as a numeric array, .npz of numeric arrays or safetensors. If object arrays are unavoidable, load only files from a location your pipeline writes to and verify a hash first.

**References:** [https://numpy.org/doc/stable/reference/generated/numpy.load.html](https://numpy.org/doc/stable/reference/generated/numpy.load.html)

**Try it: a snippet that triggers this rule**

Written for this page, not taken from any project. Save it as `ml/embeddings.py` and scan it with `keryn scan ml --verbose`; the finding below appears.

```python
import numpy as np

def load_embeddings(path):
    data = np.load(path, allow_pickle=True)
    return data["vectors"], data["labels"]
```

Checked with Keryn's browser engine when this page was built: it reports `keryn.modelload.numpy-load-allow-pickle-py` at line 5 (error, proof 1). The rule's own logic is not published, so it cannot run in this tab; the pack list in the [playground](https://keryn.dev/playground/) shows what does.

## keryn.modelload.pandas-read-pickle-py

`error` python pandas

pandas.read\_pickle is called on a path that is not a literal. The pandas docs warn that loading pickled data from untrusted sources is unsafe, and the call also accepts URLs, so an attacker-supplied or downloaded file executes code during unpickling; use Parquet, Feather or CSV for exchanged data.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Exchange tabular artefacts as Parquet or Feather. Keep read\_pickle for files your own job wrote into a private location, and check a hash of the file before reading.

**References:** [https://pandas.pydata.org/docs/reference/api/pandas.read_pickle.html](https://pandas.pydata.org/docs/reference/api/pandas.read_pickle.html)

## keryn.modelload.cloudpickle-or-dill-loads-py

`error` python cloudpickle, dill

cloudpickle.load/loads or dill.loads deserialises a value that is not a literal. Both extend pickle (they even serialise functions and lambdas by value), so whoever controls the bytes controls code execution on this host; load a data-only format such as JSON or safetensors instead.

Confidence **P0**: exploitable as written. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Replace the pickle-family call with a data-only format. If code objects must travel (distributed workers), keep the channel inside an authenticated, private network and sign the payload with an HMAC verified before loads.

**References:** [https://github.com/cloudpipe/cloudpickle](https://github.com/cloudpipe/cloudpickle) · [https://docs.python.org/3/library/pickle.html](https://docs.python.org/3/library/pickle.html) · [https://raw.githubusercontent.com/cloudpipe/cloudpickle/master/cloudpickle/cloudpickle.py](https://raw.githubusercontent.com/cloudpipe/cloudpickle/master/cloudpickle/cloudpickle.py)

**Try it: a snippet that triggers this rule**

Written for this page, not taken from any project. Save it as `worker/tasks.py` and scan it with `keryn scan worker --verbose`; the finding below appears.

```python
import cloudpickle
import redis

r = redis.Redis(host="cache.internal.example")

def run_next():
    raw = r.lpop("jobs")
    if raw is None:
        return None
    fn, args = cloudpickle.loads(raw)
    return fn(*args)
```

Checked with Keryn's browser engine when this page was built: it reports `keryn.modelload.cloudpickle-or-dill-loads-py` at line 11 (error, proof 1). The rule's own logic is not published, so it cannot run in this tab; the pack list in the [playground](https://keryn.dev/playground/) shows what does.

## keryn.modelload.skops-load-trust-everything-py

`warning` python skops, scikit-learn

skops.io.load is given the list returned by get\_untrusted\_types as its trusted argument. That list is what the file asks to be allowed, so passing it straight back turns the skops allow-list into a rubber stamp and re-opens the arbitrary-type loading skops exists to prevent; print or review the types and pass an explicit, hard-coded list.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Call get\_untrusted\_types in a review step, compare the result with a short list you have approved (for example ["xgboost.sklearn.XGBClassifier"]) and pass only that list as trusted.

**References:** [https://skops.readthedocs.io/en/stable/persistence.html](https://skops.readthedocs.io/en/stable/persistence.html)

## keryn.modelload.torch-package-importer-py

`error` python pytorch

torch.package.PackageImporter opens a package whose path is not a literal. The torch.package docs state the format relies on pickle and say to unpackage only data you trust, so an attacker-supplied .pt/.zip package runs code when its pickled objects are loaded; restrict the path to files your build produced and verify them first.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Resolve the package from a fixed directory, check its SHA-256 against a pinned value before opening it, and pass module\_allowed to restrict which external modules it may import. Prefer exporting plain weights (safetensors) when code need not travel with the model.

**References:** [https://docs.pytorch.org/docs/2.14/package.html](https://docs.pytorch.org/docs/2.14/package.html)

## keryn.modelload.native-extension-library-load-py

`error` python pytorch, tensorflow

A native shared library is loaded into the process from a path that is not a literal (torch.ops.load\_library, torch.classes.load\_library or tf.load\_op\_library). Loading registers custom ops by running the library's initialisers, so a swapped .so/.dll is native code execution with the service's privileges; load only libraries shipped in your image from fixed paths.

Confidence **P0**: exploitable as written. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify.

[CWE-427](https://keryn.dev/rules/?cwe=CWE-427) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI05](https://keryn.dev/taxonomies/owasp-agentic/#asi05-unexpected-code-execution)

**Fix:** Ship the custom-op library inside the image, reference it by a constant absolute path, and never build the path from request fields, model metadata or downloaded manifests.

**References:** [https://www.tensorflow.org/api_docs/python/tf/load_op_library](https://www.tensorflow.org/api_docs/python/tf/load_op_library) · [https://docs.pytorch.org/docs/stable/torch.html](https://docs.pytorch.org/docs/stable/torch.html) · [https://raw.githubusercontent.com/pytorch/pytorch/main/torch/_ops.py](https://raw.githubusercontent.com/pytorch/pytorch/main/torch/_ops.py) · [https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/python/framework/load_library.py](https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/python/framework/load_library.py)

## keryn.modelload.torch-hub-load-state-dict-nonliteral-url-py

`error` python pytorch

torch.hub.load\_state\_dict\_from\_url downloads from a URL that is not a literal and does not set weights\_only=True (its default is False). The checkpoint is unpickled, so whoever influences the URL gets code execution; pass weights\_only=True and download only from pinned, trusted locations.

Confidence **P0**: exploitable as written. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Set weights\_only=True and check\_hash=True, keep the URL in server-side configuration, and prefer safetensors checkpoints.

**References:** [https://docs.pytorch.org/docs/2.14/hub.html](https://docs.pytorch.org/docs/2.14/hub.html)

**Try it: a snippet that triggers this rule**

Written for this page, not taken from any project. Save it as `ml/weights.py` and scan it with `keryn scan ml --verbose`; the finding below appears.

```python
import torch

def fetch_backbone(cfg):
    url = cfg["backbone_url"]
    return torch.hub.load_state_dict_from_url(url, map_location="cpu")
```

Checked with Keryn's browser engine when this page was built: it reports `keryn.modelload.torch-hub-load-state-dict-nonliteral-url-py` at line 6 (error, proof 1). The rule's own logic is not published, so it cannot run in this tab; the pack list in the [playground](https://keryn.dev/playground/) shows what does.

## keryn.modelload.torch-hub-load-state-dict-literal-url-unhardened-py

`warning` python pytorch

torch.hub.load\_state\_dict\_from\_url fetches a fixed URL without weights\_only=True and without check\_hash=True. The checkpoint is unpickled and nothing ties the bytes to the release you reviewed, so a compromised host or a hijacked redirect yields code execution; set weights\_only=True and name the file with its hash prefix.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-494](https://keryn.dev/taxonomies/cwe/#cwe-494-download-of-code-without-integrity-check) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Add weights\_only=True and check\_hash=True (with a file name that carries the first characters of the SHA-256), or vendor the checkpoint into your artefact store.

**References:** [https://docs.pytorch.org/docs/2.14/hub.html](https://docs.pytorch.org/docs/2.14/hub.html)

## keryn.modelload.torch-hub-load-trust-repo-nonliteral-py

`error` python pytorch

torch.hub.load is called with trust\_repo=True on a repository string that is not a literal. trust\_repo=True skips the interactive confirmation and the repo's hubconf.py is then imported and executed, so a request- or config-derived repo name runs arbitrary code from any GitHub repo; use a fixed owner/repo:ref and a reviewed commit.

Confidence **P0**: exploitable as written. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-829](https://keryn.dev/taxonomies/cwe/#cwe-829-inclusion-of-functionality-from-untrusted-control-sphere) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Hard-code the repository with a tag or commit ("owner/repo:&lt;sha&gt;"), keep trust\_repo at its default, or vendor the entry point and use source="local".

**References:** [https://docs.pytorch.org/docs/2.14/hub.html](https://docs.pytorch.org/docs/2.14/hub.html)

## keryn.modelload.torch-jit-load-nonliteral-path-py

`warning` python pytorch

torch.jit.load opens a TorchScript archive from a path that is not a literal. A TorchScript archive carries serialised code and pickled constants, so a file you did not build can run attacker-chosen operations when it executes; load archives only from a fixed, access-controlled location after a hash check.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Resolve the file inside a fixed model directory (reject separators and .. in names), verify its SHA-256 against a pinned value, and prefer exporting weights as safetensors.

**References:** [https://docs.pytorch.org/docs/stable/jit.html](https://docs.pytorch.org/docs/stable/jit.html) · [https://raw.githubusercontent.com/pytorch/pytorch/main/torch/jit/_serialization.py](https://raw.githubusercontent.com/pytorch/pytorch/main/torch/jit/_serialization.py)

## keryn.modelload.yaml-load-unsafe-loader-py

`error` python pyyaml

yaml.load uses the full Loader or UnsafeLoader (or yaml.unsafe\_load is called) on a value that is not a literal. PyYAML documents that these loaders can construct arbitrary Python objects and are as powerful as pickle.load, so a model or pipeline config with a !!python/object tag executes code; use yaml.safe\_load.

Confidence **P0**: exploitable as written. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Replace the call with yaml.safe\_load (or Loader=yaml.SafeLoader) and validate the resulting dict with pydantic or a schema before use.

**References:** [https://pyyaml.org/wiki/PyYAMLDocumentation](https://pyyaml.org/wiki/PyYAMLDocumentation) · [https://raw.githubusercontent.com/yaml/pyyaml/main/lib/yaml/loader.py](https://raw.githubusercontent.com/yaml/pyyaml/main/lib/yaml/loader.py)

**Try it: a snippet that triggers this rule**

Written for this page, not taken from any project. Save it as `ml/config.py` and scan it with `keryn scan ml --verbose`; the finding below appears.

```python
import yaml

def read_config(path):
    with open(path) as fh:
        return yaml.load(fh, Loader=yaml.FullLoader)
```

Checked with Keryn's browser engine when this page was built: it reports `keryn.modelload.yaml-load-unsafe-loader-py` at line 6 (error, proof 1). The rule's own logic is not published, so it cannot run in this tab; the pack list in the [playground](https://keryn.dev/playground/) shows what does.

## keryn.modelload.hf-hub-download-result-unpickled-py

`error` python huggingface, pytorch, joblib

A file fetched with hf\_hub\_download from a repo id that is not a literal is passed straight to a pickle-backed loader. Any public Hub repo can host a malicious checkpoint, and torch.load, joblib.load, pickle.load or numpy allow\_pickle execute it on load; resolve repo ids through an allow-list and load safetensors instead.

Confidence **P0**: exploitable as written. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Map the requested model to a repo id and commit hash held in configuration, download a .safetensors file, and load it with safetensors.torch.load\_file.

**References:** [https://huggingface.co/docs/huggingface_hub/package_reference/file_download](https://huggingface.co/docs/huggingface_hub/package_reference/file_download) · [https://huggingface.co/docs/hub/security-pickle](https://huggingface.co/docs/hub/security-pickle) · [https://raw.githubusercontent.com/cloudpipe/cloudpickle/master/cloudpickle/cloudpickle.py](https://raw.githubusercontent.com/cloudpipe/cloudpickle/master/cloudpickle/cloudpickle.py)

## keryn.modelload.request-path-to-model-loader-python

`error` python data-flow rule flask, fastapi, pytorch, joblib, numpy, keras

A request parameter or route argument becomes the path of a model loader (torch.load, joblib.load, numpy.load, pickle.load(open(...)), pandas.read\_pickle or keras load\_model). Pickle-backed loaders execute code and every loader reads whatever file the caller names, so a caller can point it at an uploaded or attacker-staged artefact; map the request value to a fixed file through an allow-list.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [depends_on](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-22](https://keryn.dev/taxonomies/cwe/#cwe-22-path-traversal) [CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Accept a model name, look it up in a dict or enum of server-side paths (if name not in MODELS: abort) and load the mapped file. If a file name must pass through, reduce it with os.path.basename or werkzeug's secure\_filename, join it to a fixed directory, and still prefer safetensors or weights\_only=True.

**References:** [https://flask.palletsprojects.com/en/stable/api/#flask.Request](https://flask.palletsprojects.com/en/stable/api/#flask.Request) · [https://fastapi.tiangolo.com/tutorial/path-params/](https://fastapi.tiangolo.com/tutorial/path-params/) · [https://numpy.org/doc/stable/reference/generated/numpy.load.html](https://numpy.org/doc/stable/reference/generated/numpy.load.html) · [https://keras.io/api/models/model_saving_apis/model_saving_and_loading/](https://keras.io/api/models/model_saving_apis/model_saving_and_loading/)
