Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(secrets): refactor secret detection and masking mechanism #6858

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 23 additions & 32 deletions assets/queries/common/passwords_and_secrets/regex_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"regex": "['\"]?AllowUsersToChangePassword['\"]?\\s*[:=]\\s*['\"]?([A-Za-z0-9/~^_!@&%()=?*+-.]{4,})['\"]?"
}
],
"specialMask": "(?i)['\"]?password['\"]?\\s*[:=]\\s*"
"groupMask": 1
},
{
"id": "3e2d3b2f-c22a-4df1-9cc6-a7a0aebb0c99",
Expand Down Expand Up @@ -45,32 +45,28 @@
"regex": "['\"]?Description['\"]?\\s*[:=]\\s*['\"]?([A-Za-z0-9/~^_!@&%()=?*${}+-.'\"]+)['\"]?"
}
],
"specialMask": "(?i)['\"]?secret[_]?(key)?['\"]?\\s*(:|=)\\s*"
"groupMask": 3
},
{
"id": "51b5b840-cd0c-4556-98a7-fe5f4def80cf",
"name": "Asymmetric private key",
"regex": "-----BEGIN ((EC|PGP|DSA|RSA|OPENSSH) )?PRIVATE KEY( BLOCK)?-----\\s*(([A-Za-z0-9+,:\\-\\/=\\n\\r]+\\s*)+)-----END ((EC|PGP|DSA|RSA|OPENSSH) )?PRIVATE KEY( BLOCK)?-----",
"multiline": {
"detectLineGroup": 4
},
"regex": "-----BEGIN ((EC|PGP|DSA|RSA|OPENSSH) )?PRIVATE KEY( BLOCK)?-----\\s*(([A-Za-z0-9+,:\\-\\/=\\n\\r]+\\s*)+)\n-----END ((EC|PGP|DSA|RSA|OPENSSH) )?PRIVATE KEY( BLOCK)?-----",
pereiramarco011 marked this conversation as resolved.
Show resolved Hide resolved
"multiline": true,
"entropies": [
{
"group": 5,
"min": 3.7,
"max": 12
}
],
"specialMask": "all"
"groupMask": 4
},
{
"id": "a007a85e-a2a7-4a81-803a-7a2ca0c65abb",
"name": "Putty User Key File Content",
"regex": "['\"]?PuTTY-User-Key-File-\\d: ([\\w\\d-:\\n\\s+/=]+Private-MAC: [\\d\\w\"]+)['\"]?",
"multiline": {
"detectLineGroup": 1
},
"specialMask": "all"
"multiline": true,
"groupMask": 1
},
{
"id": "c4d3b58a-e6d4-450f-9340-04f1e702eaae",
Expand Down Expand Up @@ -103,16 +99,14 @@
"max": 7
}
],
"specialMask": "(?i)AWS_SECRET(_ACCESS)?(_KEY)?\\s*[:=]\\s*"
"groupMask": 3
},
{
"id": "4b2b5fd3-364d-4093-bac2-17391b2a5297",
"name": "K8s Environment Variable Password",
"regex": "apiVersion((.*)\\s*)*env:((.*)\\s*)*name:\\s*\\w+(?i)pass((?i)word)?\\w*\\s*(value):\\s*([\"|'].*[\"|'])",
"multiline": {
"detectLineGroup": 7
},
"specialMask": "\\s*(value):\\s*"
"multiline": true,
"groupMask": 7
},
{
"id": "d651cca2-2156-4d17-8e76-423e68de5c8b",
Expand Down Expand Up @@ -158,10 +152,8 @@
"id": "9a3650af-5b88-48cd-ab89-cd77fd0b633f",
"name": "Heroku API Key",
"regex": "['\"]?(?i)heroku((.|\\n)*)\\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\\b['\"]?",
"multiline": {
"detectLineGroup": 3
},
"specialMask": "['\"]?(?i)api_key[^\\w\"']+"
"multiline": true,
"groupMask": 3
},
{
"id": "bb51eb1e-0357-44a2-86d7-dd5350cffd43",
Expand Down Expand Up @@ -203,7 +195,7 @@
"regex": "(?i)['\"]?api[_]?key['\"]?\\s*[:=]\\s*['\"]?(SK[0-9a-fA-F]{32})['\"]?"
}
],
"specialMask": "(?i)['\"]?api[_]?key['\"]?\\s*[:=]\\s*"
"groupMask": 1
},
{
"id": "62d0025d-9575-4eff-b60b-d3b4fcec0d04",
Expand All @@ -223,25 +215,25 @@
{
"id": "7f370dd5-eea3-4e5f-8354-3cb2506f9f13",
"name": "Generic Access Key",
"regex": "(?i)^\\s*['\"]?(access)[_]?key['\"]?\\s*[:=]\\s*['\"]?([[A-Za-z0-9\/~^_!@&%()=?*+-]+)['\"]?",
"specialMask": "(?i)['\"]?access[_]?key['\"]?\\s*[:=]\\s*"
"regex": "(?i)^\\s*['\"]?(access)[_]?key['\"]?\\s*[:=]\\s*['\"]?([[A-Za-z0-9/~^_!@&%()=?*+-]+)['\"]?",
"groupMask": 2
},
{
"id": "2f665079-c383-4b33-896e-88268c1fa258",
"name": "Generic Private Key",
"regex": "(?i)['\"]?private[_]?key['\"]?\\s*[:=]\\s*['\"]?([[A-Za-z0-9/~^_!@&%()=?*+-]+)['\"]?",
"specialMask": "(?i)['\"]?private[_]?key['\"]?\\s*[:=]\\s*",
"allowRules": [
{
"description": "Avoiding bash variables",
"regex": "(?i)['\"]?\\$\\s*\\{[^\\s\\}]+\\}['\"]?"
}
]
],
"groupMask": 1
},
{
"id": "baee238e-1921-4801-9c3f-79ae1d7b2cbc",
"name": "Generic Token",
"regex": "(?i)['\"]?token(_)?(key)?['\"]?\\s*[:=]\\s*['\"]?([[A-Za-z0-9/~^_!@&%()=?*+-]+)['\"]?",
"regex": "(?i)['\"]?token(_)?(key)?['\"]?\\s*[:=]\\s*['\"]?([[A-Za-z0-9/~^_!@&%()=?*+-:]+)['\"]?",
"allowRules": [
{
"description": "Avoiding Amazon MWS Auth Token",
Expand Down Expand Up @@ -300,14 +292,13 @@
"regex": "(?i)['\"]?next(_)?token['\"]?\\s*[:=]\\s*['\"]?([[A-Za-z0-9/~^_!@&%()=?*+-]+)['\"]?"
}
],
"specialMask": "(?i)['\"]?token(_)?(key)?['\"]?\\s*[:=]\\s*"

"groupMask": 3
},
{
"id": "e0f01838-b1c2-4669-b84b-981949ebe5ed",
"id": "36b8f84d-df4e-4d49-b662-bcde71a8764f",
"name": "CloudFormation Secret Template",
"regex": "(?i)['\"]?SecretStringTemplate['\"]?\\s*:\\s*['\"]?{([\\\":A-Za-z0-9/~^_!@&%()=?*+-]{10,})}",
"specialMask": "(?i)['\"]?SecretStringTemplate['\"]?\\s*:\\s*"
"groupMask": 1
},
{
"id": "9fb1cd65-7a07-4531-9bcf-47589d0f82d6",
Expand All @@ -323,7 +314,7 @@
"regex": "['\"]?EncryptionKey['\"]?\\s*[:=]\\s*['\"]?([A-Za-z0-9/~^_!@&%()=?*+-.]+)['\"]?"
}
],
"specialMask": "(?i)['\"]?encryption[_]?key['\"]?\\s*[:=]\\s*"
"groupMask": 1
},
{
"id": "8a879bc7-6f82-40fd-bb48-74d25d557fe8",
Expand Down Expand Up @@ -373,4 +364,4 @@
"regex": "(?i)['\"]?[a-zA-Z_]+['\"]?\\s*[=:]\\s*['\"]?(\\*[0-9A-F]{40})['\"]?"
}
]
}
}
4 changes: 2 additions & 2 deletions e2e/fixtures/E2E_CLI_032_RESULT.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
},
{
"query_name": "Passwords And Secrets - CloudFormation Secret Template",
"query_id": "e0f01838-b1c2-4669-b84b-981949ebe5ed",
"query_id": "36b8f84d-df4e-4d49-b662-bcde71a8764f",
"query_url": "https://docs.kics.io/latest/secrets/",
"severity": "HIGH",
"platform": "Common",
Expand All @@ -133,7 +133,7 @@
"files": [
{
"file_name": "path\\e2e\\fixtures\\samples\\positive.yaml",
"similarity_id": "5f948e5c0c97f3e7c43cd531de50c6c54a2cec221a45f113a34a571165d30553",
"similarity_id": "a7e6db3c5be444e0af7143587415cc60a7ecb2f5881442f1eccd01d2378f72b0",
"line": 273,
"issue_type": "RedundantAttribute",
"search_key": "",
Expand Down
Loading
Loading