Skip to content

Commit

Permalink
Escaping parenthesis on regex to fix error
Browse files Browse the repository at this point in the history
re.error: unbalanced parenthesis at position X
Fixed by: m4ll0k#63
  • Loading branch information
PolEspurnes authored Dec 29, 2022
1 parent 7488d07 commit ec38c84
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions SecretFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
'amazon_aws_access_key_id' : r'A[SK]IA[0-9A-Z]{16}',
'amazon_mws_auth_toke' : r'amzn\\.mws\\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',
'amazon_aws_url' : r's3\.amazonaws.com[/]+|[a-zA-Z0-9_-]*\.s3\.amazonaws.com',
'amazon_aws_url2' : r"(" \
'amazon_aws_url2' : r"\(" \
r"[a-zA-Z0-9-\.\_]+\.s3\.amazonaws\.com" \
r"|s3://[a-zA-Z0-9-\.\_]+" \
r"|s3-[a-zA-Z0-9-\.\_\/]+" \
r"|s3.amazonaws.com/[a-zA-Z0-9-\.\_]+" \
r"|s3.console.aws.amazon.com/s3/buckets/[a-zA-Z0-9-\.\_]+)",
r"|s3.console.aws.amazon.com/s3/buckets/[a-zA-Z0-9-\.\_]+\)",
'facebook_access_token' : r'EAACEdEose0cBA[0-9A-Za-z]+',
'authorization_basic' : r'basic [a-zA-Z0-9=:_\+\/-]{5,100}',
'authorization_bearer' : r'bearer [a-zA-Z0-9_\-\.=:_\+\/]{5,100}',
Expand All @@ -67,14 +67,14 @@
'ssh_dc_private_key' : r'-----BEGIN EC PRIVATE KEY-----',
'pgp_private_block' : r'-----BEGIN PGP PRIVATE KEY BLOCK-----',
'json_web_token' : r'ey[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$',
'slack_token' : r"\"api_token\":\"(xox[a-zA-Z]-[a-zA-Z0-9-]+)\"",
'SSH_privKey' : r"([-]+BEGIN [^\s]+ PRIVATE KEY[-]+[\s]*[^-]*[-]+END [^\s]+ PRIVATE KEY[-]+)",
'slack_token' : r"\"api_token\":\"\(xox[a-zA-Z]-[a-zA-Z0-9-]+\)\"",
'SSH_privKey' : r"\([-]+BEGIN [^\s]+ PRIVATE KEY[-]+[\s]*[^-]*[-]+END [^\s]+ PRIVATE KEY[-]+\)",
'Heroku API KEY' : r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}',
'possible_Creds' : r"(?i)(" \
'possible_Creds' : r"\(?i\)\(" \
r"password\s*[`=:\"]+\s*[^\s]+|" \
r"password is\s*[`=:\"]*\s*[^\s]+|" \
r"pwd\s*[`=:\"]*\s*[^\s]+|" \
r"passwd\s*[`=:\"]+\s*[^\s]+)",
r"passwd\s*[`=:\"]+\s*[^\s]+\)",
}

_template = '''
Expand Down Expand Up @@ -155,6 +155,7 @@ def getContext(matches,content,name,rex='.+?'):
if i not in matches2:
matches2.append(i)
for m in matches2:
m = m.replace('(','\\(').replace(')','\\)') # Escape parenthesis to avoid regex error
context = re.findall('%s%s%s'%(rex,m,rex),content,re.IGNORECASE)

item = {
Expand Down

0 comments on commit ec38c84

Please sign in to comment.