/coding-skills:typescript-securityfrom coding-skills
Security best practices and vulnerability prevention for TypeScript and Node.js. Covers injection (SQL, command, XSS, SSRF), cryptography, filesystem safety, network security, cookies, secrets management, prototype pollution, async race conditions, and logging. Targets Express, Next.js, NestJS, and plain Node servers. Apply when writing, reviewing, or auditing TypeScript/Node code for security, or when working on any risky code involving crypto, I/O, secrets management, user input handling, or authentication. Includes configuration of security tools.
Ships in coding-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Persona: You are a senior TypeScript / Node.js security engineer. You apply security thinking both when auditing existing code and when writing new code — threats are easier to prevent than to fix.
Thinking mode: Use ultrathink for security audits and vulnerability analysis. Security bugs hide in subtle interactions — deep reasoning catches what surface-level review misses.
Modes:
Security in TypeScript/Node.js follows the principle of defense in depth: protect at multiple layers, validate all inputs, use secure defaults, and leverage Node's built-in security-aware APIs (node:crypto, node:path, node:fs) and the ecosystem's vetted libraries (helmet, zod, argon2). TypeScript's static type system rules out a class of bugs but does nothing for runtime trust boundaries — values arriving from the network are any in spirit even when typed string.
Before writing or reviewing code, ask three questions:
| Level | DREAD | Meaning |
|---|---|---|
| Critical | 8-10 | RCE, full data breach, credential theft — fix immediately |
| High | 6-7.9 | Auth bypass, significant data exposure, broken crypto — fix in current sprint |
| Medium | 4-5.9 | Limited exposure, session issues, defense weakening — fix in next sprint |
| Low | 1-3.9 | Minor info disclosure, best-practice deviations — fix opportunistically |
Levels align with DREAD scoring.
Before flagging a security issue, trace the full data flow through the codebase — don't assess a code snippet in isolation.
Severity adjustment, not dismissal: upstream protection does not eliminate a finding — defense in depth means every layer should protect itself. But it changes severity: a SQL concatenation reachable only through a strict zod parser is medium, not critical. Always report the finding with adjusted severity and note which upstream defenses exist and what would happen if they were removed or bypassed.
When downgrading or skipping a finding: add a brief inline comment (e.g., // security: SQL concat safe here — input is validated by parseUserId() which returns number) so the decision is documented, reviewable, and won't be re-flagged by future audits.
Apply STRIDE to every trust boundary crossing and data flow in your system: Spoofing (authentication), Tampering (integrity), Repudiation (audit logging), Information Disclosure (encryption), Denial of Service (rate limiting), Elevation of Privilege (authorization). Score each threat using DREAD (Damage, Reproducibility, Exploitability, Affected users, Discoverability) to prioritize remediation — Critical (8-10) demands immediate action.
For the full methodology with TypeScript examples, DFD trust boundaries, DREAD scoring, and OWASP Top 10 mapping, see Threat Modeling Guide.
| Severity | Vulnerability | Defense | TypeScript / Node Solution |
|---|---|---|---|
| Critical | SQL Injection | Parameterized queries separate data from code | pg $1 / mysql2 ? placeholders; Prisma, Drizzle, Knex bindings |
| Critical | Command Injection | Pass args separately, never via shell concatenation | child_process.execFile / spawn with arg array, shell: false |
| High | XSS | Auto-escaping renders user data as text, not HTML/JS | React JSX (auto-escapes), avoid dangerouslySetInnerHTML, DOMPurify for HTML |
| High | Path Traversal | Scope file access to a root, prevent ../ escapes | path.resolve + prefix check, fs.realpath, reject .. segments |
| Medium | Timing Attacks | Constant-time comparison avoids byte-by-byte leaks | crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b)) |
| High | Crypto Issues | Use vetted algorithms; never roll your own | node:crypto AES-256-GCM, randomBytes, randomUUID |
| Medium | HTTP Security | TLS + security headers prevent downgrade attacks | https.createServer, minVersion: 'TLSv1.2', helmet middleware |
| Low | Missing Headers | HSTS, CSP, X-Frame-Options prevent browser attacks | helmet() or manual security headers middleware |
| Medium | Rate Limiting | Rate limits prevent brute-force and resource exhaustion | express-rate-limit, @upstash/ratelimit, server timeouts |
| High | Prototype Pollution | Merging attacker JSON into objects mutates Object.prototype | Object.create(null), reject __proto__ / constructor / prototype keys, schema-validate first |
| High | Async Race on Shared State | Module-level mutable state mutated across concurrent requests | Avoid module-level mutable singletons; per-request context; atomic DB ops; locks for true critical sections |
| High | SSRF | User-supplied URLs hit internal services | URL allowlist, parse host, block private/link-local ranges, disable redirects to new hosts |
For complete examples, code snippets, and CWE mappings, see:
Secure, HttpOnly, SameSite, __Host- prefix, signed cookies.process.env, --env-file, secret managers.pino redaction.For the full security review checklist organized by domain (input handling, database, code execution, crypto, web, auth, errors, dependencies, async/concurrency), see Security Review Checklist — a comprehensive checklist for code review with coverage of all major vulnerability categories.
Security-relevant tooling for TypeScript / Node.js:
npm audit
npm audit signatures
npx eslint --ext .ts,.tsx .
# with eslint-plugin-security, eslint-plugin-no-secrets, @typescript-eslint
npx snyk test
npx snyk monitor
npx semgrep --config p/typescript --config p/owasp-top-ten --config p/nodejsscan .
npx osv-scanner --lockfile=package-lock.json
Recommended ESLint plugins: eslint-plugin-security, eslint-plugin-no-secrets, @typescript-eslint/eslint-plugin, eslint-plugin-n (Node-specific safety), eslint-plugin-no-unsanitized.
node --test
node --test --experimental-test-coverage
npx fast-check
Use fast-check for property-based tests on parsers, validators, and any function that maps untrusted strings to typed values — fuzz-like coverage catches edge cases that example-based tests miss.
| Severity | Mistake | Fix |
|---|---|---|
| High | Math.random() for tokens | Output is predictable. Use node:crypto.randomBytes or crypto.randomUUID() |
| Critical | SQL string concatenation / template literals into query | Attacker can modify query logic. Use parameterized queries (pg $1, mysql2 ?, Prisma, Drizzle) |
| Critical | child_process.exec with interpolated input | Shell interprets metacharacters. Use execFile / spawn with an arg array and shell: false |
| Critical | eval, new Function, vm on user input | Direct RCE. Never do this — refactor to a parser or interpreter you control |
| High | Trusting unsanitized input | Validate at trust boundaries with zod / valibot / joi — internal code trusts the boundary, so catching bad input there protects everything |
| Critical | Hardcoded secrets | Secrets in source code end up in version history, CI logs, and backups. Use env vars or secret managers |
| Medium | Comparing secrets with === | === short-circuits, leaking timing info. Use crypto.timingSafeEqual on equal-length Buffers |
| Medium | Detailed errors in responses | Stack traces and DB errors help attackers map your system. Return generic messages, log details server-side |
| High | Merging attacker-controlled JSON into plain objects | Prototype pollution propagates across the process. Schema-validate first; use Object.create(null); reject __proto__ keys |
| High | MD5 / SHA1 / SHA-256 for passwords | Fast hashes — brute-forceable. Use Argon2id (argon2 package) or bcrypt (bcrypt / bcryptjs) |
| High | AES without GCM (or rolling crypto) | ECB/CBC modes lack authentication — attacker can modify ciphertext undetected. Use aes-256-gcm |
| Medium | Binding to 0.0.0.0 by default | Exposes service to all network interfaces. Bind to a specific interface to limit attack surface |
| High | dangerouslySetInnerHTML with untrusted HTML | Direct XSS. Render as text, or sanitize with DOMPurify before injecting |
| High | Module-level mutable state across requests | Async races corrupt data or leak between users. Keep per-request state in request-scoped context (AsyncLocalStorage) |
| Severity | Anti-Pattern | Why It Fails | Fix |
|---|---|---|---|
| High | Security through obscurity | Hidden URLs are discoverable via fuzzing, logs, or source | Authentication + authorization on all endpoints |
| High | Trusting client headers | X-Forwarded-For, X-Is-Admin are trivially forged | Server-side identity verification; configure app.set('trust proxy', …) correctly |
| High | Client-side authorization | JavaScript checks are bypassed by any HTTP client | Server-side permission checks on every handler / route guard |
| High | Shared secrets across envs | Staging breach compromises production | Per-environment secrets via secret manager |
| Critical | Ignoring crypto / I/O errors | try { … } catch { /* swallow */ } may proceed unencrypted or unauthenticated | Always handle errors — fail closed, never open |
| Critical | Rolling your own crypto | Custom encryption hasn't been analyzed by cryptographers | Use node:crypto AES-GCM, argon2, vetted libraries |
See Security Architecture for detailed anti-patterns with TypeScript code examples.
More language-specific coding skills (e.g., python-security, rust-security) are planned in this same coding-skills plugin. Until they ship, treat the principles here as language-agnostic where the framework matters less than the trust model.
references/architecture.md (opens in a new tab)references/checklist.md (opens in a new tab)references/cookies.md (opens in a new tab)references/cryptography.md (opens in a new tab)references/filesystem.md (opens in a new tab)references/injection.md (opens in a new tab)references/logging.md (opens in a new tab)references/network.md (opens in a new tab)references/secrets.md (opens in a new tab)references/threat-modeling.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub oskarhane/oskars.ai --plugin coding-skills2 skills in this plugin