Generated from docs/SECURITY_AUDIT_INTERNAL.md. To save as PDF, use your browser's Print command.

ECRE-PQ security audit report (internal, standards-based)

Item Detail
Product ECRE-PQ (ecre_pq Python package, CLI, ledger node, deployment files)
Audit type Internal security audit, performed with AI assistance, open-source tools only
Standards used as criteria NIST FIPS 203, FIPS 204, FIPS 205; NIST SP 800-227; NIST IR 8547; OWASP ASVS 5.0 (Level 2); CWE Top 25 (2025); NIST SP 800-218 (SSDF); SLSA v1.0; ISO/IEC 27001:2022 Annex A (mapping)
Result No open Critical, High or Medium finding. 18 findings in total: 16 fixed or closed, 2 accepted with a documented reason (AUD-12, AUD-14).
Report date 5 December 2026
Repeatability Every automated check in this report runs in CI on each change to main and weekly.

What this report is, and what it is not. It is an internal audit: the checks were run by the project team against published standards, and every result can be reproduced with the commands in section 11. It is not a third-party audit and not a certification. No laboratory has validated the cryptographic modules under FIPS 140-3, and ISO/IEC 27001 certifies an organisation's management system, not a product, so the ISO table in section 8 is a mapping, not a certificate. Customers who need an independent review can request one; this report and the formal models are written to make that review fast.

ملخص بالعربية

خضع ECRE-PQ لتدقيق أمني داخلي وفق معايير دولية منشورة، باستخدام أدوات مفتوحة المصدر فقط. المعايير: NIST FIPS 203 وFIPS 204 وFIPS 205 (الخوارزميات ما بعد الكمومية)، وNIST SP 800-227 (استخدام آليات KEM)، وNIST IR 8547 (جدول الانتقال)، وOWASP ASVS 5.0 بالمستوى الثاني، وقائمة CWE Top 25 لعام 2025، وإطار تطوير البرمجيات الآمن NIST SP 800-218 (SSDF)، وSLSA، مع مطابقة لضوابط ISO/IEC 27001:2022 الملحق A.

شمل التدقيق: التحليل الثابت (ruff وbandit وsemgrep وmypy بالوضع الصارم)، وفحص الاعتماديات وسلسلة التوريد (pip-audit وOSV وتثبيت كل الأدوات والإجراءات بالـ hash)، وفحص الأسرار في كامل تاريخ المستودع (gitleaks)، والـ fuzzing الموجَّه (atheris) والخصائصي (Hypothesis)، والإثبات الرمزي للبروتوكول (Tamarin) وفحص نموذج السجل (TLA+/TLC)، ومراجعة يدوية مقابل نموذج التهديد.

النتيجة: لا توجد ثغرة مفتوحة بدرجة حرجة أو عالية أو متوسطة. من 18 ملاحظة أُصلحت أو أُغلقت 16، وقُبلت اثنتان مع سبب موثق. أهم إصلاح في هذه الجولة: منع إعادة تشغيل الملف المشفّر (AUD-07) عبر سجل للـ salt عند المستلم، وهو ما أثبتته Tamarin سابقاً كخاصية "المصادقة الحقنية".

هذا تدقيق داخلي، وليس تدقيقاً من طرف ثالث ولا شهادة اعتماد. وحدات التشفير غير معتمدة بـ FIPS 140-3، وشهادة ISO 27001 تُمنح للمؤسسات لا للمنتجات.

1. Scope

