Skip to content

Commit

Permalink
Merge branch 'feature/adding-lock-file-filter'
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Loo committed Mar 6, 2021
2 parents 94bff18 + 4ce85ae commit a353363
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
"filename": "docs/filters.md",
"hashed_secret": "4566d0493d8a9b7a811728e852ed5df95fa70dd2",
"is_verified": false,
"line_number": 55
"line_number": 56
}
]
},
Expand Down
13 changes: 13 additions & 0 deletions detect_secrets/filters/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,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',
}
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')

0 comments on commit a353363

Please sign in to comment.