ENع
→Secure SDLC
الدرس 13 · الأنظمة الآمنة

Secure software development

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

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

A secure software development life cycle (SDLC) builds security into every stage a change passes through: plan, code, automated checks, review, release and response. Follow one small Python change as a hurried mistake (SQL built with an f-string) is caught by a unit test and a scanner in CI, fixed with a placeholder, reviewed, released with an SBOM and a signature, and later improved again after an outside report. Finish with the four practice groups of NIST's Secure Software Development Framework and CISA's Secure by Design idea of removing whole classes of flaws.

ستتعلّم

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

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

The software development life cycle

The software development life cycle (SDLC) is the path every change takes: plan, write code, check, review, release, run. A secure SDLC builds security into each stage, instead of testing for it once at the end.

SDLC   the stages every change goes through
  plan → code → CI checks → review → release → run
secure SDLC
  a security task at every stage,
  not one test just before release
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. The software development life cycle

    The software development life cycle (SDLC) is the path every change takes: plan, write code, check, review, release, run. A secure SDLC builds security into each stage, instead of testing for it once at the end.

    SDLC   the stages every change goes through
      plan → code → CI checks → review → release → run
    secure SDLC
      a security task at every stage,
      not one test just before release
  2. Plan: requirements and threats

    The team is adding a search by user name. First they write a security requirement: queries must pass user text as a parameter, never paste it into the SQL. A threat model marks the search box as untrusted input.

    feature       find a user by name
    requirement   SQL gets user text only as a parameter
                  (SSDF PO.1: define security requirements)
    threat model  the name comes from a search box:
                  untrusted input  (SSDF PW.1.1)
  3. Code: the mistake

    In a hurry, a developer writes find_user. Line 3 uses an f-string to paste the name straight into the SQL text. That breaks the requirement: a quote in a name changes what the query means. This weakness is called injection.

    1  def find_user(db, name):
    2      q = ("SELECT id FROM users "
    3           f"WHERE name = '{name}'")
    4      cur = db.execute(q)
    5      return cur.fetchone()
    
    line 3   the name becomes part of the SQL text
             a quote ' in the name ends the string early
    weakness SQL injection (CWE-89)
  4. CI: two checks fail

    Every push runs automatic checks, called continuous integration (CI). A unit test looks up the name O'Brien, and its quote breaks the query. A scanner flags SQL built from strings. Both fail, so the change is blocked.

    def test_name_with_apostrophe():
        db = make_db()
        assert find_user(db, "O'Brien") == (2,)
    
    test     FAIL  sqlite3.OperationalError: near "Brien": syntax error
    scanner  FAIL  Bandit B608: SQL built from strings
    merge    blocked  (SSDF PW.7, PW.8)
  5. The fix: a placeholder

    The fix uses a placeholder. The ? marks where a value goes, and the name travels separately, in a tuple. The database treats it only as data, never as SQL. Python's sqlite3 documentation and OWASP both recommend this.

    1  def find_user(db, name):
    2      q = ("SELECT id FROM users "
    3           "WHERE name = ?")
    4      cur = db.execute(q, (name,))
    5      return cur.fetchone()
    
    line 3   ? = a placeholder for one value
    line 4   the value travels separately: (name,)
             the database never reads it as SQL
  6. CI: both checks pass

    The developer pushes again, and the same checks rerun. The O'Brien test passes and the scanner finds nothing. The test stays in the suite for good, so the mistake cannot quietly return. That makes it a regression test.

    test     PASS  find_user(db, "O'Brien") == (2,)
    scanner  PASS  no issues
    
    regression test  kept forever: if anyone brings
                     the old line back, CI fails again
  7. Review: a second person

    A second person reviews the change before it merges. They compare it with the requirement and the threat model, and look for logic flaws that tools miss. Tools and people together catch more than either alone.

    code review   another developer reads the change
      checks      the requirement is met
                  the threat model still holds
                  logic flaws tools cannot see
    result        approved, merged  (SSDF PW.7)
  8. Release: list it, sign it

    The pipeline builds the release, lists every component inside it in a software bill of materials (SBOM), and signs the package. Users can check the signature to confirm the software is genuine and unchanged.

    build      in the controlled pipeline
    SBOM       a list of every component inside
               (SSDF PS.3.2)
    signature  proves who released it, and that
               nothing changed since  (SSDF PS.2)
  9. Respond: report, fix, learn

    Flaws can still slip through. A researcher reports one through the team's published disclosure policy. The team confirms it, ships a fixed release, tells users, and asks why their process missed it: root cause analysis.

    report      through a vulnerability disclosure
                policy  (SSDF RV.1.3)
    fix         confirm, fix, release, tell users
                (SSDF RV.2)
    root cause  why did the process miss it?  (RV.3)
  10. NIST's SSDF: four groups

    NIST's Secure Software Development Framework (SSDF, SP 800-218) sorts this work into four groups: Prepare the Organization, Protect the Software, Produce Well-Secured Software, and Respond to Vulnerabilities.

    NIST SP 800-218, SSDF version 1.1 (2022-02)
      PO  Prepare the Organization
          PO.1 security requirements
      PS  Protect the Software
          PS.2 signed releases, PS.3 SBOM
      PW  Produce Well-Secured Software
          PW.1 threat model, PW.5 secure coding, PW.7 review, PW.8 tests
      RV  Respond to Vulnerabilities
          RV.1 disclosure policy, RV.2 fix, RV.3 root cause
  11. Secure by design

    Better still, remove whole classes of flaws. CISA's Secure by Design alert urges makers to end SQL injection with parameterized queries everywhere, and SSDF asks teams to hunt for similar flaws before anyone reports them.

    one fix      this function
    class fix    every query uses parameters;
                 a scanner rule blocks the old pattern
    CISA + FBI   "eliminate this entire class of defect"
    SSDF RV.3.3  find similar flaws proactively

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