# Python AI and ML Framework Vulnerabilities
> Recurring vulnerability patterns in the Python AI stack (notebooks, agent frameworks, model loaders, inference and MLOps servers). Here model files, metadata and LLM output are effectively code, and services often ship unauthenticated.
## How it works
The AI stack keeps reintroducing classic Python sinks through new inputs:
- **Model artifacts as code**: pickle-based checkpoints, and config or metadata that names callables (Hydra `_target_`) or carries templates (GGUF `chat_template`).
- **LLM output as code or data structure**: generated Python that gets `exec`'d, and generated dicts deserialized as trusted framework objects.
- **Fetch-anything features**: webhooks, URL inputs and RAG loaders become [[Server-Side Request Forgery|SSRF]] sinks.
- **Dev-tool defaults in production**: unauthenticated WebSockets and actor ports, and Starlette-based servers exposed without a strict proxy.
## Patterns and cases
| Pattern | Case | Detail |
|---|---|---|
| Missing auth on a privileged endpoint | **Marimo CVE-2026-39987** (CVSS 9.3, CISA KEV) | `/terminal/ws` skipped `validate_auth()`, unlike `/ws`, giving a pre-auth PTY shell. Exploited within 10 hours of disclosure (credential harvesting, NKAbuse). Affects ≤ 0.20.4; fixed in 0.23.0 |
| Authz on reconstructed path | **Starlette BadHost CVE-2026-48710** | `Host: x?` desyncs `request.url.path` from the routed path. Hits FastAPI, vLLM, LiteLLM and MCP servers. See [[Python Web Framework Security]] |
| Config names a callable | **NeMo CVE-2025-23304, Uni2TS CVE-2026-22584, FlexTok** | `hydra.utils.instantiate()` calls any callable in `_target_` from model metadata, even alongside safetensors weights |
| Template in model file | **SGLang CVE-2026-5760** (9.8) | Jinja2 SSTI via GGUF `tokenizer.chat_template` on `/v1/rerank`. Same pattern as llama-cpp-python CVE-2024-34359. See [[Jinja2 SSTI]] |
| Template in data reference | **fsspec CVE-2026-104851** | Un-sandboxed Jinja2 in `ReferenceFileSystem` references JSON (`xarray.open_dataset("reference://...")`) |
| Template in a packaged artifact | **BentoML** GHSA-v959-cwq9-7hr6 | `bentoml containerize` rendered the imported archive's `Dockerfile.template` in an unsandboxed Jinja2 `Environment` with `jinja2.ext.do`/`debug`, running code on the host before Docker. Fix: `SandboxedEnvironment` [[raw/github.com/bentoml-ssti-via-unsandboxed-jinja2-in-dockerfile-generation-15849\|GHSA]] |
| LLM output executed | **Langflow CVE-2026-33873** | The Agentic Assistant `exec`'d generated code during validation (fixed in 1.9.0) |
| LLM output deserialized | **LangChain Core CVE-2025-68664** (9.3) | `dumps()`/`dumpd()` didn't escape user dicts containing the internal `"lc"` key, so they were revived as trusted objects, leading to secret extraction. The JS equivalent is CVE-2025-68665 |
| Format-string templates | **Arize Phoenix** (CVE-2026-53998; 13.0.0 up to but not including 15.7.0) | `str.format` attribute traversal in `applyChatTemplate` leaked `PHOENIX_SECRET`, leading to JWT forgery. See [[Unsafe Python Functions]] |
| Sandbox fallback | **CrewAI CVE-2026-2275/2287** | The Code Interpreter falls back to in-process `SandboxPython` when Docker is unavailable. See [[Python Sandbox Escapes]] |
| Full-read SSRF | **MLflow CVE-2026-64849** (9.3, KEV) | Webhook delivery 3.3.0–3.15.0 is unauthenticated and follows redirects, and is exposed to DNS rebinding |
| SSRF via typed inputs | **Replicate Cog** ≤ 0.23.1 | `cog.File`/`cog.Path` prediction inputs fetch attacker URLs and follow redirects |
| SSRF in RAG tools | **CrewAI CVE-2026-2286** | RAG search tools don't validate runtime URLs. The JSON loader (CVE-2026-2285) reads arbitrary files |
| Unauthenticated deserialization port | **Xoscar** ≤ 0.11.2 | Actor-pool messages deserialized before auth. Fixed in 0.12.0 with a shared `XOSCAR_AUTH_KEY` |
| Pickle checkpoints and scanners | MLflow, Ultralytics, Qlib, Detectron2, fairseq, Megatron-LM (ZDI-26-8xx/9xx); Qiskit QPY CVE-2026-116499; picklescan CVE-2025-1716 (`pip.main` not on the denylist); Fickling CVE-2026-22607 | Covered in [[Python Pickle Deserialization]] |
| Startup hook in an SDK release | **Microsoft agent-framework** 1.26.1/1.26.2 (PYSEC-2026-4388) | `.pth` stealer on every interpreter start; targets Azure, CI and AI-provider credentials near agent code [[raw/medium.com/the-credential-was-valid-the-publisher-was-not-15854\|VeritasChain]] |
## Defenses
- Authenticate *every* endpoint, including WebSockets and inter-process ports. Don't expose notebook, MLOps or inference servers directly.
- Load weights only (safetensors, `torch.load(weights_only=True)`). Allowlist `_target_` modules and render model-supplied templates with `ImmutableSandboxedEnvironment`.
- Never `exec` LLM output in-process, and treat LLM-produced structures as untrusted input to any (de)serializer.
- For LLM apps, decide in code which tools an intent may use, validate every model-produced argument with pydantic, hold destructive calls for approval, and check output before rendering. See [[Prompt Injection]] [[raw/karthikupadrasta.medium.com/how-to-prevent-prompt-injection-in-python-llm-apps-6-layers-that-actua-15852|six layers]].
- SSRF guards must pin the resolved IP and re-check on every redirect hop. See [[SSRF Prevention]] and [[DNS Rebinding]].
- Don't rely on pickle scanners (picklescan, Fickling) as a security boundary. Both have had denylist and classification bypasses.
## Related
- [[Python Security]]
- [[Unsafe Python Functions]]
- [[Python Sandbox Escapes]]
- [[Python Web Framework Security]]
- [[Python Pickle Deserialization]]
- [[AI and LLM Security]]
- [[MCP Security]]
- [[Agentic AI Risks]]
- [[Prompt Injection]]
- [[Webhook SSRF]]
- [[Malicious Packages]]
## Sources
- [[raw/thehackernews.com/marimo-rce-flaw-cve-2026-39987-exploited-within-10-hours-of-disclosure-4813|Marimo RCE Flaw CVE-2026-39987 Exploited Within 10 Hours]]
- [[raw/csoonline.com/critical-flaw-in-marimo-python-notebook-exploited-within-10-hours-of-d-5211|Critical flaw in Marimo Python notebook exploited]]
- [[raw/korben.info/badhost-one-character-and-your-ai-agent-switches-sides-9901|BadHost: one character and your AI agent switches sides]]
- [[raw/unit42.paloaltonetworks.com/rce-with-modern-ai-ml-formats-and-python-libraries-3396|RCE With Modern AI/ML Formats and Python Libraries]]
- [[raw/thehackernews.com/sglang-cve-2026-5760-cvss-9-8-enables-rce-via-malicious-gguf-model-fil-4812|SGLang CVE-2026-5760 RCE via malicious GGUF]]
- [[raw/advisories.gitlab.com/fsspec-referencefilesystem-ssti-leads-to-rce-cve-2026-104851-12784|fsspec ReferenceFileSystem SSTI leads to RCE]]
- [[raw/sentinelone.com/cve-2026-33873-langflow-agentic-assistant-rce-vulnerability-2981|CVE-2026-33873: Langflow Agentic Assistant RCE]]
- [[raw/socradar.io/cve-2025-68664-critical-langchain-flaw-enables-secret-extraction-4808|CVE-2025-68664: LangChain secret extraction]]
- [[raw/github.com/arize-phoenix-format-string-injection-in-applychattemplate-graphql-que-14497|Arize Phoenix: format string injection]]
- [[raw/kb.cert.org/crewai-contains-multiple-vulnerabilities-including-ssrf-rce-2963|CrewAI contains multiple vulnerabilities]]
- [[raw/patchnext.com/mlflow-unauthenticated-full-read-ssrf-in-webhook-delivery-12765|MLflow unauthenticated full-read SSRF in webhook delivery]]
- [[raw/github.com/replicate-cog-through-0-23-1-ssrf-13893|Replicate Cog through 0.23.1 SSRF]]
- [[raw/github.com/xoscar-unauthenticated-rce-through-actor-message-deserialization-12478|Xoscar unauthenticated RCE through actor message deserialization]]
- [[raw/sonatype.com/cve-2025-1716-sonatype-security-advisory-3384|CVE-2025-1716 picklescan bypass]]
- [[raw/sentinelone.com/cve-2026-22607-fickling-python-rce-vulnerability-4810|CVE-2026-22607: Fickling]]
- [[raw/ibm.com/ibm-arbitrary-code-execution-in-qiskit-sdk-qpy-deserialization-13580|Qiskit SDK QPY deserialization]]
- [[raw/stackurity.ai/arize-phoenix-cve-2026-53998-graphql-format-string-secrets-leak-15629|Arize Phoenix CVE-2026-53998 GraphQL format-string secrets leak]]
- [[raw/github.com/bentoml-ssti-via-unsandboxed-jinja2-in-dockerfile-generation-15849|BentoML GHSA-v959-cwq9-7hr6: SSTI via unsandboxed Jinja2]]
- [[raw/medium.com/the-credential-was-valid-the-publisher-was-not-15854|The Credential Was Valid. The Publisher Was Not. (agent-framework)]]
- [[raw/karthikupadrasta.medium.com/how-to-prevent-prompt-injection-in-python-llm-apps-6-layers-that-actua-15852|How to Prevent Prompt Injection in Python LLM Apps: 6 Layers]]