quantumsafe-scan 0.3.0__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {quantumsafe_scan-0.3.0/quantumsafe_scan.egg-info → quantumsafe_scan-0.3.2}/PKG-INFO +28 -11
  2. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/README.md +27 -10
  3. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/__init__.py +1 -1
  4. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/scanner.py +127 -6
  5. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/pyproject.toml +1 -1
  6. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2/quantumsafe_scan.egg-info}/PKG-INFO +28 -11
  7. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/quantumsafe_scan.egg-info/SOURCES.txt +1 -0
  8. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_scanner.py +103 -0
  9. quantumsafe_scan-0.3.2/tests/test_security_hardening.py +124 -0
  10. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/LICENSE +0 -0
  11. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/callgraph.py +0 -0
  12. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/certchain.py +0 -0
  13. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/cli.py +0 -0
  14. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/dependencies.py +0 -0
  15. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/diff.py +0 -0
  16. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/horizon.py +0 -0
  17. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/origins.py +0 -0
  18. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/reachability.py +0 -0
  19. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/recommender.py +0 -0
  20. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/remediation.py +0 -0
  21. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/reporter.py +0 -0
  22. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/scorer.py +0 -0
  23. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/taint.py +0 -0
  24. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/cli/tlsscan.py +0 -0
  25. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/quantumsafe_scan.egg-info/dependency_links.txt +0 -0
  26. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/quantumsafe_scan.egg-info/entry_points.txt +0 -0
  27. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/quantumsafe_scan.egg-info/requires.txt +0 -0
  28. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/quantumsafe_scan.egg-info/top_level.txt +0 -0
  29. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/setup.cfg +0 -0
  30. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_api.py +0 -0
  31. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_benchmark.py +0 -0
  32. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_callgraph.py +0 -0
  33. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_certchain.py +0 -0
  34. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_conformance.py +0 -0
  35. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_cors.py +0 -0
  36. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_diff.py +0 -0
  37. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_features.py +0 -0
  38. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_horizon.py +0 -0
  39. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_origins.py +0 -0
  40. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_pqc.py +0 -0
  41. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_quantum.py +0 -0
  42. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_remediation.py +0 -0
  43. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_schema.py +0 -0
  44. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_scorer.py +0 -0
  45. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_seeded.py +0 -0
  46. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_taint.py +0 -0
  47. {quantumsafe_scan-0.3.0 → quantumsafe_scan-0.3.2}/tests/test_tlsscan.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantumsafe-scan
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Scan codebases and dependencies for quantum-vulnerable cryptography and generate a NIST-aligned migration plan (SARIF + CycloneDX CBOM).
5
5
  Author: QuantumSafe
6
6
  License: MIT
@@ -39,11 +39,12 @@ Dynamic: license-file
39
39
  <img src="https://img.shields.io/pypi/pyversions/quantumsafe-scan?style=flat-square&logo=python&logoColor=white" alt="Python versions">
40
40
  <a href="https://github.com/Danny-397/Quantum-Safe-Scan/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/Danny-397/Quantum-Safe-Scan/ci.yml?branch=main&style=flat-square&logo=githubactions&logoColor=white&label=CI" alt="CI status"></a>
41
41
  <a href="https://github.com/Danny-397/Quantum-Safe-Scan/tags"><img src="https://img.shields.io/github/v/tag/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github&label=version&color=5b73e8" alt="Latest version"></a>
42
- <a href="https://github.com/Danny-397/Quantum-Safe-Scan/stargazers"><img src="https://img.shields.io/github/stars/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github" alt="Stars"></a>
42
+ <a href="https://github.com/Danny-397/Quantum-Safe-Scan"><img src="https://img.shields.io/github/stars/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github" alt="Stars"></a>
43
43
  <img src="https://img.shields.io/github/last-commit/Danny-397/Quantum-Safe-Scan?style=flat-square&color=555" alt="Last commit">
44
44
  <img src="https://img.shields.io/github/license/Danny-397/Quantum-Safe-Scan?style=flat-square&color=3fb950" alt="License: MIT">
45
+ <a href="https://doi.org/10.5281/zenodo.23843488"><img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.23843488-5b73e8?style=flat-square" alt="DOI 10.5281/zenodo.23843488"></a>
45
46
  <br>
46
- <img src="https://img.shields.io/badge/tests-545%20passing-3fb950?style=flat-square&logo=pytest&logoColor=white" alt="545 tests passing">
47
+ <img src="https://img.shields.io/badge/tests-584%20passing-3fb950?style=flat-square&logo=pytest&logoColor=white" alt="584 tests passing">
47
48
  <img src="https://img.shields.io/badge/benchmark-100%25%20precision-3fb950?style=flat-square" alt="100% precision on benchmark">
48
49
  <img src="https://img.shields.io/badge/SARIF%202.1.0-schema--validated-3fb950?style=flat-square" alt="SARIF schema-validated">
49
50
  <img src="https://img.shields.io/badge/NIST-FIPS%20203%2F204%2F205-5b73e8?style=flat-square" alt="NIST FIPS 203/204/205">
@@ -91,7 +92,7 @@ solution:
91
92
  | Layer | Module | What it does |
92
93
  |-------|--------|--------------|
93
94
  | **1. Attack** | [`quantum/`](quantum/) | Shor's and Grover's algorithms in **Qiskit**, run on a quantum simulator. At simulator scale Shor factors a small number and reconstructs a toy RSA key — an educational demonstration of *why* RSA/ECC are rated HIGH (not a break of real key sizes). |
