1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
3
3
4
+ from __future__ import absolute_import
4
5
import shutil
5
6
import sys
6
7
import math
@@ -178,10 +179,14 @@ def find_entropy(printableDiff, commit_time, branch_name, prev_commit, blob, com
178
179
entropicDiff ['reason' ] = "High Entropy"
179
180
return entropicDiff
180
181
181
- def regex_check (printableDiff , commit_time , branch_name , prev_commit , blob , commitHash ):
182
+ def regex_check (printableDiff , commit_time , branch_name , prev_commit , blob , commitHash , custom_regexes = {}):
183
+ if custom_regexes :
184
+ secret_regexes = custom_regexes
185
+ else :
186
+ secret_regexes = regexes
182
187
regex_matches = []
183
- for key in regexes :
184
- found_strings = regexes [key ].findall (printableDiff )
188
+ for key in secret_regexes :
189
+ found_strings = secret_regexes [key ].findall (printableDiff )
185
190
for found_string in found_strings :
186
191
found_diff = printableDiff .replace (printableDiff , bcolors .WARNING + found_string + bcolors .ENDC )
187
192
if found_strings :
@@ -201,7 +206,7 @@ def regex_check(printableDiff, commit_time, branch_name, prev_commit, blob, comm
201
206
202
207
203
208
204
- def find_strings (git_url , since_commit = None , max_depth = None , printJson = False , do_regex = False , do_entropy = True ):
209
+ def find_strings (git_url , since_commit = None , max_depth = None , printJson = False , do_regex = False , do_entropy = True , custom_regexes = {} ):
205
210
output = {"foundIssues" : []}
206
211
project_path = clone_git_repo (git_url )
207
212
repo = Repo (project_path )
@@ -245,7 +250,7 @@ def find_strings(git_url, since_commit=None, max_depth=None, printJson=False, do
245
250
if entropicDiff :
246
251
foundIssues .append (entropicDiff )
247
252
if do_regex :
248
- found_regexes = regex_check (printableDiff , commit_time , branch_name , prev_commit , blob , commitHash )
253
+ found_regexes = regex_check (printableDiff , commit_time , branch_name , prev_commit , blob , commitHash , custom_regexes )
249
254
foundIssues += found_regexes
250
255
for foundIssue in foundIssues :
251
256
print_results (printJson , foundIssue )
0 commit comments