Critical Flaws: Hugging Face Diffusers' Custom Code Safeguards Bypassed by Malicious Models

Vabandame, selle lehekülje sisu ei ole teie valitud keeles saadaval

Introduction to the Vulnerability Landscape

Preview image for a blog post

Hugging Face has emerged as a cornerstone in the machine learning ecosystem, providing a vast repository of models, datasets, and the popular Diffusers library for generative AI applications. Its accessibility and collaborative nature, however, introduce inherent security challenges. Recently, a critical discovery revealed that three distinct CVEs in the Hugging Face Diffusers library permit malicious model repositories to execute arbitrary code on any machine that loads them, fundamentally bypassing intended custom code safeguards. This represents a significant supply chain vulnerability, turning seemingly benign model downloads into potential vectors for remote code execution (RCE).

Understanding Hugging Face Diffusers and the Security Model

The Power of Custom Models

The flexibility of the Diffusers library allows developers to extend its functionality by integrating custom code directly into models or their configurations. This capability, while powerful for innovation, also broadens the attack surface. To mitigate risks associated with arbitrary code execution, Hugging Face introduced mechanisms like the allow_unsafe_code parameter and encouraged the use of the safetensors format. The safetensors format was specifically designed as a secure alternative to PyTorch's default pickle-based serialization, which is notoriously prone to insecure deserialization vulnerabilities.

The Illusion of Safety

The premise was that by setting allow_unsafe_code=False or exclusively using models in the safetensors format, users could prevent malicious code from executing. However, the discovered CVEs demonstrate that this security model was not as robust as anticipated. These vulnerabilities exploit specific code paths and loading mechanisms within the Diffusers library that, under certain conditions, can be manipulated by a malicious model to deserialize and execute arbitrary Python objects, even when explicit safeguards are presumed to be active.

Technical Deep Dive: Exploit Primitives and CVEs

Insecure Deserialization Revisited

At the heart of many software vulnerabilities lies insecure deserialization. While safetensors was intended to eliminate the risks associated with Python's pickle module (where torch.load with allow_pickle=True can lead to RCE), the identified CVEs reveal that fallback mechanisms, alternative loading functions, or improper validation of metadata can reintroduce these dangers. The vulnerabilities allow a threat actor to craft a model repository where seemingly innocuous configuration files or components, when processed by the Diffusers library, trigger the execution of malicious Python code.

Exploiting Model Metadata and Loaders

The three CVEs leverage distinct vectors, often involving the manipulation of metadata or specific internal loading functions:

The attack chain typically involves a user downloading and loading a model from a compromised or malicious Hugging Face repository. Upon loading, the crafted data within the model or its associated configuration files triggers the RCE, granting the attacker control over the user's machine. The impact can range from data exfiltration and system compromise to the establishment of persistent backdoors.

Attack Vectors and Real-World Implications

Mitigating the Risk: Defensive Strategies

Addressing these vulnerabilities requires a multi-layered security approach:

Digital Forensics and Threat Actor Attribution

In the unfortunate event of a compromise, robust digital forensics is paramount. Investigators must quickly identify the extent of the breach, the specific exploit vector, and potential threat actor attribution. This involves meticulous log analysis, endpoint detection and response (EDR) telemetry, and network reconnaissance.

During an investigation into a suspected malicious model or a compromised system, researchers often need to understand the attacker's infrastructure. Tools like iplogger.org can be invaluable for collecting advanced telemetry – including IP addresses, User-Agents, ISPs, and device fingerprints – when analyzing suspicious links found in attacker communications or during network reconnaissance. This data aids in link analysis, mapping attacker networks, and ultimately, threat actor attribution, providing crucial insights into the source of a cyber attack.

Conclusion

The discovery of these CVEs in Hugging Face Diffusers serves as a stark reminder of the persistent security challenges within the rapidly evolving AI/ML landscape. As AI models become more complex and their use more widespread, the attack surface expands. Organizations and individual researchers must remain vigilant, adopting proactive security measures and fostering a culture of security consciousness to safeguard against sophisticated supply chain attacks and ensure the integrity of their AI workflows.

X
Küpsiseid kasutatakse [saidi] korrektseks toimimiseks. Kasutades saidi teenuseid, nõustute selle asjaoluga. Oleme avaldanud uue küpsiste poliitika, saate seda lugeda, et saada rohkem teavet selle kohta, kuidas me küpsiseid kasutame.