Live lesson · progress saved to your account

Secure Coding & Application Security

Fixing a flaw in design costs a fraction of fixing it in production. Learn the secure SDLC, review code for real vulnerabilities, compare SAST, DAST, IAST, SCA and fuzzing, secure the software supply chain with SBOMs, signing and SLSA, then fix vulnerable code and build a CI pipeline that stops a SaaS company's recurring bug.

advanced130 minwalkthrough

Anyone can read this lesson. To submit answers and earn XP, create a free account.

TASK 01Mission briefing: the same bug, three times

POSTMORTEM #3 · PaisaFlow (fictional) · October 2026 "A customer could download other companies' invoices by changing the number in the URL. This is the third time this year. Each time a different developer wrote a new endpoint and forgot the organisation check."

PaisaFlow is a Pune invoicing SaaS used by 9,000 small businesses. Their bug is a classic IDOR (Insecure Direct Object Reference), a form of broken access control, the category at the top of the OWASP Top 10:

Same bug, three endpoints, three developers 1/3 incidents

Feb 2026 · dev A

GET /api/invoices/:id

const inv = await getInvoice(id);
// org check missing
res.json(inv);

Found by: customer email

Jun 2026 · dev B

GET /api/invoices/:id/pdf

const inv = await getInvoice(id);
// org check missing
res.json(inv);

Found by: bug bounty report

Oct 2026 · dev C

GET /api/orgs/:orgId/invoices/export

const inv = await getInvoice(id);
// org check missing
res.json(inv);

Found by: a journalist

Every time, the fix was a one-line code change and an apology email. Nothing changed in how PaisaFlow builds software, so the bug came back. Application security (AppSec) engineers fix the process: security requirements, design review, code review, automated testing and pipeline gates, so the computer catches the bug before a customer does.

In this room you'll learn the secure SDLC, code review, AppSec testing tools, supply-chain security and DevSecOps. Then you'll review and fix PaisaFlow's code and design a pipeline that proves the IDOR can never ship again.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 02The secure SDLC and the cost of a bug

A Secure Software Development Lifecycle (SSDLC) adds security activities to every phase, instead of a penetration test the week before launch:

Secure SDLC: security in every phase Requirements

ASVS level chosen (L2 for SaaS with PII)

Abuse case: 'user reads another org's invoice'

  • Requirements: write security requirements. The OWASP ASVS (Application Security Verification Standard, version 5.0 released in 2025) gives testable requirements at three levels.
  • Design: threat model new features (Room 18) and review the architecture.
  • Code: secure coding standards, peer review, safe libraries.
  • Test: SAST, DAST, SCA, security unit tests and abuse cases.
  • Release: signed builds, an SBOM, a go/no-go security gate.
  • Operate: monitoring, patching, a vulnerability disclosure programme or bug bounty, and incident response.

Why bother so early? The later a flaw is found, the more it costs: more code is built on top of it, more people are involved, and in production there are customers, regulators and lawyers too:

Cost of a bug: when you find it matters ×1 (illustrative)

1 architect, a whiteboard, 30 minutes

Bar height on a square-root scale. The multipliers are illustrative; the trend is what every study agrees on.

The exact multipliers often quoted are debated, but the direction isn't. Frameworks like NIST's Secure Software Development Framework (SSDF, SP 800-218) and OWASP SAMM help organisations measure and improve this maturity.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 03Secure code review

Tools miss things that a human reviewer with a checklist catches, especially logic flaws like IDOR. A security-focused review asks four questions of every change:

Secure code review: four questions for every diff CWE-89

- db.query(`SELECT * FROM users WHERE email = '${email}'`)

+ db.query("SELECT * FROM users WHERE email = ?", [email])

Fix the class of bug, not the one instance: use the safe API everywhere.

  1. Input validation: is every input from the user, headers, files or other services validated (type, length, allowed values) on the server? Are queries parameterised rather than concatenated?
  2. Output encoding: is data encoded for where it goes (HTML, attribute, JavaScript, URL, SQL, shell)? Frameworks escape by default, until someone uses innerHTML or dangerouslySetInnerHTML.
  3. Authentication: are passwords hashed with a slow algorithm (bcrypt, scrypt, Argon2), sessions protected (HttpOnly, Secure, SameSite cookies), secrets kept out of code?
  4. Authorisation: does every endpoint check that this user may do this action on this object? Deny by default.

Also watch for: hard-coded secrets, path traversal, open redirects, verbose errors that leak stack traces, and unsafe deserialisation. Tie findings to CWE IDs (Common Weakness Enumeration), for example CWE-89 SQL injection, CWE-79 XSS and CWE-639 authorisation bypass through a user-controlled key (IDOR).

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 04AppSec testing tools: SAST, DAST, IAST, SCA and fuzzing

No single tool finds everything. Each looks at the software from a different angle:

Which tools find which bugs? 3/13 found

SAST · every commit · sees source code

✓ SQLi pattern✓ hard-coded secret✓ XSS sinkreflected XSSmissing headersopen redirectSQLi with exact data flowpath traversalvulnerable yaml-parse 2.1.0licence conflictcrash in PDF parserReDoSIDOR (invoice of other org)

Turn them all on: the IDOR is still red. It needs a custom rule or a security unit test.

