-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathpatterns.yml
508 lines (473 loc) · 17.3 KB
/
patterns.yml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
name: Configuration Secrets
patterns:
- name: Hardcoded Database Passwords
type: hardcoded_database_passwords
comments:
- "Only support for Postgres and MySQL password strings"
- "Checks if the password is null / length of 0"
- "Supports quoted passwords"
- "Case insensitive"
regex:
version: 0.1
pattern: |
[^\r\n\x00-\x08]+
start: |
(?:[^0-9A-Za-z]|\A)(?i)(?:postgres|mysql|mysql_root)_password[\t ]*[=:][\t ]*['"]?
end: |
\z|[\r\n'"]
test:
data: postgres_password=password
start_offset: 18
end_offset: 26
- name: Hardcoded Spring SQL passwords
description: |
Hardcoded JDBC / Spring datasource passwords which typically are in property files or passed in at runtime
type: hardcoded_spring_sql_passwords
regex:
version: 0.1
pattern: |
[^\r\n'"\x00-\x08]+
start: |
(\A|\b)(?:spring\.datasource|jdbc)\.password[ \t]*=[ \t]*['"]?
end: |
\z|['"\r\n]
expected:
- name: application.properties
start_offset: 314
end_offset: 318
- name: application.properties
start_offset: 358
end_offset: 375
- name: application.properties
start_offset: 422
end_offset: 442
- name: application.properties
start_offset: 836
end_offset: 843
- name: application.properties
start_offset: 1078
end_offset: 1085
- name: application.properties
start_offset: 1346
end_offset: 1353
- name: application.properties
start_offset: 1633
end_offset: 1640
test:
data: spring.datasource.password=password
start_offset: 27
end_offset: 35
- name: Django Secret Key
type: django_secret_key
regex:
version: 0.1
pattern: |
[^\r\n"']+
start: |
(\b|\A)SECRET_KEY[ \t]*=[ \t]*["']
end: |
['"]
expected:
- name: global_settings.py
start_offset: 59
end_offset: 109
test:
data: SECRET_KEY = "password"
start_offset: 14
end_offset: 22
# Experimental
- name: YAML Static Password Fields
type: yaml_static_password_fields
description: |
Pattern to find hardcoded passwords in YAML configuration files
experimental: true
regex:
version: 0.2
pattern: |
[^\r\n`'"\x00-\x08]+
start: |
(?:\n|\A)[ \t]*(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)[ \t]*:[ \t]*['"]?
end: |
['"\r\n]|\z
additional_not_match:
- ^(keyPassphrase|password|key|[ \t]+|\$\{[^}]+}|(str|string|int|bool)( +#.*)?),?$
- ^(.* = )?(None|[Tt]rue|[Ff]alse|[Nn]ull|Default(Type)?|Event|[A-Z]+_KEY|VERSION|NAME|update|destroy|(?:dis|en)ableEventListeners|\.\.\.),?$
- ^(((this|self|obj)\.)([A-Za-z_]+\,|[A-Za-z_].*)|\{\}|\[\]|[0-9a-zA-Z],|\{)$
- ^(([a-zA-Z_]+(\(\))?\.)*[a-zA-Z_]+\(\)|\|\s*)$|\{\{[^}]+\}\}|\$\{\{ |^!Ref |^\$\(.*\)|^(https?|file)://|^(/[a-zA-Z0-9./_-]+/)?[a-zA-Z0-9_-]{5,}(\.(pem|crt|key|cer|pub|der)|_rsa)$|^=|\(\) => |\([^)]+\) => \{
- ^\s*(typing\.)?([Tt]uple|[Ll]ist|[Dd]ict|Callable|Iterable|Sequence|Optional|Union)\[.*$
comments:
- "Expect large numbers of false positives on variables containing 'key' or 'token'"
- "The hardcoded password is any length"
- "Some false positives in code might appear"
- "The pattern only checks for certain key words to end the variable name (`secret`, `password`, etc.)"
- "Does not allow for multline blocks"
expected:
- name: example.yml
start_offset: 57
end_offset: 80
- name: example.yml
start_offset: 57
end_offset: 80
test:
data: "password: password123"
start_offset: 10
end_offset: 21
- name: YAML hardcoded passwords (plain scalars)
type: yaml_passwords_plain
description: |
Hardcoded passwords in YAML configuration files, using plain scalars
experimental: true
regex:
version: 0.1
pattern: |
[^\r\n`'"\x00-\x08]+
start: |
(?:\n|\A)[ \t]*(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)[ \t]*:[ \t]*
end: |
[\r\n]|\z
additional_not_match:
- ^(keyPassphrase|password|key|[ \t]+|\$\{[^}]+}|(str|string|int|bool)( +#.*)?),?$
- ^(.* = )?(None|[Tt]rue|[Ff]alse|[Nn]ull|Default(Type)?|Event|[A-Z]+_KEY|VERSION|NAME|update|destroy|(?:dis|en)ableEventListeners|\.\.\.),?$
- ^(((this|self|obj)\.)([A-Za-z_]+\,|[A-Za-z_].*)|\{\}|\[\]|[0-9a-zA-Z],|\{)$
- ^(([a-zA-Z_]+(\(\))?\.)*[a-zA-Z_]+\(\)|\|\s*)$|\{\{[^}]+\}\}|\$\{\{ |^!Ref |^\$\(.*\)|^(https?|file)://|^(/[a-zA-Z0-9./_-]+/)?[a-zA-Z0-9_-]{5,}(\.(pem|crt|key|cer|pub|der)|_rsa)$|^=|\(\) => |\([^)]+\) => \{
- ^\s*(typing\.)?([Tt]uple|[Ll]ist|[Dd]ict|Callable|Iterable|Sequence|Optional|Union)\[.*$
comments:
- "The hardcoded password is any length"
- "Some false positives in code might appear"
- "The pattern only checks for certain key words to end the variable name (`secret`, `password`, etc.)"
- "Only allows for plain scalars, not quoted or multi-line, to better control false positives"
test:
data: "password: password123"
start_offset: 10
end_offset: 21
- name: YAML hardcoded passwords (single quoted strings)
type: yaml_passwords_single_quoted
description: |
Hardcoded passwords in YAML configuration files, using single quotes
experimental: true
regex:
version: 0.1
pattern: |
[^\r\n'\x00-\x08]+
start: |
(?:\n|\A)[ \t]*(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)[ \t]*:[ \t]*'
end: |
'([ \t]*[\r\n]|\z)
additional_not_match:
- \{\{[^{}]+\}\}
comments:
- "The hardcoded password is any length"
- "Some false positives in code might appear"
- "The pattern only checks for certain key words to end the variable name (`secret`, `password`, etc.)"
- "Only allows for only single-quoted passwords, to better control false positives"
test:
data: "password: 'password123'"
start_offset: 11
end_offset: 22
- name: YAML hardcoded passwords (double quoted strings)
type: yaml_passwords_single_quoted
description: |
Hardcoded passwords in YAML configuration files, using single quotes
experimental: true
regex:
version: 0.1
pattern: |
[^\r\n"\x00-\x08]+
start: |
(?:\n|\A)[ \t]*(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)[ \t]*:[ \t]*"
end: |
"([ \t]*[\r\n]|\z)
additional_not_match:
- \{\{[^{}]+\}\}
comments:
- "The hardcoded password is any length"
- "Some false positives in code might appear"
- "The pattern only checks for certain key words to end the variable name (`secret`, `password`, etc.)"
- "Only allows for only double-quoted passwords, to better control false positives"
test:
data: |
password: "password123"
start_offset: 11
end_offset: 22
- name: YAML hardcoded passwords (multiline strings)
type: yaml_passwords_multiline
description: |
Hardcoded passwords in YAML configuration files, using multiline strings
experimental: true
regex:
version: 0.1
pattern: |
[^\x00-\x08]+?
start: |
(?:\n|\A)[ \t]*(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)[ \t]*:[ \t]*[|>][+-]?[ \t]*(\n|\r\n)[ \t]+
end: |
\n\n|\r\n\r\n|(\n|\r\n)[ \t]+\S+:|(\n|\r\n)\.\.\.[ \t\n\r]|\z
comments:
- "The hardcoded password is any length"
- "Some false positives in code or YAML files might appear, especially where the variable is called 'key' or 'token'"
- "The pattern checks for certain key words to end the variable name (`secret`, `password`, etc.)"
test:
data: |-
password: |
password123
andsomemore
other_field: foo
start_offset: 14
end_offset: 56
- name: GitHub Actions SHA Checker
type: github_actions_sha_checker
comments:
- "Checks for all github actions using a version that isn't a pinned SHA-1 commit hash"
- "Checks for uses: org name / repo name @ string under 40 characters"
- "Not case sensitive"
- "Exclude all actions in actions, github and advanced-security repo"
regex:
version: 0.1
pattern: |
[a-z0-9_-]{1,39}\/[a-z0-9_-]{1,100}@[a-z0-9._-]{1,39}
start: |
\buses:[ \t]{1,5}
end: |
\s|\z
additional_not_match:
- ^(actions|github|advanced-security)/
test:
data: |
uses: sample-org/sample-action@v2
start_offset: 6
end_offset: 33
- name: .NET Configuration file
type: dotnet_configuration
regex:
version: 0.1
pattern: |
[^"\x00\x08]+
start: |
<add\s+key="[^"]*(?i)(password|secret|pass(?:wd|word|code|phrase)?|key|token)"\s+value="
end: |
\"
comments:
- XML key/value format, <add key="key name" value="value of key" />
expected:
- name: app.config
start_offset: 59
end_offset: 84
test:
data: |
<add key="password" value="mypassword" />
start_offset: 27
end_offset: 37
- name: .NET MachineKey
type: dotnet_machinekey
regex:
version: 0.1
pattern: |
[A-Fa-f0-9]+
start: |
<machineKey\s+[^>]*(validation|decryption)Key="
end: |
\"
comments:
- contents of the validationKey or decryptionKey of a machineKey XML element
expected:
- name: web.config
start_offset: 27
end_offset: 154
- name: web.config
start_offset: 171
end_offset: 235
test:
data: |
<machineKey decryptionKey="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F" decryption="AES" />
start_offset: 27
end_offset: 91
- name: .env file style secrets
type: env_passwords
description: |
Find .env file style secrets in configuration files such as .env, Dockerfile, shell scripts etc.
experimental: true
regex:
version: 0.1
pattern: |
[^\r\n\x00-\x08'"#]{8,}
start: |
(?:\n|\A)((export|ENV|ARG) )?[A-Z_]*(?:SECRET|PASS(?:WD|WOR[TD]|CODE|PHRASE)?|KEY|TOKEN)=['"]?
end: |
[\r\n#]|['"]\s*[\r\n]|\z
additional_not_match:
# variable, process substitution
- ^\$(\{[^}]+\}|\([^)]+\)|[A-Za-z_]+|[0-9])$
# placeholders
- ^(<[^>]+>|\[[^]+\]|\{[^}+\}|(your|my|the|a)_[a-z_]+|.*(passwor[t]|key|secret|token|密码).*|\.\.\.|xxx+|yyy+|zzz+|aaa+|bbb+|ccc+)$
# non-secret related "key" content
- ^(test|value)([._-][a-z_.-]+)?$
# non-secret related content
- ^(?i)(true|false|y(es)?|no?|on|off|0|1|nill|null|none|(\\x[a-f0-9]{2})+)$
# a path
- '^(/|file:///|https?://[A-Za-z]:/)[A-Za-z0-9._-]{3,}+(/[a-z._-]{1,}){2,}/?$'
comments:
- "Looks for secrets in the format of `SECRET=secret` at the start of a line, possibly with an `ENV ` or `export ` prefix"
- "Allows no whitespace in the secret, to cut false positives"
- "Some false positives in code might appear, especially where the variable name is 'key' or 'token'"
- "The pattern only checks for certain key words to begin the pattern (`secret`, `password`, etc.)"
- "More restrictive than the Generic Passwords pattern, so less prone to false positives"
- "Lower length limit of 8 to remove FPs"
test:
data: |
SECRET_KEY=password123
start_offset: 11
end_offset: 22
- name: YAML with Base64 encoded secrets
type: yaml_base64
description: |
Hardcoded Base64-encoded passwords in YAML configuration files
experimental: true
regex:
version: 0.1
pattern: |
(([A-Za-z0-9+/]){4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)
start: |
(?:\n|\A)[ \t]*(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)[ \t]*:[ \t]*(['"]?|[|>]-?[ \t]*\n[ \t]*)
end: |
['"\r\n]|\z
additional_match:
- '[0-9]'
- '[A-Z]'
- '[a-z]'
- '^.{12,}$'
comments:
- "The Base64 must contain numbers, upper case and lower case and be at least 12 characters long"
- "Some false positives in code might appear"
test:
data: "password: AAAAAAAAAAAa00=="
start_offset: 10
end_offset: 26
- name: YAML with URI-safe Base64 encoded secrets
type: yaml_base64_uri
description: |
Hardcoded URI-safe Base64-encoded passwords in YAML configuration files
experimental: true
regex:
version: 0.1
pattern: |
(([A-Za-z0-9_-]){4})*([A-Za-z0-9_-]{4}|[A-Za-z0-9_-]{3}=|[A-Za-z0-9_-]{2}==)
start: |
(?:\n|\A)[ \t]*(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)[ \t]*:[ \t]*(['"]?|[|>]-?[ \t]*\n[ \t]*)
end: |
['"\r\n]|\z
additional_match:
- '[0-9]'
- '[A-Z]'
- '[a-z]'
- '^.{12,}$'
comments:
- "The Base64 must contain numbers, upper case and lower case and be at least 12 characters long"
- "Some false positives in code might appear"
- "This matches _- instead of +/, for URI-safe Base64"
test:
data: "password: AAAAAAAAAAAa00=="
start_offset: 10
end_offset: 26
- name: YAML with hex token
type: yaml_token
description: |
Hardcoded hex-encoded tokens in YAML configuration files
experimental: true
regex:
version: 0.1
pattern: |
[0-9a-f]{32}|[0-9a-f]{40}|[0-9a-f]{64}
start: |
(?:\n|\A)[ \t]*(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)[ \t]*:[ \t]*(['"]?|[|>]-?[ \t]*\n[ \t]*)
end: |
['"\r\n]|\z
additional_match:
- '[0-9]'
- '[a-f]'
comments:
- "The hex token must be 32, 40 or 64 characters long, and contain numbers and letters"
- "Some false positives in code might appear"
test:
data: "password: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
start_offset: 10
end_offset: 74
- name: JSON with Base64 encoded secrets
type: json_base64
description: |
Hardcoded Base64-encoded passwords in JSON configuration files
experimental: true
regex:
version: 0.1
pattern: |
(([A-Za-z0-9+/]){4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)
start: |
[{[,][ \t]*[ \t\r\n]*"(?i)[a-z_.-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)"[ \t]*:[ \t]*"
end: |
"[ \t\r\n]*[,}\]]
additional_match:
- '[0-9]'
- '[A-Z]'
- '[a-z]'
- '^.{12,}$'
comments:
- "The Base64 must contain numbers, upper case and lower case and be at least 12 characters long"
- "This may match in code, such as Python, that resembles JSON"
- "This will not match some isolated fragments of JSON, so be aware of that when testing it"
test:
data: |
{"password": "AAAAAAAAAAAa00==", "user": "admin"}
start_offset: 14
end_offset: 30
- name: JSON with URI-safe Base64 encoded secrets
type: json_base64_uri
description: |
Hardcoded URI-safe Base64-encoded passwords in JSON configuration files
experimental: true
regex:
version: 0.1
pattern: |
(([A-Za-z0-9_-]){4})*([A-Za-z0-9_-]{4}|[A-Za-z0-9_-]{3}=|[A-Za-z0-9_-]{2}==)
start: |
[{[,][ \t]*[ \t\r\n]*"(?i)[a-z_.-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)"[ \t]*:[ \t]*"
end: |
"[ \t\r\n]*[,}\]]
additional_match:
- '[0-9]'
- '[A-Z]'
- '[a-z]'
- '^.{12,}$'
comments:
- "The Base64 must contain numbers, upper case and lower case and be at least 12 characters long"
- "This may match in code, such as Python, that resembles JSON"
- "This will not match some isolated fragments of JSON, so be aware of that when testing it"
- "This matches _- instead of +/, for URI-safe Base64"
test:
data: |
{"password": "AAAAAAAAAAAa00==", "user": "admin"}
start_offset: 14
end_offset: 30
- name: JSON with hex encoded secrets
type: json_token
description: |
Hardcoded hex-encoded tokens in JSON configuration files
experimental: true
regex:
version: 0.1
pattern: |
[0-9a-f]{32}|[0-9a-f]{40}|[0-9a-f]{64}
start: |
[{[,][ \t]*[ \t\r\n]*"(?i)[a-z_-]*(?:secret|service_pass(wd|word|code|phrase)|pass(?:wd|word|code|phrase)?|key|token)"[ \t]*:[ \t]*"
end: |
"[ \t\r\n]*[,}\]]
additional_match:
- '[0-9]'
- '[a-f]'
comments:
- "The hex token must be 32, 40 or 64 characters long, and contain numbers and letters"
- "This may match in code, such as Python, that resembles JSON"
- "This will not match some isolated fragments of JSON, so be aware of that when testing it"
test:
data: |
{"password": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "user": "admin"}
start_offset: 14
end_offset: 78