94
- | **2. Detection** | [`cli/`](cli/) | A hybrid **AST + regex** static-analysis engine over 11 languages, with cross-language usage-awareness, **dependency + lockfile scanning**, **reachability ranking**, and **call-site-specific fixes**, that scores risk and produces a NIST-aligned migration plan. **100% precision on the labeled [benchmark](benchmark/)** (18 files) and **100% recall on 50 seeded cases** — see [methodology](benchmark/RESULTS.md). |
95
+ | **2. Detection** | [`cli/`](cli/) | A hybrid **AST + regex** static-analysis engine over 11 languages, with cross-language usage-awareness, **dependency + lockfile scanning**, **reachability ranking**, and **call-site-specific fixes**, that scores risk and produces a NIST-aligned migration plan. **100% precision on the labeled [benchmark](benchmark/)** (18 files), **100% recall on 50 seeded cases**, and **93% precision (95% CI 86–97%) on a random, hand-labeled sample of 100 findings in real PyPI packages**, and **88% recall (95% CI 71–96%) on a held-out random sample of real files with every usage labeled by hand** — see [methodology](benchmark/RESULTS.md), [real-code precision](benchmark/RESULTS-precision.md) and [real-code recall](benchmark/README.md#recall-on-real-code-recall_samplepy). |
95
96
  | **3. Fix** | [`pqc/`](pqc/) | A from-scratch **lattice (LWE) key-encapsulation mechanism** — the math behind CRYSTALS-Kyber / ML-KEM — so the recommended fix is runnable and provable. |
96
97
 
97
98
  The detection layer ships through three surfaces that share **one** engine:
@@ -475,7 +476,13 @@ construction — 50 real quantum-vulnerable API calls (many idiomatic variants
475
476
  per family, 7 languages) that must be detected, plus 50 comment/string decoys
476
477
  that must not be. Latest run: **100% recall, 100% mutation precision**
477
478
  ([RESULTS-seeded.md](benchmark/RESULTS-seeded.md)), enforced by
478
- `tests/test_seeded.py`. Honest limits are documented in
479
+ `tests/test_seeded.py`. Seeded cases only test the patterns someone thought to
480
+ write, so recall is also measured on **real code**: random files from 37 pinned
481
+ PyPI packages, every quantum-vulnerable usage labeled by hand before scanning. The
482
+ first sample found 68%, and its misses drove the fixes; a held-out sample labeled
483
+ afterwards finds **88% (95% CI 71–96%)**
484
+ ([how, and every miss](benchmark/README.md#recall-on-real-code-recall_samplepy)).
485
+ Honest limits are documented in
479
486
  [benchmark/README.md](benchmark/README.md) — these are regression benchmarks, not
480
487
  a claim of perfection on arbitrary code.
481
488
 
@@ -491,7 +498,7 @@ badge from an actual scan — in [docs/EXAMPLES.md](docs/EXAMPLES.md).
491
498
 
492
499
  ### Real-world scan: paramiko (the SSH library)
493
500
 
494
- Run against a shallow clone of [`paramiko/paramiko`](https://github.com/paramiko/paramiko)
501
+ Run in July 2026 against a shallow clone of [`paramiko/paramiko`](https://github.com/paramiko/paramiko)
495
502
  — the SSH implementation behind Ansible, Fabric, and much of the Python ecosystem.
496
503
  SSH key exchange leans on RSA, ECDSA, and Diffie-Hellman, all broken by Shor's
497
504
  algorithm, which makes it a textbook "harvest now, decrypt later" target:
@@ -529,9 +536,10 @@ python benchmark/realworld.py
529
536
  |---|---|
530
537
  | Packages scanned | **37** |
531
538
  | Packages with ≥1 finding | **32 (86%)** |
532
- | Python files analyzed | **10,938** |
533
- | Total findings | **5,512** — **4,083 HIGH-risk** |
534
- | Most common families | `ecc` ×1,709, `sha256` ×956, `rsa` ×770, `sha1` ×576, `dsa` ×355, `md5` ×351 |
539
+ | Python files analyzed | **11,275** |
540
+ | Total findings | **5,609** — **4,236 HIGH-risk** |
541
+ | Most common families | `ecc` ×1,831, `sha256` ×1,013, `rsa` ×796, `sha1` ×577, `md5` ×359, `dsa` ×353 |
542
+ | Run | 2026-10-28, scanner 0.3.1 (latest release of each package) |
535
543
 
536
544
  Every finding is a concrete `file:line` an auditor can open — e.g. Diffie-Hellman
537
545
  in `twisted/conch/ssh/transport.py`, MD5 in `requests/auth.py` (HTTP Digest), and
@@ -710,7 +718,7 @@ jobs:
710
718
  | `output` | `quantumsafe.sarif` | Where to write the SARIF report |
711
719
  | `exclude` | *(none)* | Comma-separated globs to skip |
712
720
  | `fail-on-high` | `"false"` | Exit non-zero if any HIGH finding is present |
713
- | `version` | *(latest)* | Pin `quantumsafe-scan`, e.g. `0.2.0` |
721
+ | `version` | *(latest)* | Pin `quantumsafe-scan`, e.g. `0.3.2` |
714
722
 
715
723
  Pin to a released tag rather than `@main` once one exists — `@main` moves under
716
724
  you, which is the same class of problem as an unpinned linter.
@@ -843,7 +851,7 @@ docker compose up --build
843
851
 
844
852
  ```bash
845
853
  pip install -r requirements-dev.txt
846
- pytest -q # 545 tests; in-memory DB, no setup
854
+ pytest -q # 584 tests; in-memory DB, no setup
847
855
  ```
848
856
 
849
857
  Seed a demo account so the dashboard is populated:
@@ -958,6 +966,15 @@ organization — scheduled re-scans with drift alerts, multi-repo/org dashboards
958
966
  SSO, and audit-ready CBOM history for compliance. Those are operational features,
959
967
  not gates on the core detection, which is the part that should always be open.
960
968
 
969
+ ## Citing
970
+
971
+ Every release is archived on Zenodo. To cite QuantumSafe, use
972
+ [10.5281/zenodo.23843488](https://doi.org/10.5281/zenodo.23843488), which always
973
+ resolves to the newest version; v0.3.1 on its own is
974
+ [10.5281/zenodo.23843498](https://doi.org/10.5281/zenodo.23843498). GitHub's
975
+ "Cite this repository" button reads the same details from
976
+ [CITATION.cff](CITATION.cff).
977
+
961
978
  ## License
962
979
 
963
980
  MIT — see [LICENSE](LICENSE).
@@ -7,11 +7,12 @@
7
7
  <img src="https://img.shields.io/pypi/pyversions/quantumsafe-scan?style=flat-square&logo=python&logoColor=white" alt="Python versions">
8
8
  <a href="https://github.com/Danny-397/Quantum-Safe-Scan/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/Danny-397/Quantum-Safe-Scan/ci.yml?branch=main&style=flat-square&logo=githubactions&logoColor=white&label=CI" alt="CI status"></a>
9
9
  <a href="https://github.com/Danny-397/Quantum-Safe-Scan/tags"><img src="https://img.shields.io/github/v/tag/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github&label=version&color=5b73e8" alt="Latest version"></a>
10
- <a href="https://github.com/Danny-397/Quantum-Safe-Scan/stargazers"><img src="https://img.shields.io/github/stars/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github" alt="Stars"></a>
10
+ <a href="https://github.com/Danny-397/Quantum-Safe-Scan"><img src="https://img.shields.io/github/stars/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github" alt="Stars"></a>
11
11
  <img src="https://img.shields.io/github/last-commit/Danny-397/Quantum-Safe-Scan?style=flat-square&color=555" alt="Last commit">
12
12
  <img src="https://img.shields.io/github/license/Danny-397/Quantum-Safe-Scan?style=flat-square&color=3fb950" alt="License: MIT">
13
+ <a href="https://doi.org/10.5281/zenodo.23843488"><img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.23843488-5b73e8?style=flat-square" alt="DOI 10.5281/zenodo.23843488"></a>
13
14
  <br>
14
- <img src="https://img.shields.io/badge/tests-545%20passing-3fb950?style=flat-square&logo=pytest&logoColor=white" alt="545 tests passing">
15
+ <img src="https://img.shields.io/badge/tests-584%20passing-3fb950?style=flat-square&logo=pytest&logoColor=white" alt="584 tests passing">
15
16
  <img src="https://img.shields.io/badge/benchmark-100%25%20precision-3fb950?style=flat-square" alt="100% precision on benchmark">
16
17
  <img src="https://img.shields.io/badge/SARIF%202.1.0-schema--validated-3fb950?style=flat-square" alt="SARIF schema-validated">
17
18
  <img src="https://img.shields.io/badge/NIST-FIPS%20203%2F204%2F205-5b73e8?style=flat-square" alt="NIST FIPS 203/204/205">
@@ -59,7 +60,7 @@ solution:
59
60
  | Layer | Module | What it does |
60
61
  |-------|--------|--------------|
61
62
  | **1. Attack** | [`quantum/`](quantum/) | Shor's and Grover's algorithms in **Qiskit**, run on a quantum simulator. At simulator scale Shor factors a small number and reconstructs a toy RSA key — an educational demonstration of *why* RSA/ECC are rated HIGH (not a break of real key sizes). |
62
- | **2. Detection** | [`cli/`](cli/) | A hybrid **AST + regex** static-analysis engine over 11 languages, with cross-language usage-awareness, **dependency + lockfile scanning**, **reachability ranking**, and **call-site-specific fixes**, that scores risk and produces a NIST-aligned migration plan. **100% precision on the labeled [benchmark](benchmark/)** (18 files) and **100% recall on 50 seeded cases** — see [methodology](benchmark/RESULTS.md). |
63
+ | **2. Detection** | [`cli/`](cli/) | A hybrid **AST + regex** static-analysis engine over 11 languages, with cross-language usage-awareness, **dependency + lockfile scanning**, **reachability ranking**, and **call-site-specific fixes**, that scores risk and produces a NIST-aligned migration plan. **100% precision on the labeled [benchmark](benchmark/)** (18 files), **100% recall on 50 seeded cases**, and **93% precision (95% CI 86–97%) on a random, hand-labeled sample of 100 findings in real PyPI packages**, and **88% recall (95% CI 71–96%) on a held-out random sample of real files with every usage labeled by hand** — see [methodology](benchmark/RESULTS.md), [real-code precision](benchmark/RESULTS-precision.md) and [real-code recall](benchmark/README.md#recall-on-real-code-recall_samplepy). |
63
64
  | **3. Fix** | [`pqc/`](pqc/) | A from-scratch **lattice (LWE) key-encapsulation mechanism** — the math behind CRYSTALS-Kyber / ML-KEM — so the recommended fix is runnable and provable. |
64
65
 
65
66
  The detection layer ships through three surfaces that share **one** engine:
@@ -443,7 +444,13 @@ construction — 50 real quantum-vulnerable API calls (many idiomatic variants
443
444
  per family, 7 languages) that must be detected, plus 50 comment/string decoys
444
445
  that must not be. Latest run: **100% recall, 100% mutation precision**
445
446
  ([RESULTS-seeded.md](benchmark/RESULTS-seeded.md)), enforced by
446
- `tests/test_seeded.py`. Honest limits are documented in
447
+ `tests/test_seeded.py`. Seeded cases only test the patterns someone thought to
448
+ write, so recall is also measured on **real code**: random files from 37 pinned
449
+ PyPI packages, every quantum-vulnerable usage labeled by hand before scanning. The
450
+ first sample found 68%, and its misses drove the fixes; a held-out sample labeled
451
+ afterwards finds **88% (95% CI 71–96%)**
452
+ ([how, and every miss](benchmark/README.md#recall-on-real-code-recall_samplepy)).
453
+ Honest limits are documented in
447
454
  [benchmark/README.md](benchmark/README.md) — these are regression benchmarks, not
448
455
  a claim of perfection on arbitrary code.
449
456
 
@@ -459,7 +466,7 @@ badge from an actual scan — in [docs/EXAMPLES.md](docs/EXAMPLES.md).
459
466
 
460
467
  ### Real-world scan: paramiko (the SSH library)
461
468
 
462
- Run against a shallow clone of [`paramiko/paramiko`](https://github.com/paramiko/paramiko)
469
+ Run in July 2026 against a shallow clone of [`paramiko/paramiko`](https://github.com/paramiko/paramiko)
463
470
  — the SSH implementation behind Ansible, Fabric, and much of the Python ecosystem.
464
471
  SSH key exchange leans on RSA, ECDSA, and Diffie-Hellman, all broken by Shor's
465
472
  algorithm, which makes it a textbook "harvest now, decrypt later" target:
@@ -497,9 +504,10 @@ python benchmark/realworld.py
497
504
  |---|---|
498
505
  | Packages scanned | **37** |
499
506
  | Packages with ≥1 finding | **32 (86%)** |
500
- | Python files analyzed | **10,938** |
501
- | Total findings | **5,512** — **4,083 HIGH-risk** |
502
- | Most common families | `ecc` ×1,709, `sha256` ×956, `rsa` ×770, `sha1` ×576, `dsa` ×355, `md5` ×351 |
507
+ | Python files analyzed | **11,275** |
508
+ | Total findings | **5,609** — **4,236 HIGH-risk** |
509
+ | Most common families | `ecc` ×1,831, `sha256` ×1,013, `rsa` ×796, `sha1` ×577, `md5` ×359, `dsa` ×353 |
510
+ | Run | 2026-10-28, scanner 0.3.1 (latest release of each package) |
503
511
 
504
512
  Every finding is a concrete `file:line` an auditor can open — e.g. Diffie-Hellman
505
513
  in `twisted/conch/ssh/transport.py`, MD5 in `requests/auth.py` (HTTP Digest), and
@@ -678,7 +686,7 @@ jobs:
678
686
  | `output` | `quantumsafe.sarif` | Where to write the SARIF report |
679
687
  | `exclude` | *(none)* | Comma-separated globs to skip |
680
688
  | `fail-on-high` | `"false"` | Exit non-zero if any HIGH finding is present |
681
- | `version` | *(latest)* | Pin `quantumsafe-scan`, e.g. `0.2.0` |
689
+ | `version` | *(latest)* | Pin `quantumsafe-scan`, e.g. `0.3.2` |
682
690
 
683
691
  Pin to a released tag rather than `@main` once one exists — `@main` moves under
684
692
  you, which is the same class of problem as an unpinned linter.
@@ -811,7 +819,7 @@ docker compose up --build
811
819
 
812
820
  ```bash
813
821
  pip install -r requirements-dev.txt
814
- pytest -q # 545 tests; in-memory DB, no setup
822
+ pytest -q # 584 tests; in-memory DB, no setup
815
823
  ```
816
824
 
817
825
  Seed a demo account so the dashboard is populated:
@@ -926,6 +934,15 @@ organization — scheduled re-scans with drift alerts, multi-repo/org dashboards
926
934
  SSO, and audit-ready CBOM history for compliance. Those are operational features,
927
935
  not gates on the core detection, which is the part that should always be open.
928
936
 
937
+ ## Citing
938
+
939
+ Every release is archived on Zenodo. To cite QuantumSafe, use
940
+ [10.5281/zenodo.23843488](https://doi.org/10.5281/zenodo.23843488), which always
941
+ resolves to the newest version; v0.3.1 on its own is
942
+ [10.5281/zenodo.23843498](https://doi.org/10.5281/zenodo.23843498). GitHub's
943
+ "Cite this repository" button reads the same details from
944
+ [CITATION.cff](CITATION.cff).
945
+
929
946
  ## License
930
947
 
931
948
  MIT — see [LICENSE](LICENSE).
@@ -5,4 +5,4 @@ pyproject.toml) so both the standalone CLI and the Flask backend share one copy
5
5
  of the detection logic.
6
6
  """
7
7
 
8
- __version__ = "0.3.0"
8
+ __version__ = "0.3.2"
@@ -136,19 +136,26 @@ RULES: list[Rule] = [
136
136
  r"\brsa[\s_\-]?4096\b|\b4096\b\s*(?:bit)?\s*rsa\b"),
137
137
  _r("rsa", "RSA", RISK_HIGH,
138
138
  "RSA public-key cryptography is broken by Shor's algorithm.",
139
- r"\bRSA\b|generate_private_key.*rsa|crypto\.generateKeyPair(?:Sync)?\(\s*['\"]rsa['\"]|rsa\.GenerateKey|OpenSSL::PKey::RSA|RSACryptoServiceProvider|openssl_pkey_new|RsaKeyParameters"),
139
+ r"\bRSA\b|generate_private_key.*rsa|crypto\.generateKeyPair(?:Sync)?\(\s*['\"]rsa['\"]|rsa\.GenerateKey|OpenSSL::PKey::RSA|RSACryptoServiceProvider|openssl_pkey_new|RsaKeyParameters"
140
+ # Key classes and modules: RSAKey (paramiko), RSAPrivateKey / RSAPublicKey
141
+ # (cryptography), paramiko.rsakey. Found missing by the recall sample.
142
+ r"|\bRSA(?:Private|Public)?Key"),
140
143
  _r("ecc", "ECDSA", RISK_HIGH,
141
144
  "ECDSA signatures are broken by Shor's algorithm.",
142
- r"\bECDSA\b|ecdsa\b"),
145
+ r"\bECDSA\b|ecdsa\b|\bECDSA(?:Private|Public)?Key"),
143
146
  _r("ecc", "ECDH", RISK_HIGH,
144
147
  "ECDH key exchange is broken by Shor's algorithm.",
145
148
  r"\bECDH\b|ecdh\b"),
146
149
  _r("ecc", "ECC", RISK_HIGH,
147
150
  "Elliptic-curve cryptography is broken by Shor's algorithm.",
148
- r"\bECC\b|elliptic[\s_\-]?curve|EllipticCurve|ec\.generate_private_key|crypto/ecdsa|secp256[rk]1|prime256v1|NIST P-256"),
151
+ r"\bECC\b|elliptic[\s_\-]?curve|EllipticCurve|ec\.generate_private_key|crypto/ecdsa|secp256[rk]1|prime256v1|NIST P-256"
152
+ # Curve25519 / Curve448 in any spelling: X25519PrivateKey, Ed25519Key,
153
+ # import_x25519_private_key, ssh-ed25519. Not preceded by a letter or
154
+ # digit, so an underscore-joined name still counts.
155
+ r"|(?<![a-z0-9])(?:x|ed)(?:25519|448)(?![0-9])|\bEC(?:Private|Public)Key"),
149
156
  _r("dsa", "DSA", RISK_HIGH,
150
157
  "DSA signatures are broken by Shor's algorithm.",
151
- r"\bDSA\b|dsa\.generate_private_key|crypto/dsa"),
158
+ r"\bDSA\b|dsa\.generate_private_key|crypto/dsa|\bDSA(?:Private|Public)?Key|\bDSSKey\b"),
152
159
  _r("dh", "Diffie-Hellman", RISK_HIGH,
153
160
  "Classic Diffie-Hellman key exchange is broken by Shor's algorithm.",
154
161
  r"\bDiffie[\s\-]?Hellman\b|\bDH\b|dh\.generate_parameters|DHParameterSpec|crypto/dh"),
@@ -160,12 +167,18 @@ RULES: list[Rule] = [
160
167
  r"\bSHA[\s\-_]?1\b|hashlib\.sha1|sha1\(|sha1_file|crypto\.createHash\(\s*['\"]sha1['\"]|MessageDigest\.getInstance\(\s*['\"]SHA-?1['\"]|Digest::SHA1"),
161
168
 
162
169
  # ---- MEDIUM ----
170
+ # The bare protocol names must start their own token: inside an identifier
171
+ # they are almost always a flag that turns the protocol OFF (OP_NO_SSLv3,
172
+ # OP_NO_TLSv1, _OP_NO_SSLv2_OR_SSLv3), which is the mitigation, not exposure.
173
+ # A random sample of real-world findings showed every such hit was a false
174
+ # positive (benchmark/RESULTS-precision.md). Selectors keep explicit forms.
163
175
  _r("tls_old", "TLS 1.0", RISK_MEDIUM,
164
176
  "TLS 1.0 is deprecated and uses quantum-vulnerable key exchange.",
165
- r"TLSv1(?:\.0)?\b|PROTOCOL_TLSv1\b|TLS1_0|SSLv3|TLSv1_method"),
177
+ r"(?<!\w)(?:TLSv1(?:\.0)?|SSLv3)\b|PROTOCOL_(?:TLSv1|SSLv3)\b|(?<!NO_)TLS1_0\b"
178
+ r"|(?:TLSv1|SSLv3)_method\b"),
166
179
  _r("tls_old", "TLS 1.1", RISK_MEDIUM,
167
180
  "TLS 1.1 is deprecated and uses quantum-vulnerable key exchange.",
168
- r"TLSv1\.1\b|PROTOCOL_TLSv1_1\b|TLS1_1|TLSv1_1_method"),
181
+ r"(?<!\w)TLSv1(?:\.1|_1)\b|PROTOCOL_TLSv1_1\b|(?<!NO_)TLS1_1\b|TLSv1_1_method\b"),
169
182
  _r("3des", "3DES / Triple DES", RISK_MEDIUM,
170
183
  "3DES is deprecated; Grover's algorithm halves its effective strength.",
171
184
  r"\b3DES\b|Triple[\s_\-]?DES\b|DESede|DES3|TripleDES|des_ede3"),
@@ -608,6 +621,86 @@ def _string_arg_scan(orig_lines: list[str], masked_lines: list[str],
608
621
  return findings
609
622
 
610
623
 
624
+ # --------------------------------------------------------------------------- #
625
+ # Identifier literals
626
+ # --------------------------------------------------------------------------- #
627
+ #
628
+ # Some string literals are not prose but the algorithm's own wire name: SSH key
629
+ # and kex types ("ssh-rsa", "rsa-sha2-256", "ecdsa-sha2-nistp256"), JOSE values
630
+ # ("kty": "RSA", "alg": "RS256", "crv": "P-256"), curve names. Masking strings
631
+ # hid every one of them (the recall sample on real code missed paramiko's key
632
+ # negotiation and PyJWT's JWKs this way). A literal counts only when its whole
633
+ # content is one of these identifiers, so a sentence that mentions RSA stays out.
634
+
635
+ _ID_LITERALS: list[tuple[re.Pattern, str]] = [
636
+ (re.compile(r"ssh-rsa(?:-cert-v01@openssh\.com)?|rsa-sha2-(?:256|512)(?:-cert-v01@openssh\.com)?"
637
+ r"|(?i:rsa)|RS(?:256|384|512)|PS(?:256|384|512)|RSA-OAEP(?:-256)?|RSA1_5"), "rsa"),
638
+ (re.compile(r"ecdsa-sha2-nistp(?:256|384|521)(?:-cert-v01@openssh\.com)?|ssh-ed(?:25519|448)(?:-cert-v01@openssh\.com)?"
639
+ r"|(?i:ecdsa|ecdh)|EC|ES(?:256K?|384|512)|EdDSA|(?i:ed25519|ed448|x25519|x448)"
640
+ r"|ECDH-ES(?:\+A(?:128|192|256)KW)?|P-(?:256|384|521)|secp(?:256[rk]1|384r1|521r1)|prime256v1"
641
+ r"|ecdh-sha2-nistp(?:256|384|521)|curve25519-sha256(?:@libssh\.org)?|curve448-sha512"), "ecc"),
642
+ (re.compile(r"ssh-dss|(?i:dsa)"), "dsa"),
643
+ (re.compile(r"diffie-hellman-group[\w-]*|DH|ffdhe(?:2048|3072|4096|6144|8192)"), "dh"),
644
+ (re.compile(r"(?i:md5)|MD5-sess|hmac-md5(?:-96)?"), "md5"),
645
+ (re.compile(r"(?i:sha-?1)|SHA1-sess|hmac-sha1(?:-96)?"), "sha1"),
646
+ ]
647
+ _PY_STRING_PREFIX = re.compile(r"^[rRbBuU]{0,2}(['\"])")
648
+ _QUOTED_ID_RE = re.compile(r"(['\"`])([A-Za-z0-9@._+\-]{2,48})\1")
649
+
650
+
651
+ def _id_literal_family(value: str) -> str | None:
652
+ for pattern, family in _ID_LITERALS:
653
+ if pattern.fullmatch(value):
654
+ return family
655
+ return None
656
+
657
+
658
+ def _id_literal_finding(family: str, rel_path: str, lineno: int, snippet: str) -> Finding:
659
+ algo, risk, why = _ALGO_INFO[family]
660
+ return Finding(rel_path, lineno, algo, risk, why, family, snippet=snippet, confidence="high")
661
+
662
+
663
+ def _id_literal_scan_python(source: str, rel_path: str, lines: list[str]) -> list[Finding]:
664
+ findings: list[Finding] = []
665
+ try:
666
+ for tok in tokenize.generate_tokens(io.StringIO(source).readline):
667
+ if tok.type != tokenize.STRING or not _PY_STRING_PREFIX.match(tok.string):
668
+ continue # f-strings and multi-part tokens are never a bare identifier
669
+ try:
670
+ value = ast.literal_eval(tok.string)
671
+ except (ValueError, SyntaxError):
672
+ continue
673
+ if isinstance(value, bytes):
674
+ value = value.decode("latin-1")
675
+ if not isinstance(value, str) or "\n" in value:
676
+ continue
677
+ family = _id_literal_family(value)
678
+ if family:
679
+ row = tok.start[0]
680
+ snippet = lines[row - 1].strip() if 0 < row <= len(lines) else ""
681
+ findings.append(_id_literal_finding(family, rel_path, row, snippet))
682
+ except (tokenize.TokenError, IndentationError, SyntaxError, ValueError):
683
+ pass
684
+ return findings
685
+
686
+
687
+ def _id_literal_scan_generic(orig_lines: list[str], masked_lines: list[str],
688
+ lang: str, rel_path: str) -> list[Finding]:
689
+ findings: list[Finding] = []
690
+ for idx, orig in enumerate(orig_lines):
691
+ masked = masked_lines[idx] if idx < len(masked_lines) else orig
692
+ if not masked.strip():
693
+ continue # the whole line was comment
694
+ cut = _comment_start(orig, lang)
695
+ for m in _QUOTED_ID_RE.finditer(orig):
696
+ if cut is not None and m.start() >= cut:
697
+ break
698
+ family = _id_literal_family(m.group(2))
699
+ if family:
700
+ findings.append(_id_literal_finding(family, rel_path, idx + 1, orig.strip()))
701
+ return findings
702
+
703
+
611
704
  def _comment_start(line: str, lang: str) -> int | None:
612
705
  """Column where a line comment begins, or None. Used to reject trailing-comment
613
706
  matches without a full re-lex (the protocol tokens are the only consumer)."""
@@ -642,6 +735,8 @@ def _regex_scan(match_lines: list[str], orig_lines: list[str],
642
735
  line = raw.rstrip("\n")
643
736
  if not line.strip() or _is_comment_line(line, lang):
644
737
  continue
738
+ if lang == "python" and _PY_TEST_NAME_RE.match(line):
739
+ continue # "def test_md5_digest(...)" names a test; it selects nothing
645
740
  orig = orig_lines[i - 1].strip() if i - 1 < len(orig_lines) else line.strip()
646
741
  for rule in RULES:
647
742
  if rule.languages and lang not in rule.languages:
@@ -710,6 +805,8 @@ def scan_file(abs_path: str, rel_path: str, mask_strings: bool = True,
710
805
  findings = _regex_scan(match_lines, lines, lang, rel_path)
711
806
  if lang == "python":
712
807
  findings += _ast_scan_python(source, rel_path, lines)
808
+ if mask_strings:
809
+ findings += _id_literal_scan_python(source, rel_path, lines)
713
810
  if taint:
714
811
  # Interprocedural data-flow pass: crypto reached through wrappers.
715
812
  from .taint import taint_scan_python
@@ -718,6 +815,26 @@ def scan_file(abs_path: str, rel_path: str, mask_strings: bool = True,
718
815
  # Recover genuine crypto usages whose algorithm was named inside a
719
816
  # (now-masked) string literal — e.g. getInstance("SHA-1").
720
817
  findings += _string_arg_scan(lines, match_lines, lang, rel_path)
818
+ findings += _id_literal_scan_generic(lines, match_lines, lang, rel_path)
819
+
820
+ # A post-quantum hybrid (ML-KEM-768 + X25519, X25519Kyber768) is the
821
+ # migration target, not exposure: its classical half is there on purpose.
822
+ # Flagging it HIGH would tell users to replace the fix. The TLS scanner
823
+ # already treats X25519MLKEM768 as quantum-safe; the code scanner agrees.
824
+ if findings:
825
+ findings = [
826
+ f for f in findings
827
+ if not (f.family == "ecc" and 0 < f.line_number <= len(lines)
828
+ and _PQ_HYBRID_RE.search(lines[f.line_number - 1]))
829
+ ]
830
+ # Identifier literals in an algorithm-disable list name what is turned OFF
831
+ # (paramiko's disabled_algorithms), the same mitigation OP_NO_* flags are.
832
+ if findings:
833
+ findings = [
834
+ f for f in findings
835
+ if not (0 < f.line_number <= len(lines)
836
+ and _DISABLE_RE.search(lines[f.line_number - 1]))
837
+ ]
721
838
 
722
839
  # Honor inline suppressions: a line containing "quantumsafe: ignore".
723
840
  if findings:
@@ -728,6 +845,10 @@ def scan_file(abs_path: str, rel_path: str, mask_strings: bool = True,
728
845
  return _dedupe(findings)
729
846
 
730
847
 
848
+ _PY_TEST_NAME_RE = re.compile(r"\s*(?:async\s+def|def|class)\s+(?:test_?|Test)\w*\s*[(:]")
849
+ _PQ_HYBRID_RE = re.compile(r"ml[-_]?kem|kyber", re.IGNORECASE)
850
+ _DISABLE_RE = re.compile(r"\bdisabled?_(?:algorithms|algos|ciphers|kex|keys|macs)\b", re.IGNORECASE)
851
+
731
852
  # Inline suppression marker, e.g. key = rsa.generate(...) # quantumsafe: ignore
732
853
  _SUPPRESS_RE = re.compile(r"quantumsafe:\s*ignore", re.IGNORECASE)
733
854
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "quantumsafe-scan"
7
- version = "0.3.0"
7
+ version = "0.3.2"
8
8
  description = "Scan codebases and dependencies for quantum-vulnerable cryptography and generate a NIST-aligned migration plan (SARIF + CycloneDX CBOM)."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantumsafe-scan
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Scan codebases and dependencies for quantum-vulnerable cryptography and generate a NIST-aligned migration plan (SARIF + CycloneDX CBOM).
5
5
  Author: QuantumSafe
6
6
  License: MIT
@@ -39,11 +39,12 @@ Dynamic: license-file
39
39
  <img src="https://img.shields.io/pypi/pyversions/quantumsafe-scan?style=flat-square&logo=python&logoColor=white" alt="Python versions">
40
40
  <a href="https://github.com/Danny-397/Quantum-Safe-Scan/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/Danny-397/Quantum-Safe-Scan/ci.yml?branch=main&style=flat-square&logo=githubactions&logoColor=white&label=CI" alt="CI status"></a>
41
41
  <a href="https://github.com/Danny-397/Quantum-Safe-Scan/tags"><img src="https://img.shields.io/github/v/tag/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github&label=version&color=5b73e8" alt="Latest version"></a>
42
- <a href="https://github.com/Danny-397/Quantum-Safe-Scan/stargazers"><img src="https://img.shields.io/github/stars/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github" alt="Stars"></a>
42
+ <a href="https://github.com/Danny-397/Quantum-Safe-Scan"><img src="https://img.shields.io/github/stars/Danny-397/Quantum-Safe-Scan?style=flat-square&logo=github" alt="Stars"></a>
43
43
  <img src="https://img.shields.io/github/last-commit/Danny-397/Quantum-Safe-Scan?style=flat-square&color=555" alt="Last commit">
44
44
  <img src="https://img.shields.io/github/license/Danny-397/Quantum-Safe-Scan?style=flat-square&color=3fb950" alt="License: MIT">
45
+ <a href="https://doi.org/10.5281/zenodo.23843488"><img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.23843488-5b73e8?style=flat-square" alt="DOI 10.5281/zenodo.23843488"></a>
45
46
  <br>
46
- <img src="https://img.shields.io/badge/tests-545%20passing-3fb950?style=flat-square&logo=pytest&logoColor=white" alt="545 tests passing">
47
+ <img src="https://img.shields.io/badge/tests-584%20passing-3fb950?style=flat-square&logo=pytest&logoColor=white" alt="584 tests passing">
47
48
  <img src="https://img.shields.io/badge/benchmark-100%25%20precision-3fb950?style=flat-square" alt="100% precision on benchmark">
48
49
  <img src="https://img.shields.io/badge/SARIF%202.1.0-schema--validated-3fb950?style=flat-square" alt="SARIF schema-validated">
49
50
  <img src="https://img.shields.io/badge/NIST-FIPS%20203%2F204%2F205-5b73e8?style=flat-square" alt="NIST FIPS 203/204/205">
@@ -91,7 +92,7 @@ solution:
91
92
  | Layer | Module | What it does |
92
93
  |-------|--------|--------------|
93
94
  | **1. Attack** | [`quantum/`](quantum/) | Shor's and Grover's algorithms in **Qiskit**, run on a quantum simulator. At simulator scale Shor factors a small number and reconstructs a toy RSA key — an educational demonstration of *why* RSA/ECC are rated HIGH (not a break of real key sizes). |
94
- | **2. Detection** | [`cli/`](cli/) | A hybrid **AST + regex** static-analysis engine over 11 languages, with cross-language usage-awareness, **dependency + lockfile scanning**, **reachability ranking**, and **call-site-specific fixes**, that scores risk and produces a NIST-aligned migration plan. **100% precision on the labeled [benchmark](benchmark/)** (18 files) and **100% recall on 50 seeded cases** — see [methodology](benchmark/RESULTS.md). |
95
+ | **2. Detection** | [`cli/`](cli/) | A hybrid **AST + regex** static-analysis engine over 11 languages, with cross-language usage-awareness, **dependency + lockfile scanning**, **reachability ranking**, and **call-site-specific fixes**, that scores risk and produces a NIST-aligned migration plan. **100% precision on the labeled [benchmark](benchmark/)** (18 files), **100% recall on 50 seeded cases**, and **93% precision (95% CI 86–97%) on a random, hand-labeled sample of 100 findings in real PyPI packages**, and **88% recall (95% CI 71–96%) on a held-out random sample of real files with every usage labeled by hand** — see [methodology](benchmark/RESULTS.md), [real-code precision](benchmark/RESULTS-precision.md) and [real-code recall](benchmark/README.md#recall-on-real-code-recall_samplepy). |
95
96
  | **3. Fix** | [`pqc/`](pqc/) | A from-scratch **lattice (LWE) key-encapsulation mechanism** — the math behind CRYSTALS-Kyber / ML-KEM — so the recommended fix is runnable and provable. |
96
97
 
97
98
  The detection layer ships through three surfaces that share **one** engine:
@@ -475,7 +476,13 @@ construction — 50 real quantum-vulnerable API calls (many idiomatic variants
475
476
  per family, 7 languages) that must be detected, plus 50 comment/string decoys
476
477
  that must not be. Latest run: **100% recall, 100% mutation precision**
477
478
  ([RESULTS-seeded.md](benchmark/RESULTS-seeded.md)), enforced by
478
- `tests/test_seeded.py`. Honest limits are documented in
479
+ `tests/test_seeded.py`. Seeded cases only test the patterns someone thought to
480
+ write, so recall is also measured on **real code**: random files from 37 pinned
481
+ PyPI packages, every quantum-vulnerable usage labeled by hand before scanning. The
482
+ first sample found 68%, and its misses drove the fixes; a held-out sample labeled
483
+ afterwards finds **88% (95% CI 71–96%)**
484
+ ([how, and every miss](benchmark/README.md#recall-on-real-code-recall_samplepy)).
485
+ Honest limits are documented in
479
486
  [benchmark/README.md](benchmark/README.md) — these are regression benchmarks, not
480
487
  a claim of perfection on arbitrary code.
481
488
 
@@ -491,7 +498,7 @@ badge from an actual scan — in [docs/EXAMPLES.md](docs/EXAMPLES.md).
491
498
 
492
499
  ### Real-world scan: paramiko (the SSH library)
493
500
 
494
- Run against a shallow clone of [`paramiko/paramiko`](https://github.com/paramiko/paramiko)
501
+ Run in July 2026 against a shallow clone of [`paramiko/paramiko`](https://github.com/paramiko/paramiko)
495
502
  — the SSH implementation behind Ansible, Fabric, and much of the Python ecosystem.
496
503
  SSH key exchange leans on RSA, ECDSA, and Diffie-Hellman, all broken by Shor's
497
504
  algorithm, which makes it a textbook "harvest now, decrypt later" target:
@@ -529,9 +536,10 @@ python benchmark/realworld.py
529
536
  |---|---|
530
537
  | Packages scanned | **37** |
531
538
  | Packages with ≥1 finding | **32 (86%)** |
532
- | Python files analyzed | **10,938** |
533
- | Total findings | **5,512** — **4,083 HIGH-risk** |
534
- | Most common families | `ecc` ×1,709, `sha256` ×956, `rsa` ×770, `sha1` ×576, `dsa` ×355, `md5` ×351 |
539
+ | Python files analyzed | **11,275** |
540
+ | Total findings | **5,609** — **4,236 HIGH-risk** |
541
+ | Most common families | `ecc` ×1,831, `sha256` ×1,013, `rsa` ×796, `sha1` ×577, `md5` ×359, `dsa` ×353 |
542
+ | Run | 2026-10-28, scanner 0.3.1 (latest release of each package) |
535
543
 
536
544
  Every finding is a concrete `file:line` an auditor can open — e.g. Diffie-Hellman
537
545
  in `twisted/conch/ssh/transport.py`, MD5 in `requests/auth.py` (HTTP Digest), and
@@ -710,7 +718,7 @@ jobs:
710
718
  | `output` | `quantumsafe.sarif` | Where to write the SARIF report |
711
719
  | `exclude` | *(none)* | Comma-separated globs to skip |
712
720
  | `fail-on-high` | `"false"` | Exit non-zero if any HIGH finding is present |
713
- | `version` | *(latest)* | Pin `quantumsafe-scan`, e.g. `0.2.0` |
721
+ | `version` | *(latest)* | Pin `quantumsafe-scan`, e.g. `0.3.2` |
714
722
 
715
723
  Pin to a released tag rather than `@main` once one exists — `@main` moves under
716
724
  you, which is the same class of problem as an unpinned linter.
@@ -843,7 +851,7 @@ docker compose up --build
843
851
 
844
852
  ```bash
845
853
  pip install -r requirements-dev.txt
846
- pytest -q # 545 tests; in-memory DB, no setup
854
+ pytest -q # 584 tests; in-memory DB, no setup
847
855
  ```
848
856
 
849
857
  Seed a demo account so the dashboard is populated:
@@ -958,6 +966,15 @@ organization — scheduled re-scans with drift alerts, multi-repo/org dashboards
958
966
  SSO, and audit-ready CBOM history for compliance. Those are operational features,
959
967
  not gates on the core detection, which is the part that should always be open.
960
968
 
969
+ ## Citing
970
+
971
+ Every release is archived on Zenodo. To cite QuantumSafe, use
972
+ [10.5281/zenodo.23843488](https://doi.org/10.5281/zenodo.23843488), which always
973
+ resolves to the newest version; v0.3.1 on its own is
974
+ [10.5281/zenodo.23843498](https://doi.org/10.5281/zenodo.23843498). GitHub's
975
+ "Cite this repository" button reads the same details from
976
+ [CITATION.cff](CITATION.cff).
977
+
961
978
  ## License
962
979
 
963
980
  MIT — see [LICENSE](LICENSE).
@@ -39,6 +39,7 @@ tests/test_remediation.py
39
39
  tests/test_scanner.py
40
40
  tests/test_schema.py
41
41
  tests/test_scorer.py
42
+ tests/test_security_hardening.py
42
43
  tests/test_seeded.py
43
44
  tests/test_taint.py
44
45
  tests/test_tlsscan.py
@@ -282,3 +282,106 @@ def test_repo_url_validation_rejects_bad_urls(bad_url):
282
282
 
283
283
  def test_repo_url_validation_accepts_good_url():
284
284
  assert _validate_repo_url("https://github.com/org/app") == "https://github.com/org/app"
285
+
286
+
287
+ # ---- TLS: disable flags are the mitigation, not exposure -------------------
288
+ # Every tls_old finding in a random sample of real-world findings was one of
289
+ # these (benchmark/RESULTS-precision.md): OP_NO_* flags that turn the old
290
+ # protocol off. They must stay silent, and real selections must still fire.
291
+
292
+ @pytest.mark.parametrize("line", [
293
+ "ctx.options |= ssl.OP_NO_SSLv3 | ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1\n",
294
+ 'OP_NO_SSLv3 = getattr(_ssl, "OP_NO_SSLv3", 0)\n',
295
+ " ssl.TLSVersion.TLSv1_2: _OP_NO_SSLv2_OR_SSLv3 | _OP_NO_TLSv1_3,\n",
296
+ ])
297
+ def test_tls_disable_flags_are_not_findings(tmp_path, line):
298
+ _write(tmp_path, "tls.py", "import ssl\n" + line)
299
+ assert not [f for f in scan_path(str(tmp_path)) if f.family == "tls_old"]
300
+
301
+
302
+ @pytest.mark.parametrize("line, label", [
303
+ ("ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)\n", "TLS 1.0"),
304
+ ("ctx = SSL.Context(SSL.SSLv3_METHOD)\n", "TLS 1.0"),
305
+ ("ctx.minimum_version = ssl.TLSVersion.TLSv1\n", "TLS 1.0"),
306
+ ("ctx.minimum_version = ssl.TLSVersion.TLSv1_1\n", "TLS 1.1"),
307
+ ])
308
+ def test_tls_old_selections_are_still_found(tmp_path, line, label):
309
+ _write(tmp_path, "tls.py", "import ssl\n" + line)
310
+ algos = {f.algorithm for f in scan_path(str(tmp_path)) if f.family == "tls_old"}
311
+ assert label in algos
312
+
313
+
314
+ # ---- Recall fixes from the real-code recall sample (benchmark/RESULTS-recall*.md) ----
315
+
316
+ def _families_by_line(tmp_path, name, content):
317
+ _write(tmp_path, name, content)
318
+ out = {}
319
+ for f in scan_path(str(tmp_path)):
320
+ out.setdefault(f.line_number, set()).add(f.family)
321
+ return out
322
+
323
+
324
+ @pytest.mark.parametrize("line, family", [
325
+ ("from paramiko.rsakey import RSAKey", "rsa"),
326
+ ("k = RSAKey.from_private_key_file(path)", "rsa"),
327
+ ("def load(k: RSAPrivateKey): ...", "rsa"),
328
+ ("from paramiko.ecdsakey import ECDSAKey", "ecc"),
329
+ ("k = Ed25519Key.from_private_key_file(path)", "ecc"),
330
+ ("from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey", "ecc"),
331
+ ("k = DH.import_x25519_private_key(data)", "ecc"),
332
+ ("k = DSSKey(filename=path)", "dsa"),
333
+ ])
334
+ def test_key_classes_and_curve25519_are_found(tmp_path, line, family):
335
+ assert family in _families_by_line(tmp_path, "k.py", line + "\n").get(1, set())
336
+
337
+
338
+ @pytest.mark.parametrize("line, family", [
339
+ ('if keytype == "ssh-rsa":', "rsa"),
340
+ ('opts.key_types = ("rsa-sha2-512",)', "rsa"),
341
+ ('jwk = {"kty": "RSA", "n": n}', "rsa"),
342
+ ('token = jwt.encode(payload, key, algorithm="ES256")', "ecc"),
343
+ ('key = ECC.generate(curve="P-256")', "ecc"),
344
+ ('kex = "diffie-hellman-group14-sha1"', "dh"),
345
+ ('opts.digests = ("hmac-md5-96",)', "md5"),
346
+ ])
347
+ def test_identifier_literals_are_found(tmp_path, line, family):
348
+ assert family in _families_by_line(tmp_path, "s.py", line + "\n").get(1, set())
349
+
350
+
351
+ @pytest.mark.parametrize("line", [
352
+ 'log.info("falling back to RSA for this host")', # prose: not a bare identifier
353
+ 'raise ValueError("ECDSA keys are not supported")',
354
+ 'name = "rsa.key"', # a filename, not the algorithm
355
+ ])
356
+ def test_prose_strings_stay_out(tmp_path, line):
357
+ assert not _families_by_line(tmp_path, "p.py", line + "\n")
358
+
359
+
360
+ def test_identifier_literals_in_other_languages(tmp_path):
361
+ lines = _families_by_line(tmp_path, "a.js",
362
+ 'const alg = "RS256";\n// const old = "ssh-rsa";\n')
363
+ assert "rsa" in lines.get(1, set())
364
+ assert 2 not in lines
365
+
366
+
367
+ @pytest.mark.parametrize("line", [
368
+ "suite = HPKE(KEM.MLKEM768_X25519)",
369
+ "sk = MLKEM768X25519PrivateKey(mlkem_sk, x25519_sk)",
370
+ 'group = "X25519MLKEM768"',
371
+ ])
372
+ def test_pq_hybrids_are_not_flagged_as_ecc(tmp_path, line):
373
+ assert "ecc" not in _families_by_line(tmp_path, "h.py", line + "\n").get(1, set())
374
+
375
+
376
+ def test_disabled_algorithm_lists_are_not_findings(tmp_path):
377
+ lines = _families_by_line(
378
+ tmp_path, "t.py",
379
+ 'Transport(sock, disabled_algorithms={"keys": ["rsa-sha2-512"], "macs": ["hmac-md5"]})\n')
380
+ assert not lines
381
+
382
+
383
+ def test_test_names_are_not_findings(tmp_path):
384
+ lines = _families_by_line(tmp_path, "test_x.py",
385
+ "def test_sign_ed25519_key():\n pass\n"
386
+ "class TestMD5Digest:\n pass\n")
387
+ assert not lines
@@ -0,0 +1,124 @@
1
+ """Regression tests for the 2026-10-26 security review of the backend.
2
+
3
+ Each test pins one fix:
4
+ * reset links are single-use (they were valid for their full hour, reusable);
5
+ * a zip that would expand past the caps is refused before anything is written;
6
+ * oversized uploads are rejected at the door with a JSON 413;
7
+ * rate limits are per visitor (behind Render's proxy they were site-wide);
8
+ * the app refuses to start on Render with the public default secret;
9
+ * passwords past bcrypt's 72-byte limit still register and log in (bcrypt 5
10
+ raises on them where bcrypt 4 truncated).
11
+ """
12
+
13
+ import io
14
+ import re
15
+ import uuid
16
+ import zipfile
17
+
18
+ import auth
19
+ import pytest
20
+ import scanner_service
21
+ from app import create_app
22
+ from config import DEV_SECRET, Config
23
+
24
+
25
+ def _register(client, password="password123"):
26
+ email = f"user-{uuid.uuid4().hex[:8]}@test.com"
27
+ client.post("/api/v1/auth/register",
28
+ json={"email": email, "password": password, "accept_terms": True})
29
+ return email
30
+
31
+
32
+ def _reset_token(client, monkeypatch, email):
33
+ sent = []
34
+ monkeypatch.setattr(auth, "send_email", lambda subject, to, body: sent.append(body))
35
+ client.post("/api/v1/auth/forgot", json={"email": email})
36
+ return re.search(r"reset=(\S+)", sent[0]).group(1)
37
+
38
+
39
+ def test_reset_link_works_once(client, monkeypatch):
40
+ email = _register(client)
41
+ token = _reset_token(client, monkeypatch, email)
42
+
43
+ first = client.post("/api/v1/auth/reset", json={"token": token, "password": "new-password-1"})
44
+ assert first.status_code == 200
45
+ again = client.post("/api/v1/auth/reset", json={"token": token, "password": "new-password-2"})
46
+ assert again.status_code == 400
47
+
48
+ login = client.post("/api/v1/auth/login", json={"email": email, "password": "new-password-1"})
49
+ assert login.status_code == 200
50
+
51
+
52
+ def test_old_style_reset_token_is_rejected(client, app):
53
+ """A token carrying only the user id (the old format) must not verify."""
54
+ _register(client)
55
+ with app.app_context():
56
+ legacy = auth._serializer().dumps(1, salt=auth.RESET_SALT)
57
+ resp = client.post("/api/v1/auth/reset", json={"token": legacy, "password": "new-password-1"})
58
+ assert resp.status_code == 400
59
+
60
+
61
+ def _zip(files):
62
+ buf = io.BytesIO()
63
+ with zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) as zf:
64
+ for name, data in files.items():
65
+ zf.writestr(name, data)
66
+ return buf.getvalue()
67
+
68
+
69
+ def test_zip_that_expands_past_the_cap_is_refused(tmp_path, monkeypatch):
70
+ monkeypatch.setattr(scanner_service, "_MAX_EXTRACTED_BYTES", 1_000)
71
+ path = tmp_path / "bomb.zip"
72
+ path.write_bytes(_zip({"a.py": b"0" * 5_000})) # compresses to ~30 bytes
73
+ with pytest.raises(ValueError, match="expands past"):
74
+ scanner_service._safe_extract(str(path), str(tmp_path / "out"))
75
+ assert not (tmp_path / "out" / "a.py").exists()
76
+
77
+
78
+ def test_zip_with_too_many_files_is_refused(tmp_path, monkeypatch):
79
+ monkeypatch.setattr(scanner_service, "_MAX_ARCHIVE_FILES", 2)
80
+ path = tmp_path / "many.zip"
81
+ path.write_bytes(_zip({f"f{i}.py": b"x = 1\n" for i in range(3)}))
82
+ with pytest.raises(ValueError, match="more than"):
83
+ scanner_service._safe_extract(str(path), str(tmp_path / "out"))
84
+
85
+
86
+ def test_oversized_upload_gets_json_413(app):
87
+ app.config["MAX_CONTENT_LENGTH"] = 1_000
88
+ resp = app.test_client().post(
89
+ "/api/v1/scan", data={"file": (io.BytesIO(b"0" * 5_000), "big.zip")},
90
+ content_type="multipart/form-data")
91
+ assert resp.status_code == 413
92
+ assert "25 MB" in resp.get_json()["error"]
93
+
94
+
95
+ def test_rate_limits_are_per_visitor():
96
+ application = create_app(Config)
97
+ application.config["RATELIMIT_ENABLED"] = True
98
+ client = application.test_client()
99
+ a = {"CF-Connecting-IP": f"198.51.100.{uuid.uuid4().int % 250 + 1}"}
100
+ b = {"CF-Connecting-IP": "203.0.113.77"}
101
+ body = {"email": "nobody@test.com", "password": "wrong-password"}
102
+
103
+ codes = [client.post("/api/v1/auth/login", json=body, headers=a).status_code
104
+ for _ in range(21)]
105
+ assert codes[-1] == 429, "the 21st login from one visitor should be limited"
106
+ assert client.post("/api/v1/auth/login", json=body, headers=b).status_code == 401, (
107
+ "a different visitor must not inherit the first one's limit")
108
+
109
+
110
+ def test_refuses_to_start_on_render_with_the_default_secret(monkeypatch):
111
+ class Default(Config):
112
+ SECRET_KEY = DEV_SECRET
113
+ JWT_SECRET_KEY = DEV_SECRET
114
+
115
+ monkeypatch.setenv("RENDER", "true")
116
+ with pytest.raises(RuntimeError, match="must be set in production"):
117
+ create_app(Default)
118
+
119
+
120
+ def test_password_longer_than_72_bytes_registers_and_logs_in(client):
121
+ password = "é" * 50 # 100 bytes of UTF-8
122
+ email = _register(client, password=password)
123
+ login = client.post("/api/v1/auth/login", json={"email": email, "password": password})
124
+ assert login.status_code == 200