The vulnerability, identified as CVE-2025-12060, is a path traversal weakness in Keras's file extraction functionality. The root cause is the unsafe use of Python's tarfile.extractall function, which is known to be vulnerable to path traversal if not used with proper filters (related to CVE-2007-4559). When a user calls keras.utils.get_file with extract=True on a malicious tar archive, the underlying code can write files outside of the target extraction directory.
The analysis of the fixing commit 47fcb397ee4caffd5a75efd1fa3067559594e951 reveals two vulnerable functions that were patched:
-
_ArchiveReader.__init__ in keras/src/saving/saving_lib.py: This function performed a direct, unfiltered call to self.archive.extractall(), representing a direct path to exploitation.
-
extract_archive in keras/src/utils/file_utils.py: This function used a custom but flawed filter (filter_safe_paths) before extraction. This indicates an attempt at security that was ultimately insufficient to prevent the attack.
The patch addresses the vulnerability by introducing a new, secure function extract_open_archive. This function centralizes extraction logic and incorporates the modern filter="data" parameter for tarfile.extractall on compatible Python versions (3.12+), which is the recommended mitigation. For older versions, it uses a more robust custom filter. Both of the originally vulnerable functions were refactored to use this new secure utility. Therefore, during exploitation on a vulnerable version, a runtime profile would show either _ArchiveReader.__init__ or extract_archive as the function that triggers the insecure file extraction.