Skip to content

Commit f973020

Browse files
committed
Add examples from issues of hardcoded password checks.
1 parent 742bcf2 commit f973020

File tree

2 files changed

+80
-24
lines changed

2 files changed

+80
-24
lines changed

examples/hardcoded-passwords.py

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,6 @@ class SomeClass:
183183
a[b]: "str" = "password"
184184

185185

186-
# Possible hardcoded password: 'password'
187-
# Severity: Low Confidence: Medium
188-
# https://github.com/PyCQA/bandit/issues/642
189-
class MyConfig:
190-
my_password: str = 'password'
191-
192-
193186
#-----------------------------------------------------------------------------
194187
# DICTIONARIES
195188
#-----------------------------------------------------------------------------
@@ -210,21 +203,6 @@ class MyConfig:
210203
{a: "password"}
211204

212205

213-
# Possible hardcoded password: 'pass'
214-
# Severity: Low Confidence: Medium
215-
# https://github.com/PyCQA/bandit/issues/313
216-
log({"server": server, "password": 'pass', "user": user})
217-
218-
# not!
219-
log({"server": server, "password": password, "user": user})
220-
221-
222-
# Possible hardcoded password: '12345'
223-
# Severity: Low Confidence: Medium
224-
# https://github.com/PyCQA/bandit/issues/1267
225-
{"password": "12345"}
226-
227-
228206
#-----------------------------------------------------------------------------
229207
# COMPARISONS
230208
#-----------------------------------------------------------------------------
@@ -403,6 +381,84 @@ def NoMatch3(a, b):
403381
pass
404382

405383

384+
#-----------------------------------------------------------------------------
385+
# REPORTED ISSUES
386+
#-----------------------------------------------------------------------------
387+
388+
# https://github.com/PyCQA/bandit/issues/313
389+
390+
# Possible hardcoded password: 'pass'
391+
# Severity: Low Confidence: Medium
392+
log({"server": server, "password": 'pass', "user": user})
393+
394+
# not!
395+
log({"server": server, "password": password, "user": user})
396+
397+
# Possible hardcoded password: 'pass'
398+
# Severity: Low Confidence: Medium
399+
log(password='pass')
400+
401+
402+
# https://github.com/PyCQA/bandit/issues/386
403+
404+
# Possible hardcoded password: 'secret'
405+
# Severity: Low Confidence: Medium
406+
EMAIL_PASSWORD = "secret"
407+
408+
# Possible hardcoded password: 'emails_secret'
409+
# Severity: Low Confidence: Medium
410+
email_pwd = 'emails_secret'
411+
412+
413+
# https://github.com/PyCQA/bandit/issues/551
414+
415+
# Possible hardcoded password: 'aaaaaaa'
416+
# Severity: Low Confidence: Medium
417+
app.config['SECRET_KEY'] = 'aaaaaaa'
418+
419+
420+
# https://github.com/PyCQA/bandit/issues/605
421+
422+
# Possible hardcoded password: 'root'
423+
# Severity: Low Confidence: Medium
424+
def fooBar(password):
425+
if password == "root":
426+
print("OK, logged in")
427+
428+
429+
# https://github.com/PyCQA/bandit/issues/639
430+
431+
# Possible hardcoded password: '1238aoufhz8xyf3jr;'
432+
# Severity: Low Confidence: Medium
433+
password = "1238aoufhz8xyf3jr;"
434+
435+
436+
# https://github.com/PyCQA/bandit/issues/642
437+
438+
# Possible hardcoded password: 'password'
439+
# Severity: Low Confidence: Medium
440+
class MyConfig:
441+
my_password: str = 'password'
442+
443+
444+
# https://github.com/PyCQA/bandit/issues/759
445+
446+
# Possible hardcoded password: '12123123'
447+
# Severity: Low Confidence: Medium
448+
password = "12123123"
449+
450+
# Possible hardcoded password: '12123123'
451+
# Severity: Low Confidence: Medium
452+
self.password = "12123123"
453+
454+
455+
# https://github.com/PyCQA/bandit/issues/1267
456+
457+
# Possible hardcoded password: '12345'
458+
# Severity: Low Confidence: Medium
459+
{"password": "12345"}
460+
461+
406462
#-----------------------------------------------------------------------------
407463
# OTHER
408464
#-----------------------------------------------------------------------------

tests/functional/test_functional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ def test_exec(self):
168168
def test_hardcoded_passwords(self):
169169
"""Test for hard-coded passwords."""
170170
expect = {
171-
"SEVERITY": {"UNDEFINED": 0, "LOW": 43, "MEDIUM": 0, "HIGH": 0},
172-
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 43, "HIGH": 0},
171+
"SEVERITY": {"UNDEFINED": 0, "LOW": 51, "MEDIUM": 0, "HIGH": 0},
172+
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 51, "HIGH": 0},
173173
}
174174
self.check_example("hardcoded-passwords.py", expect)
175175

0 commit comments

Comments
 (0)