GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — snowflake-connector-python/secret_detector.py at master · byule/snowflake-connector-python

Expand file tree

/

secret_detector.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
63 lines (51 loc) · 2.28 KB
/

secret_detector.py

Copy path

File metadata and controls

63 lines (51 loc) · 2.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2019 Snowflake Computing Inc. All right reserved.
#
"""
Detects and Masks Secrets. Based on SecretDetector.java in the JDBC Driver
"""
import re
class SecretDetector(object):
AWS_KEY_PATTERN = re.compile(r"(aws_key_id|aws_secret_key|access_key_id|secret_access_key)\s*=\s*'([^']+)'", flags=re.IGNORECASE)
AWS_TOKEN_PATTERN = re.compile(r'(accessToken|tempToken|keySecret)"\s*:\s*"([a-z0-9/+]{32,}={0,2})"', flags=re.IGNORECASE)
SAS_TOKEN_PATTERN = re.compile(r'(sig|signature|AWSAccessKeyId|password|passcode)=(?P<secret>[a-z0-9%/+]{16,})', flags=re.IGNORECASE)
PRIVATE_KEY_PATTERN = re.compile(r'-----BEGIN PRIVATE KEY-----\\n([a-z0-9/+=\\n]{32,})\\n-----END PRIVATE KEY-----', flags=re.MULTILINE | re.IGNORECASE)
PRIVATE_KEY_DATA_PATTERN = re.compile(r'"privateKeyData": "([a-z0-9/+=\\n]{10,})"', flags=re.MULTILINE | re.IGNORECASE)
@staticmethod
def mask_aws_keys(text):
return SecretDetector.AWS_KEY_PATTERN.sub(r"\1='**********'", text)
@staticmethod
def mask_sas_tokens(text):
return SecretDetector.SAS_TOKEN_PATTERN.sub(r'\1=**********', text)
@staticmethod
def mask_aws_tokens(text):
return SecretDetector.AWS_TOKEN_PATTERN.sub(r'\1":"XXXX"', text)
@staticmethod
def mask_private_key(text):
return SecretDetector.PRIVATE_KEY_PATTERN.sub("-----BEGIN PRIVATE KEY-----\\\\nXXXX\\\\n-----END PRIVATE KEY-----", text)
@staticmethod
def mask_private_key_data(text):
return SecretDetector.PRIVATE_KEY_DATA_PATTERN.sub('"privateKeyData": "XXXX"', text)
@staticmethod
def mask_secrets(text):
"""
Masks any secrets. This is the method that should be used by outside classes
:param text: a string which may contain a secret
:return: the masked string
"""
if text is None:
return None
masked_text = SecretDetector.mask_private_key_data(
SecretDetector.mask_private_key(
SecretDetector.mask_aws_tokens(
SecretDetector.mask_sas_tokens(
SecretDetector.mask_aws_keys(
text
)
)
)
)
)
return masked_text
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.