Skip to content

Detect nested Keras Lambda layers#351

Open
dfgvaetyj3456356-hash wants to merge 1 commit into
protectai:mainfrom
dfgvaetyj3456356-hash:security/detect-nested-keras-lambda
Open

Detect nested Keras Lambda layers#351
dfgvaetyj3456356-hash wants to merge 1 commit into
protectai:mainfrom
dfgvaetyj3456356-hash:security/detect-nested-keras-lambda

Conversation

@dfgvaetyj3456356-hash

Copy link
Copy Markdown

Summary

  • Recursively traverse Keras model config trees when looking for Lambda layers.
  • Reuse the same traversal for .keras and H5 Keras configs.
  • Add dependency-light regression coverage for nested Lambda detection, including an in-memory .keras archive scanner path.

Why

The current Keras Lambda checks only inspect the first-level config.layers array. Keras model configs can contain nested model/layer configs, so a nested Lambda layer can be missed by ModelScan even though top-level Lambda layers are reported.

This is related to #340's nested config work, but narrower: #340 focuses on unsafe module references and preserves the existing top-level Lambda check. This PR specifically makes Lambda detection recursive and applies the same helper to H5 config parsing.

Testing

  • python -m pytest tests\test_keras_nested_lambda_scan.py -q
  • python -m compileall modelscan\scanners\keras_utils.py modelscan\scanners\keras\scan.py modelscan\scanners\h5\scan.py tests\test_keras_nested_lambda_scan.py

I could not run the broader ests/test_modelscan.py targets locally because the checkout is missing optional test dependencies such as dill and TensorFlow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant