skills/typescript-security/SKILL.md
Guideline for designing, implementing, and verifying secure TypeScript and JavaScript applications following OWASP Top 10 best practices. Use when the user wants to: (1) review TypeScript or JavaScript code for security vulnerabilities, (2) design a secure Node.js, Deno, or browser application architecture, (3) implement security features (authentication, authorization, cryptography, input validation), (4) audit npm/yarn/pnpm dependencies for known vulnerabilities, (5) create security checklists or verification plans, (6) fix security bugs or harden existing TypeScript or JavaScript code, (7) set up security testing and static analysis (ESLint security plugins, Semgrep, Snyk), or (8) handle any TypeScript/JavaScript security concern including injection prevention, prototype pollution, XSS protection, SSRF prevention, secrets management, and secure deployment.
npx skillsauth add jim60105/copilot-prompt typescript-securityInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Provide a structured approach to building secure TypeScript and JavaScript applications, covering the OWASP Top 10, secure coding patterns, and verification checklists. Apply these guidelines throughout the secure development lifecycle — from threat modeling through deployment. This guide covers both server-side (Node.js, Deno, Bun) and client-side (browser) contexts.
Before writing code, identify and mitigate threats at the design level:
postMessage, URL parameters, localStorage)Design with security controls built-in:
Never use these patterns. Violations are high-severity findings in any review.
| Never | Instead |
|-------|---------|
| eval() / Function() constructor with untrusted input | JSON.parse() or a dedicated parser |
| child_process.exec() with user input | child_process.execFile() or spawn() with array args |
| String concatenation / template literals in SQL | Parameterized queries (db.query(sql, params)) |
| innerHTML / outerHTML / document.write() with untrusted data | textContent, framework templating, or DOMPurify |
| dangerouslySetInnerHTML with unsanitized data | DOMPurify + explicit sanitization |
| Math.random() for security purposes | crypto.randomUUID() / crypto.getRandomValues() |
| MD5 / SHA1 for password hashing | bcrypt, argon2, or scrypt via crypto.scrypt() |
| == for security comparisons | === strict equality |
| Object.assign() / spread with untrusted input on prototypes | Validated schema (Zod, class-validator) + Object.create(null) |
| require() / import() with user-controlled paths | Static imports with allowlisted modules |
| Hardcoded secrets in source code | Environment variables or secret manager (Vault, AWS SM) |
| NODE_ENV !== 'production' left in production | Environment-specific configuration |
| JSON.parse() without schema validation on untrusted data | Zod, io-ts, or class-validator after parsing |
| new RegExp(userInput) | Escape user input or use a safe regex library |
| vm.runInNewContext() / vm.runInThisContext() with untrusted code | Isolated worker threads or dedicated sandbox |
| Disabling TLS verification (rejectUnauthorized: false) | Proper certificate management |
Apply a layered verification approach:
eslint-plugin-security — Node.js security linter ruleseslint-plugin-no-unsanitized — Detect unsafe DOM manipulationsemgrep — Pattern-based analysis with OWASP and TypeScript/JavaScript rulesetstypescript-eslint — Type-aware linting for TypeScriptnpm audit / yarn audit / pnpm audit — Built-in package manager auditingsnyk — Comprehensive vulnerability database and remediation advicesocket.dev — Supply chain attack detection (typosquatting, install scripts)detect-secrets — Baseline-aware secrets scannergitleaks — Git-aware secrets scanningQuick tool commands:
# ESLint security plugins
npm install --save-dev eslint-plugin-security eslint-plugin-no-unsanitized
npx eslint --ext .ts,.js,.tsx,.jsx src/
# npm audit — dependency vulnerabilities
npm audit
npm audit --audit-level=high
# Snyk — comprehensive dependency and code scanning
npx snyk test
npx snyk code test
# detect-secrets — secrets scanning
detect-secrets scan > .secrets.baseline
# Semgrep — advanced pattern matching
semgrep --config=p/javascript --config=p/typescript --config=p/owasp-top-ten src/
# Socket.dev — supply chain security
npx socket npm info <package-name>
For complete verification checklists (code review, architecture review, dependency audit, deployment, testing, incident response): See references/security-checklist.md
package-lock.json, yarn.lock, pnpm-lock.yaml) and commit themnpm audit / snyk test in CI/CD pipeline on every build--ignore-scripts for packages where postinstall scripts are not neededsocket.dev or similar tools to detect supply chain attacks (install scripts, obfuscated code)npm provenance)trivy; use minimal base images (distroless, alpine); run as non-root userStrict-Transport-Security headerContent-Security-Policy, X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Permissions-PolicyMap each OWASP 2025 category to TypeScript/JavaScript-specific risks and primary mitigations:
| # | Category | TypeScript/JavaScript-Specific Risks | Primary Mitigation |
|---|----------|--------------------------------------|-------------------|
| A01 | Broken Access Control | Missing auth middleware, IDOR via sequential IDs, path traversal, SSRF via fetch(userUrl), CORS origin: *, client-side-only auth checks | Centralized auth middleware, object-level permissions, path.resolve() + containment check, URL allowlisting, explicit CORS origins |
| A02 | Security Misconfiguration | NODE_ENV=development in prod, Swagger/docs exposed, verbose error stacks, permissive CORS, default express.static() serving .env | Environment-specific config, disable docs in prod, centralized error handler, explicit CORS, .env outside webroot |
| A03 | Software Supply Chain Failures | Unpinned deps, typosquatting on npm, malicious postinstall scripts, no lockfile, unvetted transitive deps, CI/CD secrets exposure | npm audit / snyk in CI, lockfiles committed, --ignore-scripts, socket.dev, npm provenance |
| A04 | Cryptographic Failures | Math.random() for tokens, weak hashing, hardcoded API keys, disabled TLS verification, secrets in client bundles | crypto.randomUUID() / crypto.getRandomValues(), bcrypt/argon2, env vars / secret manager, proper TLS config |
| A05 | Injection | SQL via template literals, XSS via innerHTML/dangerouslySetInnerHTML, child_process.exec(), NoSQL injection ($gt/$ne operators), SSTI, eval() | Parameterized queries, DOM sanitization (DOMPurify), execFile()/spawn() with array args, input validation, textContent |
| A06 | Insecure Design | No rate limiting, missing input validation layer, no abuse case modeling, client-side enforcement of server-side security | Threat modeling, validation at boundaries (Zod/class-validator), rate limiting middleware, server-side enforcement |
| A07 | Authentication Failures | Weak session config, JWT algorithm: "none" or HS256 with public key, no brute-force protection, tokens in localStorage | Secure session settings, explicit algorithms: ["RS256"], account lockout / rate limiting, HttpOnly cookies |
| A08 | Software or Data Integrity Failures | Prototype pollution, node-serialize deserialization, unsigned updates, CDN scripts without SRI, CI/CD pipeline injection | Schema validation (Zod), JSON.parse() + validation, SRI for CDN scripts, pinned CI actions with SHA |
| A09 | Security Logging and Alerting Failures | Logging passwords/tokens, console.log in production, no auth event logging, missing alerting, no structured logging | Structured logging (pino/winston) with field filtering, audit trail, alerting thresholds, honeytokens |
| A10 | Mishandling of Exceptional Conditions | Unhandled promise rejections, empty catch {}, failing open, sensitive info in error responses, uncaught exceptions crashing process | Specific error types, finally blocks, centralized error handler, process.on('unhandledRejection'), fail-closed patterns |
For detailed vulnerable → secure code examples for each category: See references/owasp-top-10.md
Follow this procedure when reviewing TypeScript or JavaScript code for security:
npm audit and snyk test. Flag any unpatched dependencies or packages with known CVEs. Check for suspicious postinstall scripts.semgrep with JavaScript/TypeScript and OWASP rulesets for deeper analysis.innerHTML, document.write). Check CSP configuration, SRI on external scripts, and proper sanitization of user content.# === Static Analysis ===
npm install --save-dev eslint-plugin-security eslint-plugin-no-unsanitized
npx eslint --ext .ts,.js,.tsx,.jsx src/
semgrep --config=p/javascript --config=p/typescript --config=p/owasp-top-ten src/
# === Dependency Audit ===
npm audit --audit-level=high
npx snyk test
# === Secrets Detection ===
detect-secrets scan > .secrets.baseline
gitleaks detect --source .
# === Lock Dependencies ===
npm ci # install from lockfile (CI/CD)
# === Container Scanning ===
# trivy image <image-name>
Consult these files for detailed guidance beyond this overview:
development
Diátaxis Documentation Expert. An expert technical writer specializing in creating high-quality software documentation, guided by the principles and structure of the Diátaxis technical documentation authoring framework.
testing
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.
tools
Comprehensive guide for building, configuring, customizing, and deploying Docsify documentation sites. Use when the user wants to (1) initialize a new Docsify site, (2) add or organize Markdown pages, sidebars, navbars, or cover pages, (3) configure `window.$docsify` options, (4) customize themes / CSS variables / fonts, (5) install built-in or third-party Docsify plugins (search, GA, emoji, zoom, copy-code, comments, pagination, tabs, etc.), (6) write a custom Docsify plugin using lifecycle hooks, (7) use Docsify Markdown helpers (callouts, link attributes, image attributes, heading IDs, task lists, embed files with `:include`), (8) deploy to GitHub Pages, GitLab Pages, Netlify, Vercel, Firebase, Docker, Nginx, etc., (9) enable PWA / offline mode, virtual routes, or Vue compatibility, or (10) upgrade a Docsify site from v4 to v5. Triggers on mentions of "docsify", "_sidebar.md", "_navbar.md", "_coverpage.md", "$docsify", or `docsify-cli`.
testing
Writing guidelines for producing high-quality Traditional Chinese (zh-TW) content. Use when writing any kind of content. Including blog posts, notes, technical articles, technical writing, chitchat, social media posts, etc., even when you are just sending a text message. Also use when reviewing or editing existing Chinese content for tone, style, and terminology compliance.