137/361

What are some tools and techniques for identifying security vulnerabilities in JavaScript code?

Quiz · Security
Medium
6 min
security
tooling

TL;DR

Use several complementary layers, automated in CI: dependency scanning (SCA) for vulnerable packages (npm audit, Dependabot/Renovate, Snyk, OSV-Scanner, Socket for malicious packages), static analysis (SAST) for risky code patterns (ESLint security plugins, Semgrep, CodeQL), secret scanning (GitHub secret scanning, gitleaks), dynamic testing (DAST) of the running app (OWASP ZAP, Burp Suite), runtime signals (CSP violation reports, error monitoring), and human review: threat modelling, security-focused code review and periodic penetration tests. No single tool finds everything.

1. Dependencies (software composition analysis)

Most JavaScript code in production comes from node_modules, so this is usually the biggest risk.

npm audit --omit=dev            # known CVEs in production dependencies
npx osv-scanner --lockfile=package-lock.json
  • Dependabot / Renovate: automatic PRs for vulnerable and outdated packages.
  • Snyk, Socket, GitHub dependency review: flag known vulnerabilities and suspicious package behaviour (install scripts, typosquatting, newly added network or filesystem access).
  • Lockfiles committed, npm ci in CI, and consider disabling install scripts by default (ignore-scripts) with explicit allowlists.
  • Triage by reachability: a ReDoS in a dev-only build tool matters less than one in your request parser.

2. Static analysis (SAST)

// patterns these tools flag
el.innerHTML = userInput;                     // DOM XSS sink
eval(code); new Function(body);               // code injection
db.query(`SELECT * FROM t WHERE id = ${id}`); // SQL injection
child_process.exec(`convert ${file}`);        // command injection
  • ESLint: eslint-plugin-security, eslint-plugin-no-unsanitized, react/no-danger, TypeScript strictness.
  • Semgrep: fast, customisable rules (write your own for company-specific APIs).
  • CodeQL (GitHub code scanning): data-flow analysis tracing untrusted sources to dangerous sinks.
  • Run in PRs with inline annotations; tune rules to keep false positives low or developers will ignore them.

3. Secrets

  • GitHub push protection / secret scanning, gitleaks or trufflehog in pre-commit and CI.
  • Check built bundles for leaked keys: anything in VITE_*/NEXT_PUBLIC_* env vars ships to users.
  • Rotate any exposed secret; deleting the commit isn't enough.

4. Dynamic testing (DAST) and manual testing

  • OWASP ZAP (baseline scan in CI against a staging deploy) and Burp Suite for manual testing: intercept requests, tamper parameters, test auth and access control.
  • Check headers and TLS with Mozilla HTTP Observatory and similar scanners.
  • Browser DevTools: inspect storage for tokens, cookies' flags, CSP errors, and what the network tab exposes.
  • Penetration tests and bug bounty programmes find logic flaws (broken access control, IDOR) that scanners miss.

5. Runtime and monitoring

  • CSP reports (report-to) reveal injection attempts and unexpected third-party scripts.
  • Trusted Types violations in report-only mode map out DOM XSS sinks.
  • Error monitoring and WAF/rate-limiting logs for abuse patterns.
  • Subresource Integrity on third-party scripts, and inventories of what third parties load.

6. Process

  • Threat modelling for new features (who can send what, where does data flow, what's sensitive?).
  • Security checklist in code review: auth checks on every endpoint, output encoding, no secrets, safe redirects.
  • OWASP resources: the Top 10 and cheat sheets as team references; the ASVS for requirements.
  • Training and ownership: security champions per team, clear SLAs for fixing findings by severity.

A sensible CI pipeline

  1. Lint + type-check (including security rules) on every PR.
  2. SCA and secret scanning on every PR; block on high-severity reachable issues.
  3. CodeQL/Semgrep scans on PRs and on the main branch.
  4. DAST baseline scan against preview or staging deployments.
  5. Scheduled full scans and dependency updates.

In an interview, mention…

  • The layers (SCA, SAST, secrets, DAST, runtime, manual) and what each catches.
  • Supply-chain risk as the dominant JS concern, with lockfiles and malicious-package detection.
  • Keeping signal high (triage, reachability, tuned rules) so developers act on findings.
  • Tools complement but don't replace threat modelling, review and pen testing.

Spotted a mistake or a rights concern? Report an issue