Handle invalid YAML timestamps during scan#970
Open
KairosOps wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #584.
PyYAML raises a plain
ValueErrorwhile constructing some malformed timestamps, for example0000-01-01. The YAML transformer only convertedyaml.YAMLErrorintoParsingError, so that constructor failure could escape the transformer and crashdetect-secrets scan --all-filesinstead of falling back to the normal line scanner.This treats that parse-time
ValueErrorthe same way as other YAML parsing failures. The transformer now raisesParsingError,get_transformed_file()ignores the failed structured transform, and scanning can continue over the raw file contents.Checked:
python -m py_compile detect_secrets\transformers\yaml.py tests\transformers\yaml_transformer_test.py tests\core\scan_test.pypython -m pytest tests\transformers\yaml_transformer_test.py tests\core\scan_test.py -qpython -m flake8 --select=E9,F63,F7,F82 detect_secrets\transformers\yaml.py tests\transformers\yaml_transformer_test.py tests\core\scan_test.pygit diff --checkI also tried a wider nearby test set including
tests/core/secrets_collection_test.py; that surfaced an unrelated existing assertion wheretest_data/config.mdproduced no detected secrets in this local environment. Full-file flake8 also reports many pre-existing E501 line-length violations in these files, so I kept the lint check scoped to syntax/undefined-name failures for this small patch.