ToolLooks atGood atBlind spots
SAST (static)Source code, without running itInjection patterns, hard-coded secrets, dangerous functions; runs on every commitFalse positives; business logic; config at runtime
DAST (dynamic)The running app, from outsideXSS, misconfigured headers, real exploitabilityNeeds a deployed app; can't see code paths it doesn't reach
IAST (interactive)Agent inside the running app during testsPrecise data flow with few false positivesLanguage/runtime support; only exercised paths
SCAYour third-party dependenciesKnown vulnerable versions, licencesYour own code; unknown (zero-day) flaws
FuzzingRandom/mutated inputs at high speedCrashes, parser and memory bugsNeeds harnesses; logic flaws

Examples: Semgrep and CodeQL (SAST), ZAP and Burp Suite (DAST), Dependabot, OWASP Dependency-Check and Trivy (SCA), AFL++ and libFuzzer (fuzzing).

Notice what's missing: none of them understands "invoice 4471 belongs to another company" out of the box. Logic flaws need custom rules and security unit tests written by people who know the business.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 05Supply chain security: dependencies, SBOMs, signing and SLSA

A typical web app is mostly code other people wrote. PaisaFlow's 40 direct npm packages pull in more than 900 transitive dependencies, each a door into the build:

Your code is the tip; dependencies are the iceberg SCA scanning
▣paisaflow-api
└express4.21.2
└body-parser1.20.3
└pdf-render3.4.0
└yaml-parse2.1.0
└expresss1.0.2
└date-fmt0.9.1

SLSA Build L1 provenance → L2 signed by hosted builder → L3 hardened builder.

Real supply-chain attacks: Log4Shell (2021) hid in a logging library used almost everywhere; the xz Utils backdoor (2024) was planted by a "maintainer" who spent two years earning trust; attackers publish typosquatted packages (expresss, reqeusts) and hijack abandoned ones.

Defences:

  • Pin and lock versions (lockfiles), review new dependencies, prefer maintained ones, remove unused ones.
  • Run SCA continuously, because new vulnerabilities are published for old versions every day.
  • Generate an SBOM (Software Bill of Materials) for each release, in SPDX or CycloneDX format, so you can answer "are we affected?" in minutes.
  • Sign artefacts and verify signatures before deploy (for example with Sigstore's cosign).
  • Follow SLSA (Supply-chain Levels for Software Artifacts). Its v1.0 Build track runs from L1 (provenance exists) to L2 (signed provenance from a hosted build platform) to L3 (a hardened build platform that resists tampering).

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 06DevSecOps: security gates in CI/CD

DevSecOps puts security checks where developers already work: the IDE, the pull request and the CI/CD pipeline. "Shift left" means catching problems as early (as far left in the timeline) as possible:

Shift left: the commit's journey through CI Secrets
Secrets
SAST
SCA
Unit + authz tests
Image/IaC scan
DAST staging
Deploy

Running gates…

A practical pipeline:

  1. Pre-commit / PR: secrets scanning (gitleaks, TruffleHog), linting, fast SAST on the diff.
  2. Build: SCA on the lockfile, container image scan, IaC scanning (Checkov, Trivy) for Terraform and Kubernetes files, SBOM and signing.
  3. Test: unit tests including security regression tests, then DAST against a staging deployment.
  4. Deploy: only signed artefacts that passed the gates.

Two hard-won lessons:

  • Secrets in git history never go away. Deleting the line in a new commit leaves it in history. Rotate the secret immediately, then clean history if needed.
  • Tune the gates. Block on high-confidence, high-severity findings; report the rest. A gate that fails on every informational finding gets switched off by frustrated developers within a week.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 07Hands-on: find 8 bugs in a code review

A PaisaFlow developer opened a pull request for the login, invoice and search routes of their Express API. Review it like an AppSec engineer: flag every vulnerable line. There are exactly 8 bugs, and some lines that look risky are actually done right.

Lab · Review the pull request (8 bugs) 0/8 found · 0 false flags

Click a line to flag it. Click again to unflag. More than 2 false flags and the developer stops trusting your reviews.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+30 XP

TASK 08Hands-on: fix the vulnerable functions

Now fix them. Edit each function in the browser editor and run its security unit tests. The tests check the shape of a correct fix, the way a reviewer would.

Lab · Fix the vulnerable functions 0/5 passing

compares the invoice's org with req.user.orgId

returns 404 for another org's invoice

still returns the invoice to its owner

Hints: use ? placeholders with a parameter array, the provided escapeHtml(), bcrypt.hash(password, 12), path.basename(), and compare the invoice's orgId with req.user.orgId, returning 404 so attackers can't even learn which IDs exist.

Answer the questions

+10 XP

+10 XP

+10 XP

+30 XP

TASK 09Final mission: the pipeline that stops the recurring bug

Design PaisaFlow's CI pipeline. Then prove it: four real commits from this week are replayed through it. Three must be blocked (a leaked payment key, a critical vulnerable dependency, and the IDOR coming back in a new bulk-download endpoint) and the clean feature commit must pass, or developers will route around your gates.

Final mission · Build the pipeline, then replay the week configure
Secrets
SAST
SAST gate
SCA
Tests
DAST
name: paisaflow-ci
on: [pull_request]
jobs:
  security:
    steps:

feat: CSV export for GST returnsshould pass

3 info-level SAST notes, 1 medium advisory in a dev-only dependency

fix: retry payment webhookshould block

adds PAYGATE_LIVE_KEY=pg_live_7Hc… to config.js

chore: bump yaml-parse to 2.1.0should block

dependency with a critical advisory

feat: bulk invoice downloadshould block

new route /api/invoices/bulk without org check

Complete the mission for the Code Guardian badge and the room's XP.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+30 XP