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 bountyTools
| Type | What it does | Tools |
|---|---|---|
| Threat modeling | Find risks at design time (STRIDE) | OWASP Threat Dragon, whiteboard |
| Linting | Insecure patterns while coding | eslint-plugin-security, eslint-plugin-n |
| Secret scanning | Leaked keys | gitleaks, husky (pre-commit hook) |
| SAST | Static code analysis | Semgrep, SonarQube, CodeQL |
| SCA | Vulnerable dependencies | npm audit, Snyk, Dependabot |
| DAST | Attacks the running app | OWASP ZAP, Burp Suite, Nuclei |
| API testing | Auth/IDOR tests on endpoints | Postman/Newman, supertest + jest/vitest |
| Pentest / bug bounty | Humans finding logic bugs | External 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.comOnly 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