ENع
→Supply chain
الدرس 16 · الأنظمة الآمنة

Software supply chain security

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

12 دقيقة11 خطوة5 أسئلةIntermediate
عن هذا الدرس

Your app runs far more code than your team wrote: packages from a registry, the packages those need, and the build server that turns it all into a release. Follow one real Python package, requests, through that chain. Audit it for known flaws, pin its exact file by its SHA-256 hash, and watch a seven-line Python checker accept the genuine wheel and refuse a copy with one changed byte. Then keep an SBOM, lock down the build and sign the release, following NIST's SSDF and OWASP.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 16 · تفاعلي
01 / 11

Your app's supply chain

Your app is more than your code. It runs packages other people wrote, downloaded from a registry. A build server turns it all into a release, which is deployed. That whole path is the software supply chain, and every link can fail.

your code        what your team writes
dependencies     packages other people wrote
registry         where they are downloaded from (PyPI)
build server     turns code + packages into a release
production       where the release runs
supply chain     the whole path, every link
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Your app's supply chain

    Your app is more than your code. It runs packages other people wrote, downloaded from a registry. A build server turns it all into a release, which is deployed. That whole path is the software supply chain, and every link can fail.

    your code        what your team writes
    dependencies     packages other people wrote
    registry         where they are downloaded from (PyPI)
    build server     turns code + packages into a release
    production       where the release runs
    supply chain     the whole path, every link
  2. Dependencies, and theirs

    Your project asks for requests 2.31.0, a popular Python package. pip downloads it from PyPI, the Python Package Index, plus the four packages it needs. Those are transitive dependencies: you never chose them, but their code runs inside your app.

    pip install requests==2.31.0
      requests            2.31.0    direct: you asked for it
      urllib3             2.8.0      transitive
      idna                3.20       transitive
      certifi             2026.10.23 transitive
      charset-normalizer  3.5.2      transitive
    1 package asked for, 5 installed
  3. Where the chain breaks

    OWASP ranks supply chain failures third in its 2025 Top 10. Common mistakes: an old version with known flaws, a look-alike package name, a version that changes without review, a hijacked maintainer account, or a tampered build server.

    OWASP Top 10:2025  A03 Software Supply Chain Failures
    mistake                    fix
    old, flawed version        audit and update
    look-alike package name    check the exact name
    version changes silently   pin version + hash
    hijacked maintainer        pin hash, verify signature
    tampered build server      locked-down build, provenance
  4. Check for known flaws

    pip-audit compares each version with a public advisory database. It flags requests 2.31.0: CVE-2024-35195 and two more, all fixed in later releases. The fix is to upgrade, here to 2.34.2, then run the check again.

    pip-audit   requests 2.31.0
      CVE-2024-35195   fixed in 2.32.0
      CVE-2024-47081   fixed in 2.32.4
      CVE-2026-25645   fixed in 2.33.0
    upgrade     requests 2.34.2
    pip-audit   no known advisories (checked 2026-11-06)
    CISA KEV    flaws attackers already use: fix first
  5. Lines 1–2: pin a hash

    Next, pin exactly what you trust. The lock file records each version and the SHA-256 hash of its file: requests==2.34.2 --hash=sha256:2a0d60c1…. Line 2 of the checker reads the file name and that pinned hash.

    requirements.txt (the lock file)
      requests==2.34.2 \
        --hash=sha256:2a0d60c172f83ac6ab31e4554906c0f3
                      b3588d37b5cb939b1c061f4907e278e0
    line 1   import hashlib, sys
    line 2   wheel = the file, pin = that hash
  6. Lines 3–7: hash and compare

    Lines 3 and 4 hash the downloaded wheel with SHA-256. Line 5 compares the result with the pin. They match, so line 7 says install. pip does this for every package when the lock file has hashes (--require-hashes).

    wheel   requests-2.34.2-py3-none-any.whl
            73,075 bytes
    got     2a0d60c1…78e0
    pin     2a0d60c1…78e0
    equal → "hash ok: install"
  7. One changed byte is caught

    Now one byte of the file is changed, say by a hijacked account or a bad mirror. The digest is completely different, so line 5 sees a mismatch and line 6 stops before any of the code inside can run.

    same file, last byte changed (XOR 0x01)
    got     404259fc…7dea
    pin     2a0d60c1…78e0
    not equal → "mismatch: refuse", exit status 1
    pip: THESE PACKAGES DO NOT MATCH THE HASHES
  8. SBOM: the ingredients list

    A software bill of materials (SBOM) lists every component with its supplier and version, transitive ones too. CISA calls it a nested inventory. When a new flaw is announced, like Log4Shell in 2021, you can see at once whether you use it.

    SBOM   every component, its version and supplier
      requests            2.34.2
      urllib3             2.8.0
      idna                3.20
      certifi             2026.10.23
      charset-normalizer  3.5.2
    formats   SPDX, CycloneDX
    use       "are we affected?" answered in minutes
  9. A locked-down build

    Attackers also target the build: in 2020 they slipped malicious code into SolarWinds Orion updates. So build automatically from reviewed code, on an isolated server with few secrets and MFA, and record provenance: which source and steps made the release.

    NIST SSDF PO.5   separate and protect each
                     build environment (MFA, access control)
    automated        same steps every time, no hand edits
    few secrets      only what this build needs
    provenance       which source, which steps, which builder
                     (SLSA build provenance)
  10. Sign it, verify it

    The build signs the release and publishes its hash. NIST's SSDF (practice PS.2) asks makers to give users a way to check integrity. The production server verifies the signature and hash before it runs anything; a mismatch means stop.

    SSDF PS.2   a way to verify release integrity:
                post hashes, sign the code
    build       signs the release
    production  checks signature + hash first
    mismatch    do not run it
  11. Defence in depth

    No single check is enough. Audit and update dependencies, pin and verify hashes, keep an SBOM, lock down the build and sign releases. NIST SP 800-218 (the SSDF) and SP 800-161 describe these practices for software makers and buyers.

    audit + update     known flaws fixed
    pin + verify       only the exact files you trust
    SBOM               know what you run
    locked-down build  provenance recorded
    sign + verify      production runs only real releases
    NIST SP 800-218 (SSDF) · NIST SP 800-161 Rev. 1

اختبار يتاح بعد الخطوة الأخيرة.