Secure software development
About this lesson
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.
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
Read the lesson step by step
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 releasePlan: 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)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)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)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 SQLCI: 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 againReview: 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)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)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)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 causeSecure 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
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01Which version of the line passes a user's name to SQLite safely?
The ? placeholder with the value in a separate tuple is a parameterized query: the database treats the name only as data. The other three paste the name into the SQL text, which Python's sqlite3 documentation warns against.
02Why does the team keep the O'Brien test in the suite after the fix passes?
A regression test guards a bug that was fixed. Every future push reruns it, so the same mistake cannot quietly return.
03A scanner such as Bandit flags the string-built query. Why does the team still use tests and code review?
Bandit reports this pattern with low confidence. Automated checks and human review catch different things, so using several layers catches more.
04What does signing a release prove to users?
A signature lets users verify the package is genuine and unchanged (SSDF PS.2). It says nothing about whether the code inside is free of flaws.
05A researcher reports a flaw through the team's disclosure policy, and the team ships a fix. Which SSDF practice group is that?
Respond to Vulnerabilities (RV) covers receiving reports, fixing and releasing, and studying the root cause so similar flaws are found and removed.
Glossary
- Secure SDLC
- A software development life cycle (the stages every change goes through: plan, code, test, review, release, run) with a security task built into each stage, instead of one check at the end.
- Security requirement and threat model
- A security requirement says what the software must do to stay safe, such as passing user text to SQL only as a parameter. A threat model maps where untrusted input enters and what could go wrong there.
- Injection and parameterized query
- Injection happens when text from a user is pasted into a command (such as SQL) and changes what the command means. A parameterized query marks where values go (?) and sends them separately, so the database treats them only as data.
- Continuous integration (CI)
- Automated builds and checks that run on every push, such as unit tests and static analysis scanners. A failing check blocks the change from merging.
- Static analysis and regression test
- Static analysis (SAST) reads source code for risky patterns without running it; Bandit is one such tool for Python. A regression test is kept after a fix so the same bug cannot come back unnoticed.
- SBOM and signed release
- A software bill of materials (SBOM) lists every component inside a release. A digital signature lets users check who released the package and that it has not been changed.
- Vulnerability disclosure policy and root cause analysis
- A published policy telling outsiders how to report a flaw and what the team will do. Root cause analysis asks why the process let the flaw through, so a whole class of similar flaws can be removed.
- NIST SSDF (SP 800-218)
- NIST's Secure Software Development Framework: secure development practices in four groups, Prepare the Organization, Protect the Software, Produce Well-Secured Software and Respond to Vulnerabilities.
Notes and sources
- The example uses Python's built-in sqlite3 module. With a name such as O'Brien, the first version raises sqlite3.OperationalError (the quote ends the SQL string early); the fixed version returns the right row. Both were run on Python 3.14.
- Bandit 1.9.4 reports this pattern as B608 (CWE-89) with low confidence. Scanners give hints, not proof, and miss some flaws, which is why tests and human review are still needed.
- The figure shows one tidy path. Real teams vary it: CI and review usually run side by side on a pull request, and many checks run before code is ever pushed.
- A signature proves who released a package and that it has not changed since. It does not prove the code is free of flaws.
- NIST SP 800-218 (SSDF version 1.1, February 2022) is the current final version. The figure links each stage to one group to keep it simple; many practices span several stages.
- This course is about defence. It explains a weakness only at the level of the mistake and its fix, and never how to attack a real system.
- NIST SP 800-218: Secure Software Development Framework (SSDF) Version 1.1 (February 2022)
- Python documentation: sqlite3, how to use placeholders to bind values in SQL queries
- OWASP Cheat Sheet Series: SQL Injection Prevention
- CISA and FBI: Secure by Design Alert, Eliminating SQL Injection Vulnerabilities in Software (March 2024)
- CISA: Secure by Design
- CISA: Software Bill of Materials (SBOM)
- Bandit documentation: B608 hardcoded_sql_expressions
- MITRE CWE-89: Improper Neutralization of Special Elements used in an SQL Command (SQL Injection)
Quiz Unlocks after the last step.