credsweeper.common package

Submodules

credsweeper.common.constants module

class credsweeper.common.constants.Chars(value)[source]

Bases: Enum

Stores enumeration of characters sets of encoding dictionaries

ASCII_PRINTABLE = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
ASCII_VISIBLE = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
BASE16LOWER = '0123456789abcdef'
BASE16UPPER = '0123456789ABCDEF'
BASE32_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
BASE36_CHARS = '0123456789abcdefghijklmnopqrstuvwxyz'
BASE62_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
BASE64STDPAD_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
BASE64STD_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
BASE64URLPAD_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_='
BASE64URL_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
HEX_CHARS = '0123456789ABCDEFabcdef'
UUID_LOWER_CHARS = '0123456789abcdef-'
UUID_UPPER_CHARS = '0123456789ABCDEF-'
class credsweeper.common.constants.Confidence(value)[source]

Bases: Enum

Confidence of candidate

MODERATE = 'moderate'
STRONG = 'strong'
WEAK = 'weak'
static get(confidence: str | Confidence) Confidence | None[source]

returns Confidence value from string or None

class credsweeper.common.constants.DiffRowType(value)[source]

Bases: Enum

Diff type of row

ADDED = 'added'
DELETED = 'deleted'
class credsweeper.common.constants.GroupType(value)[source]

Bases: Enum

Group type - used in Group constructor for load predefined set of filters

DEFAULT = 'default'
KEYWORD = 'keyword'
PATTERN = 'pattern'
class credsweeper.common.constants.RuleType(value)[source]

Bases: Enum

Rule type

KEYWORD = 'keyword'
MULTI = 'multi'
PATTERN = 'pattern'
PEM_KEY = 'pem_key'
class credsweeper.common.constants.Severity(value)[source]

Bases: Enum

Severity of candidate

CRITICAL = 'critical'
HIGH = 'high'
INFO = 'info'
LOW = 'low'
MEDIUM = 'medium'
static get(severity: str | Severity) Severity | None[source]

returns Severity value from string or None

class credsweeper.common.constants.StartEnd(start, end)

Bases: tuple

end: int

Alias for field number 1

start: int

Alias for field number 0

class credsweeper.common.constants.ThresholdPreset(value)[source]

Bases: Enum

Preset threshold to simplify precision/recall selection for the user.

high = 'high'
highest = 'highest'
low = 'low'
lowest = 'lowest'
medium = 'medium'

credsweeper.common.keyword_checklist module

class credsweeper.common.keyword_checklist.KeywordChecklist[source]

Bases: object

KeywordsChecklist contains words 3 or more letters length

KEYWORD_PATH = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/credsweeper/checkouts/v1.15.8/credsweeper/common/keyword_checklist.txt')
MORPHEME_PATH = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/credsweeper/checkouts/v1.15.8/credsweeper/common/morpheme_checklist.txt')
check_morphemes(line_lower: str, threshold: int) bool[source]

Checks limit of morphemes limit in line.

Parameters:
  • line_lower – input line - MUST be in lower

  • threshold – number of minimal morphemes

Returns:

True - if number of morphemes exceeds the threshold

property keyword_len: int

Length of keyword_set

property keyword_list: List[str]

Get list with keywords in descended order of length

property keyword_set: Set[str]

Get set with keywords

property morpheme_len: int

Length of morpheme_set

property morpheme_set: Set[str]

Get extended set with keywords.

Returns:

Extended set of strings

credsweeper.common.keyword_pattern module

class credsweeper.common.keyword_pattern.KeywordPattern[source]

Bases: object

Pattern set of keyword types

auth_keywords = '(\\s?(oauth|bot|basic|bearer|apikey|accesskey|ssws|ntlm|token)\\s)?'
directive = '(?P<directive>(?:(?:[#%]define|define(?=(\\s|\\\\{1,8}[tnr])*\\()|%global)(?:\\s?\\(|\\s|\\\\{1,8}[tnr]){1,8}|\\bset(?=\\b|\\w*(\\s|\\\\{1,8}[tnr])*\\()))?'
classmethod get_keyword_pattern(keyword: str) Pattern[source]

Returns compiled regex pattern

key_left = '(?:\\\\[nrt]|(\\\\\\\\*u00|%)[0-9a-f]{2}|\\s)*(?P<variable>(([\\"\'`]{1,8}[^:=\\"\'`}<>\\\\/&?]*|[^:=\\"\'`}<>\\s()\\\\/&?;,%]*)'
key_right = '[^%:=\\"\'`<>({?!&;\\n]{0,80})(&(quot|apos|#3[49]);|(\\\\\\\\*u00|%)[0-9a-f]{2}|[\\"\'`])*)'
left_quote = '(?P<value_leftquote>((?P<esq>\\\\{1,8})?([\\"\'`]|&(quot|apos|#3[49]);)){1,4}))?'
right_quote = '(?(value_leftquote)(?P<value_rightquote>(?<!\\\\)(?P=value_leftquote)|\\\\$|(?<=[0-9a-z+_/-])$)|(?(wrap)(\\]|\\)|\\}|;|\\\\|$)))'
separator = '(?(directive)|(\\s|\\\\{1,8}[tnr])*\\]?(\\s|\\\\{1,8}[tnr])*)(?P<separator>:(\\s[a-z]{3,9}[?]?\\s)?=|:(?!:)|=(>|&gt;|(\\\\\\\\*u00|%)26gt;)|!==|!=|===|==|=~|=|(?(directive)(,|\\\\t|\\s|\\((?!\\))){1,80}|%3d))(\\s|\\\\{1,8}[tnr])*'
string_prefix = '(((b|r|br|rb|u|t|f|rf|fr|l|@)(?=(\\\\*[\\"\'`])))?'
value = '(?P<value>(?(value_leftquote)((?!(?P=value_leftquote))(?(esq)((?!(?P=esq)([\\"\'`]|&(quot|apos|#3[49]);)).)|((?!(?P=value_leftquote)).)))|(?!&(quot|apos|#3[49]);)(\\\\{1,8}([ tnr]|[^\\s\\"\'`])|(?P<url_esc>%[0-9a-f]{2})|(?(url_esc)[^\\s\\"\'`,;\\\\&]|[^\\s\\"\'`,;\\\\]))){4,8000}|(<[^>]{4,8000}>)|(\\$?\\({1,3}[^)]{4,8000}\\){1,3})|(\\$?\\{{1,3}[^}]{4,8000}\\}{1,3})|(?(wrap)(?(value_leftquote)(?!\\\\(?P=value_leftquote))|[^\\]\\)\\}]){16,8000}))'
wrap = '(?P<wrap>(((\\s|\\\\{1,8}[tnr]|new|byte|char|string|\\[\\]){1,8})?(?P<get>([_a-z][0-9a-z_.\\[\\]]*\\.)get|(os\\.)?getenv)?([0-9a-z_.]|::|-(>|&gt;))*\\s*(\\[(?!\\])|\\((?!\\))|\\{(?!\\}))(\\s|\\\\{1,8}[tnr])*(?(get)(\'[^\']{1,31}\'|\\"[^\\"]{1,31}\\")\\s*(,|\\)\\s*or)\\s*|)([0-9a-z_]{1,32}\\s*[:=]\\s*)?){1,8})?'

Module contents