Agent-skills-standard typescript-security
Validate input, secure auth tokens, and prevent injection attacks in TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/typescript/typescript-security" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-typescript-security-81040a && rm -rf "$T"
manifest:
skills/typescript/typescript-security/SKILL.mdsource content
TypeScript Security
Priority: P0 (CRITICAL)
Validate Input at Boundaries
- Use
,Zod
, orJoi
at API boundary. Alwaysclass-validator
and validateparse
before using. Useuser-controlled input
for error handling without throwing. ReturnsafeParse
on failure.400 with structured errors
See references/REFERENCE.md for Zod validation schemas, secure cookie setup, and JWT auth patterns.
Prevent Injection and XSS
- Sanitization: Use
for HTML sanitization to prevent Cross-Site Scripting (XSS).DOMPurify - SQL Injection: Use Parameterized Queries (e.g.,
) or Type-safe ORMs (pool.query('... WHERE id = $1', [id])
/Prisma
). UseTypeORM
for raw queries.Prisma.sql - Input Filtering: Sanitize
before using it in file paths or OS commands (Command Injection).user-controlled input
Secure Authentication
- Use
for password hashing. ImplementArgon2id
(viaJWT
orjsonwebtoken
) withjose
andHttpOnly
cookies. UseSecure
for public/private key pairs and implementRS256
.Refresh Token rotation - Secrets: Store secrets in
(e.g.,.env
) or Secret Managers. NEVER commit them to Git.JWT_SECRET - CORS: Configure
with Strict Origin Whitelisting. AvoidCORS
.origin: '*' - Encryption: Use
(Node.js) orcrypto
for sensitive data. Avoid legacy algorithms like MD5/SHA1.Web Crypto API
Verification
After typing validation schemas (Zod/joi) or auth guards, call
getDiagnostics (typescript-lsp) to confirm type narrowing correct before finalizing.
Anti-Patterns
- No dynamic execution: Avoid
,eval
constructor, or string literals as timer callbacks — all execute runtime code and bypass TypeScript's type system.Function - No shell string interpolation: Never use
cmd ${userInput}`)execSync(\
execSyncor interpolate environment variables / config values into
spawnSync/
execFileSync('git', ['arg1', arg2])` with a static command + separate args array instead.strings. Shell metacharacters cause **command injection (OWASP A03)**. Use - No unvalidated SSRF origins: When a URL comes from env vars or config (e.g.,
), validate it against an allowed-origin allowlist before callingFEEDBACK_API_URL
/fetch()
.axios - No Plaintext: Never commit secrets.
- No Trust: Validate everything server-side.
References
See references/REFERENCE.md for Zod validation, secure cookie setup, JWT auth, security headers, and RBAC patterns.