Security Testing and Secure SDLC

Build security into every stage instead of checking it once at the end ("shift left").

Design → Code → Commit → CI → Deploy → Run
  │        │       │      │      │       │
Threat   Lint/   Secret  SAST,  Image   DAST, monitoring,
model    review  scan    deps   scan    pentest, bug bounty

Tools

TypeWhat it doesTools
Threat modelingFind risks at design time (STRIDE)OWASP Threat Dragon, whiteboard
LintingInsecure patterns while codingeslint-plugin-security, eslint-plugin-n
Secret scanningLeaked keysgitleaks, husky (pre-commit hook)
SASTStatic code analysisSemgrep, SonarQube, CodeQL
SCAVulnerable dependenciesnpm audit, Snyk, Dependabot
DASTAttacks the running appOWASP ZAP, Burp Suite, Nuclei
API testingAuth/IDOR tests on endpointsPostman/Newman, supertest + jest/vitest
Pentest / bug bountyHumans finding logic bugsExternal firm, HackerOne

Security unit tests (supertest + jest)

const request = require('supertest');

test('user A cannot read user B order (IDOR)', async () => {
  const res = await request(app).get(`/orders/${orderOfB}`).set('Authorization', `Bearer ${tokenA}`);
  expect(res.status).toBe(404);
});

test('rejects SQL injection payload', async () => {
  const res = await request(app).get('/users/1%20OR%201=1').set('Authorization', `Bearer ${tokenA}`);
  expect(res.status).toBe(400);
});

test('login is rate limited', async () => {
  for (let i = 0; i < 5; i++) await request(app).post('/login').send({ email: 'a@b.com', password: 'x' });
  const res = await request(app).post('/login').send({ email: 'a@b.com', password: 'x' });
  expect(res.status).toBe(429);
});

Example CI (GitHub Actions)

name: security
on: [pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 22 }
      - run: npm ci --ignore-scripts
      - run: npm audit --omit=dev --audit-level=high
      - run: npx eslint .
      - uses: gitleaks/gitleaks-action@v2
      - uses: returntocorp/semgrep-action@v1
        with: { config: p/owasp-top-ten }

In real projects, pin actions to a commit SHA (see 15).

OWASP ZAP baseline scan (DAST)

docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t https://staging.example.com

Only scan apps you own or are allowed to test.

Checklist

  • Threat model for new features that touch auth, payments or PII
  • A security checklist in the PR template
  • Secret scan pre-commit + in CI
  • SAST + dependency scan fail the build on high severity
  • DAST against staging
  • Security tests for authz, rate limits and validation
  • A yearly pentest; a security.txt / disclosure policy