Item Version
Source main after PRs #1 to #17, plus the fixes in this report (about 2,500 lines in src/)
Components File encryption and signing (fileformat, signatures, keys, slhdsa), key vault and PKCS#11 custody (vault, custody), replay cache (replay), peer book, recovery ledger and SQLite store, HTTP ledger node (primary and follower), CLI, public API
Deployment files deploy/ (Docker, Caddy, Cloudflare Tunnel), scripts/build-liboqs.sh
CI .github/workflows/*.yml
Cryptographic backends pyca/cryptography 51.0.1 (bundled OpenSSL), liboqs 0.16.0 (commit 5a1a854b) through liboqs-python 0.16.0.2
Platforms tested Linux x86_64 and ARM64, macOS; Python 3.12 and 3.13

Out of scope: the static website (site/), the internals of OpenSSL and liboqs, hardware side channels, and the operating environment of any customer deployment.

2. Method

  1. Threat model first. Assets, attackers and trust boundaries are in docs/THREAT_MODEL.md. Every manual check below refers to it.
  2. Automated analysis with pinned open-source tools (section 3).
  3. Cryptographic conformance against FIPS 203/204/205, SP 800-227 and IR 8547 (section 4).
  4. Formal verification of the file protocol (Tamarin) and of the recovery ledger state machine (TLA+/TLC).
  5. Requirement-by-requirement review against OWASP ASVS 5.0 Level 2 (section 5) and the CWE Top 25 (section 6).
  6. Fix and re-test. Every fixed finding has a regression test.
  7. Process review against SSDF, SLSA and ISO/IEC 27001 Annex A (section 8).

Severity scale: Critical (breaks confidentiality, authenticity or funds directly), High, Medium, Low, Info.

3. Tools and results

All tool versions are pinned; CI installs them from hash-locked requirement files (requirements/*.txt, pip install --require-hashes), and every GitHub Action is pinned to a commit SHA.

Check Tool and version Result
Lint and security lint ruff 0.17.6 (S, B, BLE, PGH rule sets), bandit 1.9.4 Clean. One false positive (SECRET_TYPE label) suppressed with a reason.
Pattern rules semgrep 1.188.0, community rules at commit a5ad1714 (Python security, cryptography, requests, correctness, generic secrets, GitHub Actions) Clean. Reviewed suppressions: subprocess.run with an argument list in spec/tamarin/check.py; the node's upstream urlopen (HTTPS only, redirects refused).
Type checking mypy 2.4.1 --strict 0 errors in 17 modules. One real type confusion (vault KDF parameters) was found and fixed in the first round.
Known vulnerabilities pip-audit 2.10.1 (PyPI advisories), osv-scanner (OSV database, in CI) 0 known vulnerabilities in cryptography 51.0.1, liboqs-python 0.16.0.2, python-pkcs11 0.10.1 and the test dependencies.
Pinned artifacts sha256 tla2tools.jar v1.8.0 and the liboqs commit match their pinned values. The liboqs build now writes a SHA-256 manifest that the library checks before loading (AUD-11).
Secrets gitleaks 8.30.1 over all branches and full history; semgrep secret rules No credentials, keys or tokens committed. One false positive (LIBOQS_CACHE_KEY) allowlisted in .gitleaks.toml.
Coverage-guided fuzzing atheris 3.1.0, fuzz/fuzz_parsers.py About 7 million executions on JSON, public keys, file headers, full decryption of mutated files, detached signatures and ledger blocks. No crash after the AUD-01 fix. Runs 5 minutes in CI each week.
Property-based testing Hypothesis, tests/test_fuzz_properties.py Mutated files never decrypt; any field substitution in signatures or ledger payloads is rejected; total ledger value is conserved.
Unit and integration tests pytest 77 passed, 1 skipped locally (the PKCS#11 test needs SoftHSM, which CI installs). Line coverage 77% overall; signatures 100%, ledger 96%, vault 94%, replay 94%, fileformat 90%, keys 90%.
Protocol proof Tamarin 1.12.0, Maude 3.5.1 All lemmas in spec/tamarin/expected.json verified; see section 4.4.
State-machine model check TLA+ tools 1.8.0 (TLC) spec/RecoveryLedger.tla invariants hold on every push.

4. Cryptographic conformance

4.1 Algorithms

Function Algorithm Standard NIST security category
Key establishment ML-KEM-768 combined with X25519 (hybrid, HPKE MLKEM768-X25519) FIPS 203; SP 800-227; RFC 9180 3
Signature, part 1 ML-DSA-65 FIPS 204 3
Signature, part 2 SLH-DSA-SHA2-192s (pure mode) FIPS 205 3
Composite rule Both signatures must verify (AND), over a labelled message Design per draft IETF composite signatures 3
Payload encryption AES-256-GCM in STREAM chunks SP 800-38D n/a
Key derivation HKDF-SHA256 SP 800-56C, RFC 5869 n/a
Password hashing (vault) Argon2id, 64 MiB, t=3, p=4 RFC 9106 n/a
Randomness OS CSPRNG (os.urandom / OpenSSL) SP 800-90A/B through the OS n/a

Notes:

4.2 Key management

Fresh 32-byte file key and HKDF salt per file; STREAM nonces are a counter with a final flag, bounded below 2^88, so they never repeat under one key. Each vault seal derives a new key from a new 16-byte salt, so its random 96-bit nonce is used once per key. Vault KDF parameters are compared before derivation, so a crafted vault cannot lower or explode the cost. Key files are created with O_EXCL and mode 0600 in a 0700 home directory. High-value keys can be sealed under a non-extractable AES-256 key in a PKCS#11 token.

4.3 Downgrade, domain separation and errors

There is no algorithm negotiation: type, suite, chunk size, KDF parameters and magic bytes must match exactly, and v1 files are rejected. Domain labels and ML-DSA context strings differ per format (file, detached, ledger, block), so a signature cannot be moved between formats. The recipient, the pinned sender and the signature are checked before any decryption, so there is no decryption oracle. Every failure from untrusted input surfaces as a documented ValueError subclass (verified by fuzzing). ML-KEM decapsulation uses implicit rejection.

4.4 Formal verification

docs/FORMAL_ANALYSIS.md gives the full model. In the symbolic model, with an unbounded number of parties and files, Tamarin verifies:

4.5 Constant time

All operations on secret data run in OpenSSL or liboqs. The Python layer compares only public values, and the node's submit token is compared with hmac.compare_digest. Timing of the underlying libraries is trusted, not measured on hardware.

5. OWASP ASVS 5.0, Level 2

Chapter Applies Result Evidence
V1 Encoding and sanitization Yes Pass Canonical JSON with depth (32) and size limits; strict base64; no shell, SQL built with parameters only
V2 Validation and business logic Yes Pass Strict field types (AUD-04); ledger rules for nonce, epoch, expiry and value conservation; TLC model
V3 Web frontend security No n/a The node serves JSON only; the website is static and out of scope
V4 API and web service Yes Pass Body size limits, 413 handling, JSON content type, rate limits per client and IPv6 /64
V5 File handling Yes Pass No overwrite of outputs; temp file then atomic link; partial output removed on error (AUD-05)
V6 Authentication Yes Pass Submit token hashed and compared in constant time; file senders authenticated by composite signatures
V7 Session management No n/a No sessions
V8 Authorization Yes Pass Only the primary accepts writes; followers verify every block signature before applying
V9 Self-contained tokens No n/a No JWT or similar tokens
V10 OAuth and OIDC No n/a Not used
V11 Cryptography Yes Pass Section 4: approved PQC algorithms, hybrid KEM, no custom primitives, CSPRNG, unique nonces, crypto inventory above
V12 Secure communication Yes Pass TLS terminated by Caddy or Cloudflare; follower accepts only https:// upstreams and refuses redirects (AUD-10)
V13 Configuration Yes Pass Proxy headers trusted only from configured proxy ranges (AUD-08); secrets from files with mode checks; no debug endpoints
V14 Data protection Yes Pass Private keys only in the vault or a PKCS#11 token; plaintext appears only after all checks pass
V15 Secure coding and architecture Yes Pass Pinned and hash-locked dependencies; integrity check of liboqs before load (AUD-11); mypy strict
V16 Security logging and error handling Yes Pass Documented error classes; no secrets in errors; node logs without request bodies
V17 WebRTC No n/a Not used

6. CWE Top 25 (2025) review

CWE Relevant code Result
CWE-79, 352, 1321 (web client issues) None (no HTML served) Not applicable
CWE-89, 78, 77, 94 (injection) SQLite store, subprocess in check.py Parameterised SQL only; argument lists, no shell. No finding.
CWE-22 (path traversal) CLI paths, peer book Paths come from the local user; peer names are validated. No finding.
CWE-787, 125, 416, 476, 119, 190 (memory safety) Python code; C in OpenSSL/liboqs Memory-safe language in scope; integer sizes bounded in the parsers (AUD-02).
CWE-20 (input validation) All parsers AUD-01, AUD-02, AUD-04, AUD-06 fixed; fuzzed.
CWE-862, 863, 306, 287 (access control and authentication) Node, ledger AUD-08 fixed; signatures required on every block and operation.
CWE-200 (information exposure) Error messages Errors depend only on public data.
CWE-434 (unrestricted upload) Node submit Size limit and strict schema.
CWE-502 (unsafe deserialization) All input JSON only; no pickle or YAML loaders.
CWE-798 (hard-coded credentials) Whole history gitleaks clean.
CWE-918 (SSRF) Follower upstream Fixed HTTPS upstream from configuration; redirects refused (AUD-10).
CWE-400, 770 (resource exhaustion) Node Connection cap and LRU rate table (AUD-08, AUD-09).
CWE-59, 367 (link following, races) Peer book, outputs O_EXCL, mkstemp and atomic replace (AUD-16).

7. Findings

ID Severity CWE Where Finding Status
AUD-01 Medium CWE-674 encoding, ledger JSON nested about 500 levels raised RecursionError out of block processing. Fixed: depth limit 32, mapped to malformed; tests.
AUD-02 Low CWE-20 encoding.loads Integers over 4300 digits raised a bare ValueError. Fixed.
AUD-03 Medium CWE-829 CI Actions referenced by mutable tags. Fixed: all pinned to commit SHAs; Dependabot.
AUD-04 Low CWE-843 signatures.verify "size": true accepted as 1. Fixed: strict types.
AUD-05 Low CWE-459 api.encrypt_file Truncated output left after a failure. Fixed: removed on error; test.
AUD-06 Info CWE-20 vault Non-canonical base64 accepted. Fixed.
AUD-07 Medium CWE-294 File format An old file could be delivered again and would verify. Fixed: ReplayCache (SQLite, mode 0600) records (sender, salt) after all checks pass; the CLI uses it by default (--allow-replay to opt out); forged files do not burn a salt. Matches the Tamarin REPLAY_CACHE model. Tests.
AUD-08 Medium CWE-348, CWE-770 node Proxy IP header always trusted; unbounded threads. Fixed: header honoured only from configured proxy ranges; at most 128 concurrent connections (configurable). Tests.
AUD-09 Low CWE-770 node.allow Rate table cleared at 100,000 clients. Fixed: LRU eviction; IPv6 grouped by /64. Tests.
AUD-10 Low CWE-601 node._fetch Follower followed redirects, including to http://. Fixed: redirects refused; upstream must be https://. Test.
AUD-11 Low CWE-427, CWE-494 slhdsa liboqs loaded without an integrity check. Fixed: the build writes liboqs.sha256; the library refuses a mismatched library. liboqs-python is hash-locked through the requirement files. Test.
AUD-12 Low CWE-345 keys SLH-DSA secret key not checked against its public root on load. Accepted: every signature is verified before it is returned, so a mismatched key cannot produce an accepted signature. Revisit when liboqs exposes keygen from seed.
AUD-13 Low CWE-460 fileformat.decrypt Low-level function writes plaintext before the final re-hash. Fixed for the public API: api.decrypt_file and the CLI write to a temp file and publish only after every check; the low-level function documents that callers must discard output on error.
AUD-14 Low CWE-316 keys, vault Python cannot erase secrets from memory. Accepted (threat model). Use PKCS#11 custody for high-value keys.
AUD-15 Low CWE-276 cli._password POSIX mode check meaningless on Windows. Fixed: --password-file refused on Windows. Test.
AUD-16 Low CWE-59 peers._save Fixed temp name could follow a planted symlink. Fixed: mkstemp and atomic replace; home directory must not be group or world writable. Tests.
AUD-17 Info CWE-1357 CI Tools pinned by version, not hash. Fixed: requirements/*.txt with hashes, --require-hashes in CI.
AUD-18 Info n/a Tooling False positives reviewed and suppressed with a reason. Closed.

8. Secure development process

NIST SP 800-218 (SSDF)

Practice Evidence
PO.1 Security requirements docs/THREAT_MODEL.md, SECURITY.md
PO.3 Toolchains Pinned, hash-locked tools; SHA-pinned Actions
PO.5 Secure environments CI with read-only default permissions; no secrets in the repository
PS.1, PS.2 Protect and verify code Private repository, changes to main by pull request; pinned dependency commits checked by hash
PS.3 Archive releases Git history and merged pull requests; container image built in CI
PW.1 Secure design Threat model; Tamarin and TLC models
PW.4 Reuse well-secured software pyca/cryptography, liboqs; no custom primitives
PW.6, PW.7, PW.8 Review and test Static analysis, fuzzing, property tests, unit tests in CI
RV.1 Identify vulnerabilities Weekly pip-audit and OSV scans; Dependabot
RV.2, RV.3 Respond and analyse root cause This report; regression test per finding; SECURITY.md disclosure process

SLSA v1.0

Source is version-controlled with reviewed pull requests, and builds run on hosted CI from pinned inputs. No SLSA build level is claimed because signed build provenance is not yet produced. Next step: actions/attest-build-provenance on release builds, which would support Build Level 2.

ISO/IEC 27001:2022 Annex A mapping

Control How ECRE-PQ supports it
5.21 ICT supply chain security Hash-locked dependencies, SHA-pinned Actions, liboqs manifest
8.4 Access to source code Private repository, pull-request workflow
8.8 Technical vulnerability management Weekly dependency scans, Dependabot, this report
8.9 Configuration management Pinned deployment files, documented node configuration
8.12 Data leakage prevention Secrets scanning on all history
8.24 Use of cryptography Section 4
8.25 Secure development life cycle Section 8 (SSDF)
8.26 Application security requirements ASVS table (section 5)
8.27 Secure architecture Threat model, formal models
8.28 Secure coding Static analysis, strict typing, CWE review
8.29 Security testing Fuzzing, property tests, CI on every change
8.32 Change management Pull requests with CI checks on every change

This mapping shows how the product supports an organisation's controls. It is not an ISO certification.

9. Design limits and compensating controls

These are properties of the design, not open findings. Each has controls in place today; the right-hand column says what further step is planned.

Design limit Compensating controls in place Planned
Signing runs on the host. The PKCS#11 token protects keys at rest; seeds are unsealed into memory for each operation. Keys are sealed under a non-extractable AES-256 key inside the token, so a stolen vault file is useless without the token and its PIN. Each signature is composite (ML-DSA-65 and SLH-DSA-SHA2-192s): a forger must break both families or steal both seeds. Every signature is verified before it is released. In-token signing once tokens support PKCS#11 3.2 ML-DSA and SLH-DSA mechanisms.
Formal proofs cover the protocol design, not every line of code. The code is checked separately: mypy --strict, 81 test functions (unit, integration and property), about 7 million fuzzing executions of every parser, weekly fuzzing in CI, and regression tests for every finding in this report. The Tamarin model is re-checked on every protocol change. Continuous fuzzing (OSS-Fuzz or ClusterFuzzLite).
The ledger has one sequencer, which orders operations. The sequencer cannot forge or alter a spend: every operation needs the account's own composite signature. Followers pin the sequencer key, verify every block attestation, replay every operation under the ledger rules and halt on any mismatch, so tampering is detected by anyone running a follower. Recovery priority is enforced by the ledger rule checked with TLC. Follower witness countersignatures on chain heads, then multiple sequencers.
Cryptographic libraries are not FIPS 140-3 validated modules in this build. Only standardised algorithms (FIPS 203, 204, 205) from widely reviewed libraries; liboqs is pinned to a commit and its binary is hash-checked before loading; all dependencies are hash-locked. Build against a validated module where a customer's regulation requires it.
Whole-file replay is not prevented by the format alone. Closed in the product: the replay cache refuses a second copy of any file (AUD-07), proved sufficient by Tamarin lemma R1. None.

10. Limitations of this audit

11. Reproduce

python -m venv /tmp/tools
/tmp/tools/bin/pip install --require-hashes -r requirements/security-tools.txt
python -m pip install -e ".[test]"
/tmp/tools/bin/ruff check src tests fuzz
/tmp/tools/bin/bandit -c pyproject.toml -r src
/tmp/tools/bin/mypy --python-executable "$(command -v python)" src
export OQS_INSTALL_PATH=/tmp/oqs && scripts/build-liboqs.sh "$OQS_INSTALL_PATH"
python -m pytest
/tmp/tools/bin/pip-audit

Semgrep, osv-scanner, gitleaks, fuzzing, Tamarin and TLC commands are in .github/workflows/.