-
Notifications
You must be signed in to change notification settings - Fork 466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add audit baseline functionality #44
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3783eaf
--audit v1
228b881
Merge branch 'master' of github.com:yelp/detect-secrets into add-audi…
c825e58
fixing shifted subset edge case
488e246
better UI
83a88f7
refactor plugins core logic
b192f99
refactor plugins for easier secret generation
467d92a
inline highlighting of secret
bf07ab5
handling case where auditing ini/yaml files
1140ae0
adding test cases
afe4725
s/break/continue
b77ceec
fixing tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
handling case where auditing ini/yaml files
- Loading branch information
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from collections import defaultdict | ||
|
||
from ..plugins.core import initialize | ||
from ..plugins.high_entropy_strings import HighEntropyStringsPlugin | ||
from .baseline import merge_results | ||
from .color import BashColor | ||
from .color import Color | ||
|
@@ -147,6 +148,7 @@ def _save_baseline_to_file(filename, data): # pragma: no cover | |
|
||
|
||
def _secret_generator(baseline): | ||
"""Generates secrets to audit, from the baseline""" | ||
current_secret_index = 1 | ||
num_secrets_to_parse = sum(map( | ||
lambda filename: len(list(filter( | ||
|
@@ -250,7 +252,7 @@ def _highlight_secret(secret_line, secret, filename, plugin_settings): | |
plugin_settings, | ||
) | ||
|
||
for raw_secret in plugin.secret_generator(secret_line): | ||
for raw_secret in _raw_secret_generator(plugin, secret_line): | ||
secret_obj = PotentialSecret( | ||
plugin.secret_type, | ||
filename, | ||
|
@@ -265,15 +267,6 @@ def _highlight_secret(secret_line, secret, filename, plugin_settings): | |
# We only want to highlight the right one. | ||
if secret_obj.secret_hash == secret['hashed_secret']: | ||
break | ||
else: | ||
# It hits here if the secret has been moved, from the original | ||
# line number listed in the baseline. | ||
raise SecretNotFoundOnSpecifiedLineError( | ||
textwrap.dedent(""" | ||
ERROR: Secret not found on specified line number! | ||
Try recreating your baseline to fix this issue. | ||
""")[1:-1], | ||
) | ||
|
||
index_of_secret = secret_line.index(raw_secret) | ||
return '{}{}{}'.format( | ||
|
@@ -286,6 +279,26 @@ def _highlight_secret(secret_line, secret, filename, plugin_settings): | |
) | ||
|
||
|
||
def _raw_secret_generator(plugin, secret_line): | ||
"""Generates raw secrets by re-scanning the line, with the specified plugin""" | ||
for raw_secret in plugin.secret_generator(secret_line): | ||
yield raw_secret | ||
|
||
if issubclass(plugin.__class__, HighEntropyStringsPlugin): | ||
with plugin.non_quoted_string_regex(strict=False): | ||
for raw_secret in plugin.secret_generator(secret_line): | ||
yield raw_secret | ||
|
||
# It hits here if the secret has been moved, from the original | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be more pythonic/you wouldn't need a comment (uncle bob 💯 ), if you did |
||
# line number listed in the baseline. | ||
raise SecretNotFoundOnSpecifiedLineError( | ||
textwrap.dedent(""" | ||
ERROR: Secret not found on specified line number! | ||
Try recreating your baseline to fix this issue. | ||
""")[1:-1], | ||
) | ||
|
||
|
||
def _get_user_decision(prompt_secret_decision=True): | ||
""" | ||
:type prompt_secret_decision: bool | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe add some comments and space it out so there isn't the
)))
. I initially misread it asmap
gets all the secrets that don't have anis_secret
attribute (i.e. the ones that have not been audited) and adds that number to the number of results in the baseline.