mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-31 02:36:52 +00:00
Find private keys within gzip-compresssed files
This commit is contained in:
parent
5c514f85cc
commit
e2c9870bc2
3 changed files with 27 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import gzip
|
||||
from collections.abc import Sequence
|
||||
|
||||
BLACKLIST = [
|
||||
|
|
@ -29,6 +30,16 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||
content = f.read()
|
||||
if any(line in content for line in BLACKLIST):
|
||||
private_key_files.append(filename)
|
||||
continue
|
||||
try:
|
||||
if filename.endswith(('.gz', '.tgz')):
|
||||
with gzip.open(filename, 'rb') as f:
|
||||
content = f.read()
|
||||
if any(line in content for line in BLACKLIST):
|
||||
private_key_files.append(filename)
|
||||
continue
|
||||
except gzip.BadGzipFile:
|
||||
pass
|
||||
|
||||
if private_key_files:
|
||||
for private_key_file in private_key_files:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue