fix: Disable interpolation in config parser to prevent skipping files#963
Open
Mallikarjunadevops wants to merge 1 commit into
Open
fix: Disable interpolation in config parser to prevent skipping files#963Mallikarjunadevops wants to merge 1 commit into
Mallikarjunadevops wants to merge 1 commit into
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 #944
What is this PR?
This PR fixes a bug where
detect-secretsfails to detect secrets in configuration files (.cfg / .ini) when interpolation placeholders like%%(c)sare present before the secret.Why?
When parsing configuration files with Python's built-in
configparser.ConfigParser, the default setting performs BasicInterpolation. If the parser encounters a string that resembles interpolation syntax but cannot be interpolated, it raises an exception which leads toParsingError. This causesdetect-secretsto effectively skip the file content past the error, resulting in missed secrets.Since
detect-secretsonly needs to scan raw strings and shouldn't attempt to interpolate variables, initializingConfigParserwithinterpolation=Nonecompletely avoids this error and allows all keys and values to be extracted and scanned.Testing Evidence
Added a test to
tests/transformers/config_transformer_test.pyto verify that%%(c)sis correctly extracted without exceptions.Manually verified that secrets in
test.cfgfrom the issue report are now caught successfully.