|
1 | 1 | """Acceptance tests for issue #211: password hashes are not hardcoded passwords. |
2 | 2 |
|
3 | | -A value in a password-hash format (a PHC string such as ``$argon2id$...`` or a modular |
4 | | -crypt string such as ``$2b$...`` or ``$6$...``) is what an application stores instead of |
5 | | -the password; it does not reveal the password, so a credential-like name bound to it is |
6 | | -not a hardcoded credential. The algorithm identifier is what tells a hash: an incomplete |
7 | | -hash such as ``$argon2id$`` reveals nothing either. A plaintext value bound to the same |
8 | | -name is still reported, dollar signs included. |
| 3 | +A value in a password-hash format is what an application stores instead of the |
| 4 | +password; it does not reveal the password, so a credential-like name bound to it is not |
| 5 | +a hardcoded credential. The formats are PHC and modular crypt strings (``$argon2id$...``, |
| 6 | +``$2b$...``, ``$6$...``), and the encodings of Werkzeug (``scrypt:32768:8:1$...``) and |
| 7 | +Django (``pbkdf2_sha256$...``). A hash has the shape of its format: an algorithm |
| 8 | +identifier followed by text that is not a hash (``$2y$Summer2024!``) is a plaintext |
| 9 | +password, while the identifier alone (``$argon2id$``, an incomplete hash) reveals |
| 10 | +nothing. A plaintext value bound to the same name is still reported. |
9 | 11 | """ |
10 | 12 |
|
11 | 13 | from __future__ import annotations |
@@ -39,13 +41,32 @@ def check(text: str) -> tuple[Finding, ...]: |
39 | 41 | "$6$saltsalt$qFmFH.bQmmtXzyBY0s9v7Oicd2z4XSIecDzlB5KiA2/jctKu9YterLp8wwnSq.qc.eoxqOmSuNp2xS0ktL3nh/", |
40 | 42 | "$pbkdf2-sha256$29000$N2YMIWQsBWBMae09x1jrPQ$1t8iyB2A.WF/Z5JZv.lfCIhXXN33N23OSgQYThBYRfk", |
41 | 43 | "$scrypt$ln=16,r=8,p=1$aM15713r3Xsvxbi31lqr1Q$nFNh2CVHVjNldFVKDHDlm4CbdRSCdEBsjjJxD+iCs5E", |
| 44 | + "$1$O3JMY.Tw$AdLnLjQ/5jXF9.MTp3gHv/", |
| 45 | + "$apr1$71850310$gh9m4xcAn3MGxogwX/ztb.", |
| 46 | + "$y$j9T$F5Jx5fExrKuPp53xLKQ..1$X3DX6M94c7o.9agCG9G317fhZg9SqC.5i5rd.RhAtQ7", |
| 47 | + "scrypt:32768:8:1$KbI3sQ1x9cBnGz7a$d624ca2ead7454931117ad5ab4342ed9d93ae0407f730264d97f655506d36fb308d1ddb7f4c5f9046884ba4516df4b6e492ba26a31786ff43bec1f2d8999bc47", |
| 48 | + "pbkdf2:sha256:600000$KbI3sQ1x9cBnGz7a$57fab0cc5de31d8fb5518804d402a6dd807e483ba7c6e3968a10cd466d28c46e", |
| 49 | + "pbkdf2_sha256$870000$Qx7mR2vT9kLp4sWz$q8bVU34ZbIqSroAvvFgZhHZ6jNeCNMPqYZOg52ta260=", |
| 50 | + "argon2$argon2id$v=19$m=102400,t=2,p=8$c29tZXNhbHQ$ieVgG5ysTJFx4k/KvmC9aQ", |
| 51 | + "bcrypt_sha256$$2b$12$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy", |
| 52 | + "scrypt$16384$c29tZXNhbHQ$8$1$nFNh2CVHVjNldFVKDHDlm4CbdRSCdEBsjjJxD+iCs5E=", |
42 | 53 | ], |
43 | 54 | ) |
44 | 55 | def test_a_password_hash_is_not_a_hardcoded_credential(value: str) -> None: |
45 | 56 | assert check(f'web_password = "{value}"\n') == () |
46 | 57 |
|
47 | 58 |
|
48 | | -@pytest.mark.parametrize("value", ["hunter2-not-a-placeholder", "pa$$w0rd-really", "$ecret$value"]) |
| 59 | +@pytest.mark.parametrize( |
| 60 | + "value", |
| 61 | + [ |
| 62 | + "hunter2-not-a-placeholder", |
| 63 | + "pa$$w0rd-really", |
| 64 | + "$ecret$value", |
| 65 | + "$2y$Summer2024!", |
| 66 | + "$scrypt$MyRealPassw0rd", |
| 67 | + "$5$hunter2-plain", |
| 68 | + ], |
| 69 | +) |
49 | 70 | def test_a_plaintext_password_is_still_reported(value: str) -> None: |
50 | 71 | (finding,) = check(f'web_password = "{value}"\n') |
51 | 72 |
|
|
0 commit comments