Update dependency keras to v3.11.3 [SECURITY] #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Coming soon: The Renovate bot (GitHub App) will be renamed to Mend. PRs from Renovate will soon appear from 'Mend'. Learn more here.
This PR contains the following updates:
==3.3.2
->==3.11.3
Warning
Some dependencies could not be looked up. Check the Dependency Dashboard for more information.
GitHub Vulnerability Alerts
CVE-2025-1550
Impact
The Keras
Model.load_model
function permits arbitrary code execution, even withsafe_mode=True
, through a manually constructed, malicious.keras
archive. By altering theconfig.json
file within the archive, an attacker can specify arbitrary Python modules and functions, along with their arguments, to be loaded and executed during model loading.Patches
This problem is fixed starting with version
3.9
.Workarounds
Only load models from trusted sources and model archives created with Keras.
References
CVE-2025-8747
Summary
It is possible to bypass the mitigation introduced in response to CVE-2025-1550, when an untrusted Keras v3 model is loaded, even when “safe_mode” is enabled, by crafting malicious arguments to built-in Keras modules.
The vulnerability is exploitable on the default configuration and does not depend on user input (just requires an untrusted model to be loaded).
Impact
Details
Keras’ safe_mode flag is designed to disallow unsafe lambda deserialization - specifically by rejecting any arbitrary embedded Python code, marked by the “lambda” class name.
https://github.com/keras-team/keras/blob/v3.8.0/keras/src/saving/serialization_lib.py#L641 -
A fix to the vulnerability, allowing deserialization of the object only from internal Keras modules, was introduced in the commit bb340d6780fdd6e115f2f4f78d8dbe374971c930.
However, it is still possible to exploit model loading, for example by reusing the internal Keras function
keras.utils.get_file
, and download remote files to an attacker-controlled location.This allows for arbitrary file overwrite which in many cases could also lead to remote code execution. For example, an attacker would be able to download a malicious
authorized_keys
file into the user’s SSH folder, giving the attacker full SSH access to the victim’s machine.Since the model does not contain arbitrary Python code, this scenario will not be blocked by “safe_mode”. It will bypass the latest fix since it uses a function from one of the approved modules (
keras
).Example
The following truncated
config.json
will cause a remote file download from https://raw.githubusercontent.com/andr3colonel/when_you_watch_computer/refs/heads/master/index.js to the local/tmp
folder, by sending arbitrary arguments to Keras’ builtin functionkeras.utils.get_file()
-PoC
Download malicious_model_download.keras to a local directory
Load the model -
index.js
was created in the/tmp
directoryFix suggestions
block_all_lambda
that allows users to completely disallow loading models with a Lambda layer.keras
,keras_hub
,keras_cv
,keras_nlp
modules and remove/block all “gadget functions” which could be used by malicious ML models.lambda_whitelist_functions
that allows users to specify a list of functions that are allowed to be invoked by a Lambda layerCredit
The vulnerability was discovered by Andrey Polkovnichenko of the JFrog Vulnerability Research
CVE-2025-9906
Arbitrary Code Execution in Keras
Keras versions prior to 3.11.0 allow for arbitrary code execution when loading a crafted
.keras
model archive, even whensafe_mode=True
.The issue arises because the archive’s
config.json
is parsed before layer deserialization. This can invokekeras.config.enable_unsafe_deserialization()
, effectively disabling safe mode from within the loading process itself. An attacker can place this call first in the archive and then include aLambda
layer whose function is deserialized from a pickle, leading to the execution of attacker-controlled Python code as soon as a victim loads the model file.Exploitation requires a user to open an untrusted model; no additional privileges are needed. The fix in version 3.11.0 enforces safe-mode semantics before reading any user-controlled configuration and prevents the toggling of unsafe deserialization via the config file.
Affected versions: < 3.11.0
Patched version: 3.11.0
It is recommended to upgrade to version 3.11.0 or later and to avoid opening untrusted model files.
CVE-2025-9905
Note: This report has already been discussed with the Google OSS VRP team, who recommended that I reach out directly to the Keras team. I’ve chosen to do so privately rather than opening a public issue, due to the potential security implications. I also attempted to use the email address listed in your
SECURITY.md
, but received no response.Summary
When a model in the
.h5
(or.hdf5
) format is loaded using the KerasModel.load_model
method, thesafe_mode=True
setting is silently ignored without any warning or error. This allows an attacker to execute arbitrary code on the victim’s machine with the same privileges as the Keras application. This report is specific to the.h5
/.hdf5
file format. The attack works regardless of the other parameters passed toload_model
and does not require any sophisticated technique—.h5
and.hdf5
files are simply not checked for unsafe code execution.From this point on, I will refer only to the
.h5
file format, though everything equally applies to.hdf5
.Details
Intended behaviour
According to the official Keras documentation,
safe_mode
is defined as:I understand that the behavior described in this report is somehow intentional, as
safe_mode
is only applicable to.keras
models.However, in practice, this behavior is misleading for users who are unaware of the internal Keras implementation.
.h5
files can still be loaded seamlessly usingload_model
withsafe_mode=True
, and the absence of any warning or error creates a false sense of security. Whether intended or not, I believe silently ignoring a security-related parameter is not the best possible design decision. At a minimum, ifsafe_mode
cannot be applied to a given file format, an explicit error should be raised to alert the user.This issue is particularly critical given the widespread use of the
.h5
format, despite the introduction of newer formats.As a small anecdotal test, I asked several of my colleagues what they would expect when loading a
.h5
file withsafe_mode=True
. None of them expected the setting to be silently ignored, even after reading the documentation. While this is a small sample, all of these colleagues are cybersecurity researchers—experts in binary or ML security—and regular participants in DEF CON finals. I was careful not to give any hints about the vulnerability in our discussion.Technical Details
Examining the implementation of
load_model
inkeras/src/saving/saving_api.py
, we can see that thesafe_mode
parameter is completely ignored when loading.h5
files. Here's the relevant snippet:As shown, when the file format is
.h5
or.hdf5
, the method delegates tolegacy_h5_format.load_model_from_hdf5
, which does not use or check thesafe_mode
parameter at all.Solution
Since the release of the new
.keras
format, I believe the simplest and most effective way to address this misleading behavior—and to improve security in Keras—is to have thesafe_mode
parameter raise an explicit error whensafe_mode=True
is used with.h5
/.hdf5
files. This error should be clear and informative, explaining that the legacy format does not supportsafe_mode
and outlining the associated risks of loading such files.I recognize this fix may have minor backward compatibility considerations.
If you confirm that you're open to this approach, I’d be happy to open a PR that includes the missing check.
PoC
From the attacker’s perspective, creating a malicious
.h5
model is as simple as the following:From the victim’s side, triggering code execution is just as simple:
That’s all. The exploit occurs during model loading, with no further interaction required. The parameters passed to the method do not mitigate of influence the attack in any way.
As expected, the attacker can substitute the
exec(...)
call with any payload. Whatever command is used will execute with the same permissions as the Keras application.Attack scenario
The attacker may distribute a malicious
.h5
/.hdf5
model on platforms such as Hugging Face, or act as a malicious node in a federated learning environment. The victim only needs to load the model—even withsafe_mode=True
that would give the illusion of security. No inference or further action is required, making the threat particularly stealthy and dangerous.Once the model is loaded, the attacker gains the ability to execute arbitrary code on the victim’s machine with the same privileges as the Keras process. The provided proof-of-concept demonstrates a simple shell spawn, but any payload could be delivered this way.
Release Notes
keras-team/keras (keras)
v3.11.3
: Keras 3.11.3Compare Source
What's Changed
Full Changelog: keras-team/keras@v3.11.2...v3.11.3
v3.11.2
: Keras 3.11.2Compare Source
What's Changed
New Contributors
Full Changelog: keras-team/keras@v3.11.1...v3.11.2
v3.11.1
: Keras 3.11.1Compare Source
What's Changed
Full Changelog: keras-team/keras@v3.11.0...v3.11.1
v3.11.0
: Keras 3.11.0Compare Source
What's Changed
fit()
/evaluate()
/predict()
.keras.ops.kaiser
function.keras.ops.hanning
function.keras.ops.cbrt
function.keras.ops.deg2rad
function.keras.ops.layer_normalization
function to leverage backend-specific performance optimizations.Backend-specific changes
JAX backend
TensorFlow backend
Flatten
layer.OpenVINO backend
New Contributors
Full Changelog: keras-team/keras@v3.10.0...v3.11.0
v3.10.0
: Keras 3.10.0Compare Source
New features
model.save()
. It is controlled via themax_shard_size
argument. Specifying this argument will split your Keras model weight file into chunks of this size at most. Useload_model()
to reload the sharded files.keras.optimizers.Muon
keras.layers.RandomElasticTransform
keras.losses.CategoricalGeneralizedCrossEntropy
(with functional versionkeras.losses.categorical_generalized_cross_entropy
)axis
argument toSparseCategoricalCrossentropy
lora_alpha
to all LoRA-enabled layers. If set, this parameter scales the low-rank adaptation delta during the forward pass.keras.activations.sparse_sigmoid
keras.ops.image.elastic_transform
keras.ops.angle
keras.ops.bartlett
keras.ops.blackman
keras.ops.hamming
keras.ops.view_as_complex
,keras.ops.view_as_real
PyTorch backend
TensorFlow backend
tf.RaggedTensor
support toEmbedding
layersynchronization
argumentOpenVINO backend
New Contributors
Full Changelog: keras-team/keras@v3.9.0...v3.10.0
v3.9.2
: Keras 3.9.2Compare Source
What's Changed
Full Changelog: keras-team/keras@v3.9.1...v3.9.2
v3.9.1
: Keras 3.9.1Compare Source
What's Changed
Full Changelog: keras-team/keras@v3.9.0...v3.9.1
v3.9.0
: Keras 3.9.0Compare Source
New features
keras.RematScope
andkeras.remat
. It can be used to turn on rematerizaliation for certain layers in fine-grained manner, e.g. only for layers larger than a certain size, or for a specific set of layers, or only for activations.keras.ops.rot90
keras.ops.rearrange
(Einops-style)keras.ops.signbit
keras.ops.polar
keras.ops.image.perspective_transform
keras.ops.image.gaussian_blur
keras.layers.RMSNormalization
keras.layers.AugMix
keras.layers.CutMix
keras.layers.RandomInvert
keras.layers.RandomErasing
keras.layers.RandomGaussianBlur
keras.layers.RandomPerspective
dtype
argument toJaxLayer
andFlaxLayer
layersBinaryAccuracy
metricantialias
argument tokeras.layers.Resizing
layer.npz
model files (numpy format). Thanks to Peng Zhou for reporting the vulnerability.New Contributors
Full Changelog: keras-team/keras@v3.8.0...v3.9.0
v3.8.0
: Keras 3.8.0Compare Source
New: OpenVINO backend
OpenVINO is now available as an infererence-only Keras backend. You can start using it by setting the
backend
field to"openvino"
in yourkeras.json
config file.OpenVINO is a deep learning inference-only framework tailored for CPU (x86, ARM), certain GPUs (OpenCL capable, integrated and discrete) and certain AI accelerators (Intel NPU).
Because OpenVINO does not support gradients, you cannot use it for training (e.g.
model.fit()
) -- only inference. You can train your models with the JAX/TensorFlow/PyTorch backends, and when trained, reload them with the OpenVINO backend for inference on a target device supported by OpenVINO.New: ONNX model export
You can now export your Keras models to the ONNX format from the JAX, TensorFlow, and PyTorch backends.
Just pass
format="onnx"
in yourmodel.export()
call:New: Scikit-Learn API compatibility interface
It's now possible to easily integrate Keras models into Sciki-Learn pipelines! The following wrapper classes are available:
keras.wrappers.SKLearnClassifier
: implements the sklearnClassifier
APIkeras.wrappers.SKLearnRegressor
: implements the sklearnRegressor
APIkeras.wrappers.SKLearnTransformer
: implements the sklearnTransformer
APIOther feature additions
keras.ops.diagflat
keras.ops.unravel_index
sparse_plus
activationsparsemax
activationkeras.layers.RandAugment
keras.layers.Equalization
keras.layers.MixUp
keras.layers.RandomHue
keras.layers.RandomGrayscale
keras.layers.RandomSaturation
keras.layers.RandomColorJitter
keras.layers.RandomColorDegeneration
keras.layers.RandomSharpness
keras.layers.RandomShear
axis
totversky
lossJAX specific changes
TensorFlow specific changes
keras.random.shuffle
XLA compilablePyTorch specific changes
model.export()
andkeras.export.ExportArchive
with the PyTorch backend, supporting both the TF SavedModel format and the ONNX format.New Contributors
Full Changelog: keras-team/keras@v3.7.0...v3.8.0
v3.7.0
: Keras 3.7.0Compare Source
API changes
flash_attention
argument tokeras.ops.dot_product_attention
and tokeras.layers.MultiHeadAttention
.keras.layers.STFTSpectrogram
layer (to extract STFT spectrograms from inputs as a preprocessing step) as well as its initializerkeras.initializers.STFTInitializer
.celu
,glu
,log_sigmoid
,hard_tanh
,hard_shrink
,squareplus
activations.keras.losses.Circle
loss.keras.visualization.draw_bounding_boxes
,keras.visualization.draw_segmentation_masks
,keras.visualization.plot_image_gallery
,keras.visualization.plot_segmentation_mask_gallery
.double_checkpoint
argument toBackupAndRestore
to save a fallback checkpoint in case the first checkpoint gets corrupted.CenterCrop
,RandomFlip
,RandomZoom
,RandomTranslation
,RandomCrop
.keras.ops.exp2
,keras.ops.inner
operations.Performance improvements
bias_add
.New Contributors
Full Changelog: keras-team/keras@v3.6.0...v3.7.0
v3.6.0
: Keras 3.6.0Compare Source
Highlights
keras.saving.KerasFileEditor
. Use it to inspect, diff, modify and resave Keras weights files. See basic workflow here.keras.utils.Config
class for managing experiment config parameters.BREAKING changes
keras.utils.get_file
, withextract=True
oruntar=True
, the return value will be the path of the extracted directory, rather than the path of the archive.Other changes and additions
fit()
,evaluate()
,predict()
. This enables 100% compact stacking oftrain_step
calls on accelerators (e.g. when running small models on TPU).on_batch_end
, this will disable async logging. You can force it back by addingself.async_safe = True
to your callbacks. Note that theTensorBoard
callback isn't considered async safe by default. Default callbacks like the progress bar are async safe.keras.saving.KerasFileEditor
utility to inspect, diff, modify and resave Keras weights file.keras.utils.Config
class. It behaves like a dictionary, with a few nice features:config.foo = 2
orconfig["foo"]
are both valid)config.to_json()
.config.freeze()
.bitwise_and
bitwise_invert
bitwise_left_shift
bitwise_not
bitwise_or
bitwise_right_shift
bitwise_xor
keras.ops.logdet
.keras.ops.trunc
.keras.ops.dot_product_attention
.keras.ops.histogram
.PyDataset
instances to use multithreading.verbose
inkeras.saving.ExportArchive.write_out()
method for exporting TF SavedModel.epsilon
argument inkeras.ops.normalize
.Model.get_state_tree()
method for retrieving a nested dict mapping variable paths to variable values (either as numpy arrays or backend tensors (default)). This is useful for rolling out custom JAX training loops.keras.layers.AutoContrast
,keras.layers.Solarization
.keras.layers.Pipeline
class, to apply a sequence of layers to an input. This class is useful to build a preprocessing pipeline. Compared to aSequential
model,Pipeline
features a few important differences:Model
, just a plain layer.tf.data
, the pipeline will also remaintf.data
compatible, independently of the backend you use.New Contributors
Full Changelog: keras-team/keras@v3.5.0...v3.6.0
v3.5.0
: Keras 3.5.0Compare Source
What's Changed
keras.Model.save()
and load.keras
models directly from Hugging Face Hub withkeras.saving.load_model()
.keras.optimizers.Lamb
optimizer.keras.distribution
API support for very large models.keras.ops.associative_scan
op.keras.ops.searchsorted
op.keras.utils.PyDataset.on_epoch_begin()
method.data_format
argument tokeras.layers.ZeroPadding1D
layer.Full Changelog: keras-team/keras@v3.4.1...v3.5.0
v3.4.1
: Keras 3.4.1Compare Source
This is a minor bugfix release.
v3.4.0
: Keras 3.4.0Compare Source
Highlights
keras.dtype_policies.DTypePolicyMap
for easy configuration of dtype policies of nested sublayers of a subclassed layer/model.keras.ops.argpartition
keras.ops.scan
keras.ops.lstsq
keras.ops.switch
keras.ops.dtype
keras.ops.map
keras.ops.image.rgb_to_hsv
keras.ops.image.hsv_to_rgb
What's changed
float8
inference forDense
andEinsumDense
layers.name
argument in all Keras Applications models.axis
argument inkeras.losses.Dice
.keras.utils.FeatureSpace
to be used in atf.data
pipeline even when the backend isn't TensorFlow.StringLookup
layer can now taketf.SparseTensor
as input.Metric.variables
is now recursive.training
argument toModel.compute_loss()
.dtype
argument to all losses.keras.utils.split_dataset
now supports nested structures in dataset.Full Changelog: keras-team/keras@v3.3.3...v3.4.0
v3.3.3
: Keras 3.3.3Compare Source
This is a minor bugfix release.
Configuration
📅 Schedule: Branch creation - "" (UTC), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.