Skip to content
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

adding is_lock_file filter #417

Merged
merged 2 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@
"filename": "docs/filters.md",
"hashed_secret": "4566d0493d8a9b7a811728e852ed5df95fa70dd2",
"is_verified": false,
"line_number": 55
"line_number": 56
}
]
},
"generated_at": "2021-02-25T19:11:59Z"
"generated_at": "2021-03-04T16:27:24Z"
}
13 changes: 13 additions & 0 deletions detect_secrets/filters/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,16 @@ def is_indirect_reference(secret: str) -> bool:
continue

return output


def is_lock_file(filename: str) -> bool:
return os.path.basename(filename) in {
'Brewfile.lock.json',
'Cartfile.resolved',
'composer.lock',
'Gemfile.lock',
'Package.resolved',
'package-lock.json',
'Podfile.lock',
'yarn.lock',
domanchi marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions detect_secrets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def clear(self) -> None:
'detect_secrets.filters.heuristic.is_templated_secret',
'detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign',
'detect_secrets.filters.heuristic.is_indirect_reference',
'detect_secrets.filters.heuristic.is_lock_file',
}
}

Expand Down
1 change: 1 addition & 0 deletions docs/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ the `detect_secrets.filters` namespace.
| `common.is_ignored_due_to_verification_policies` | Powers secret verification functionality. |
| `heuristic.is_indirect_reference` | Primarily for `KeywordDetector`, filters secrets like `secret = get_secret_key()`. |
| `heuristic.is_likely_id_string` | Ignores secret values prefixed with `id`. |
| `heuristic.is_lock_file` | Ignores common lock files. |
| `heuristic.is_non_text_file` | Ignores non-text files (e.g. archives, images). |
| `heuristic.is_potential_uuid` | Ignores uuid looking secret values. |
| `heuristic.is_prefixed_with_dollar_sign` | Primarily for `KeywordDetector`, filters secrets like `secret = $variableName;`. |
Expand Down
11 changes: 11 additions & 0 deletions tests/filters/heuristic_filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,14 @@ def test_is_indirect_reference(line, result):
}],
}):
assert bool(list(scan_line(line))) is result


def test_is_lock_file():
# Basic test
assert filters.heuristic.is_lock_file('composer.lock')

# file path
assert filters.heuristic.is_lock_file('path/yarn.lock')

# assert non-regex
assert not filters.heuristic.is_lock_file('Gemfilealock')