CVE-2025-12058: Vulnerability in Keras Model.load_model Leading to Arbitrary Local File Loading and SSRF
The Keras.Model.loadmodel method, including when executed with the intended security mitigation safemode=True, is vulnerable to arbitrary local file loading and Server-Side Request Forgery (SSRF).
This vulnerability stems from the way the StringLookup layer is handled during model loading from a specially crafted .keras archive. The constructor for the StringLookup layer accepts a vocabulary argument that can specify a local file path or a remote file path.
Arbitrary Local File Read: An attacker can create a malicious .keras file that embeds a local path in the StringLookup layer's configuration. When the model is loaded, Keras will attempt to read the content of the specified local file and incorporate it into the model state (e.g., retrievable via getvocabulary()), allowing an attacker to read arbitrary local files on the hosting system.
Server-Side Request Forgery (SSRF): Keras utilizes tf.io.gfile for file operations. Since tf.io.gfile supports remote filesystem handlers (such as GCS and HDFS) and HTTP/HTTPS protocols, the same mechanism can be leveraged to fetch content from arbitrary network endpoints on the server's behalf, resulting in an SSRF condition.
The security issue is that the feature allowing external path loading was not properly restricted by the safemode=True flag, which was intended to prevent such unintended data access.
Other sources
Vulnerability in Keras Model.loadmodel Leading to Arbitrary Local File Loading and SSRF
— Microsoft
Affected Software
Event History
Frequently Asked Questions
What is the severity of CVE-2025-12058?
CVE-2025-12058 is classified as a high severity vulnerability due to its potential for arbitrary local file loading and Server-Side Request Forgery.
How do I fix CVE-2025-12058?
To mitigate CVE-2025-12058, ensure you update to the latest version of Keras where this vulnerability has been addressed.
What is affected by CVE-2025-12058?
CVE-2025-12058 affects the Keras.Model.load_model method, specifically when the StringLookup layer is involved.
Can CVE-2025-12058 lead to data leakage?
Yes, CVE-2025-12058 can lead to data leakage because it allows arbitrary file access on the server.
Is safe_mode=True sufficient to mitigate CVE-2025-12058?
No, even with safe_mode=True, CVE-2025-12058 remains vulnerable, so an update or further mitigation is necessary.