[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CSNR3TJPXTD77NPZ10G77B":3,"skill-same:01M7CSNR3TJPXTD77NPZ10G77B":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":32,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7CSNR3TJPXTD77NPZ10G77B","node-typescript-security-pitfalls",null,"Use when reviewing Node.js or TypeScript server code - Express\u002FFastify\u002FNest handlers, Next.js server actions and route handlers, child_process, ORM raw queries, prototype pollution, template engines, JWT and outbound HTTP clients","makifbaysal\u002Ftasktrooper","makifbaysal","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F25031940?v=4","01M7CRG3ZCSYZSSEVDMW3DEYC8","Mehmet Akif Baysal","01M7CRG401FJ8YAXH5ER730XYV",122,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fnode-typescript-security-pitfalls\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: node-typescript-security-pitfalls\ncategory: security\ndescription: Use when reviewing Node.js or TypeScript server code - Express\u002FFastify\u002FNest handlers, Next.js server actions and route handlers, child_process, ORM raw queries, prototype pollution, template engines, JWT and outbound HTTP clients\ntech_stack: TypeScript & Node\nsource: original; informed by trailofbits\u002Fskills (CC BY-SA 4.0, ideas only, own wording) and anthropics\u002Fclaude-code security-guidance plugin (ideas only); Node.js, Next.js and library security advisories cited, not reproduced\n---\n# Node and TypeScript Security Pitfalls\n\n## Overview\n\nTypeScript types vanish at runtime: `req.query.id: string` can arrive as an array or an object. Most Node findings come from that gap, from `exec` with a template string, from raw-query escape hatches in otherwise safe ORMs, and — in Next.js — from forgetting that a server action is a public endpoint.\n\n## 1. Runtime Types Are Not Declared Types\n\n```ts\n\u002F\u002F ❌ ?id[$ne]=x or ?id[]=a&id[]=b gives an object or array, not a string\nconst doc = await Orders.findOne({ id: req.query.id as string, owner: user.id });\n\u002F\u002F ✅ validate at the boundary (zod\u002Fvalibot\u002Fclass-validator) and coerce\nconst { id } = z.object({ id: z.string().uuid() }).parse(req.query);\n```\n\nLength, `includes` and equality checks on an unvalidated query value can be bypassed the same way.\n\n## 2. child_process (CWE-78, CWE-88)\n\n```ts\n\u002F\u002F ❌ shell\nexec(`convert ${file} out.png`);\nspawn(\"git\", [\"clone\", url], { shell: true });\n\u002F\u002F ✅ no shell, end of options\nexecFile(\"git\", [\"clone\", \"--\", url, dir]);\n```\n\nAlso check the `env` option for request-controlled keys (`NODE_OPTIONS=--require …`).\n\n## 3. Raw Queries in Safe ORMs (CWE-89)\n\n| Library | Unsafe | Safe |\n|---------|--------|------|\n| Prisma | `$queryRawUnsafe`, `$executeRawUnsafe`, `Prisma.raw()` | `$queryRaw` tagged template, model methods |\n| TypeORM | `query(\"… \" + x)`, `.where(\\`id = ${id}\\`)` | `.where(\"id = :id\", { id })` |\n| Sequelize | `sequelize.query(\\`… ${x}\\`)`, `literal(x)` | `replacements` \u002F `bind` |\n| Knex | `knex.raw(\\`… ${x}\\`)` | `knex.raw(\"… ?\", [x])` |\n| Drizzle | `sql.raw(x)` | `sql\\`… ${x}\\`` |\n\nMongo\u002FMongoose: operator injection from JSON bodies (section 1), `$where`.\n\n## 4. Next.js Server Actions and Route Handlers\n\n- Every exported async function in a `\"use server\"` file is a callable POST endpoint, whether or not a page renders a form for it. Each must authenticate and authorize **inside** the action.\n\n```ts\n\u002F\u002F ❌ the page is admin-only, the action is not\n\"use server\";\nexport async function deleteUser(id: string) { await db.user.delete({ where: { id } }); }\n\u002F\u002F ✅\nexport async function deleteUser(id: string) {\n  const session = await auth();\n  if (session?.user.role !== \"admin\") throw new Error(\"forbidden\");\n  await db.user.delete({ where: { id } });\n}\n```\n\n- Authorization done only in `middleware.ts`: middleware matchers miss paths, and Next.js \u003C 15.2.3 \u002F 14.2.25 \u002F 13.5.9 \u002F 12.3.5 let an `x-middleware-subrequest` header skip middleware entirely (CVE-2025-29927). Check in the handler or data layer too.\n- Server components passing whole records to client components serialise every field into the page payload.\n- `NEXT_PUBLIC_*` variables are shipped to the browser.\n\n## 5. Prototype Pollution (CWE-1321) — high confidence only\n\nReport only with a gadget: a recursive merge\u002Fset of user JSON (`lodash.merge`, `_.set` with user paths, hand-written deep merge) where `__proto__` or `constructor.prototype` reaches a property later read for an auth decision, a `child_process` option (`shell`, `env`), or a template option.\n\n```ts\n\u002F\u002F ❌ deepMerge(defaults, req.body) with {\"__proto__\": {\"isAdmin\": true}}\n\u002F\u002F ✅ validate the body against a schema first; build lookups with Object.create(null) or Map\n```\n\n## 6. Templates and Rendering\n\n- EJS `\u003C%- user %>`, Handlebars `{{{ user }}}`, Pug `!= user` → XSS.\n- `res.render(view, req.query)` or `{ ...req.body }` as locals: template options ride along (EJS `outputFunctionName`\u002F`escapeFunction`, CVE-2022-29078 class) → RCE.\n- User-controlled template source compiled with `Handlebars.compile`, `pug.compile`, `ejs.render`.\n\n## 7. Sandboxes and Code Loading\n\n- `vm`\u002F`vm.runInNewContext` is not a security boundary; `vm2` is discontinued after sandbox escapes. Running user code in either is CRITICAL when reachable.\n- `eval`, `new Function`, `require(userPath)`, dynamic `import(userPath)`.\n- `js-yaml` 3.x `load()` instantiates JavaScript types (`!!js\u002Ffunction`) — `safeLoad` or js-yaml 4's `load`.\n- `node-serialize` `unserialize` on input.\n\n## 8. HTTP Clients and Tokens\n\n- axios: an absolute URL passed where a path was expected overrides `baseURL` and sends the configured auth headers to that host (CVE-2025-27152 class) — validate that user-supplied paths are relative.\n- Redirect following by default in axios\u002Fgot\u002Fnode-fetch on user URLs (ssrf-and-url-allowlists).\n- `jsonwebtoken`: `jwt.decode` does not verify; `jwt.verify` without `algorithms`.\n- `crypto.timingSafeEqual` for MACs (throws on length mismatch — compare lengths first); `Math.random` for tokens.\n\n## 9. Express and Fastify Specifics\n\n- `app.set(\"trust proxy\", true)` trusts every hop's `X-Forwarded-For`.\n- `express.static(\".\")` or `express.static(__dirname)` serves source and `.env`.\n- `res.sendFile(path.join(dir, name))` instead of `res.sendFile(name, { root: dir })`.\n- Multer `file.originalname` used as the stored path.\n- A route registered before `app.use(authMiddleware)` runs without it.\n\n## Common Mistakes\n\n- Reporting `$queryRaw` tagged templates, TypeORM parameters or `execFile` arrays as injection.\n- Reporting prototype pollution with no gadget.\n- Reporting `JSON.parse` as unsafe deserialization.\n- Missing that a server action is reachable without the page that renders it.\n\n## Red Flags\n\n- Template literals inside `exec(`, `query(`, `raw(`, `$queryRawUnsafe(`.\n- `shell: true`.\n- `\"use server\"` files with exported mutations and no `auth()` call inside them.\n- `as string` on `req.query` \u002F `req.params` values used in a query.\n- `merge(`, `defaultsDeep(`, `set(` fed with `req.body`.\n\n## References (names and links only)\n\n[Node.js security best practices](https:\u002F\u002Fnodejs.org\u002Fen\u002Flearn\u002Fgetting-started\u002Fsecurity-best-practices) · [Next.js data security](https:\u002F\u002Fnextjs.org\u002Fdocs\u002Fapp\u002Fguides\u002Fdata-security) · CVE-2025-29927, CVE-2025-27152, CVE-2022-29078 · CWE-78, 89, 1321 · [OWASP Top 10:2025](https:\u002F\u002Fowasp.org\u002FTop10\u002F2025\u002F)\n","# Node and TypeScript Security Pitfalls\n\n## Overview\n\nTypeScript types vanish at runtime: `req.query.id: string` can arrive as an array or an object. Most Node findings come from that gap, from `exec` with a template string, from raw-query escape hatches in otherwise safe ORMs, and — in Next.js — from forgetting that a server action is a public endpoint.\n\n## 1. Runtime Types Are Not Declared Types\n\n```ts\n\u002F\u002F ❌ ?id[$ne]=x or ?id[]=a&id[]=b gives an object or array, not a string\nconst doc = await Orders.findOne({ id: req.query.id as string, owner: user.id });\n\u002F\u002F ✅ validate at the boundary (zod\u002Fvalibot\u002Fclass-validator) and coerce\nconst { id } = z.object({ id: z.string().uuid() }).parse(req.query);\n```\n\nLength, `includes` and equality checks on an unvalidated query value can be bypassed the same way.\n\n## 2. child_process (CWE-78, CWE-88)\n\n```ts\n\u002F\u002F ❌ shell\nexec(`convert ${file} out.png`);\nspawn(\"git\", [\"clone\", url], { shell: true });\n\u002F\u002F ✅ no shell, end of options\nexecFile(\"git\", [\"clone\", \"--\", url, dir]);\n```\n\nAlso check the `env` option for request-controlled keys (`NODE_OPTIONS=--require …`).\n\n## 3. Raw Queries in Safe ORMs (CWE-89)\n\n| Library | Unsafe | Safe |\n|---------|--------|------|\n| Prisma | `$queryRawUnsafe`, `$executeRawUnsafe`, `Prisma.raw()` | `$queryRaw` tagged template, model methods |\n| TypeORM | `query(\"… \" + x)`, `.where(\\`id = ${id}\\`)` | `.where(\"id = :id\", { id })` |\n| Sequelize | `sequelize.query(\\`… ${x}\\`)`, `literal(x)` | `replacements` \u002F `bind` |\n| Knex | `knex.raw(\\`… ${x}\\`)` | `knex.raw(\"… ?\", [x])` |\n| Drizzle | `sql.raw(x)` | `sql\\`… ${x}\\`` |\n\nMongo\u002FMongoose: operator injection from JSON bodies (section 1), `$where`.\n\n## 4. Next.js Server Actions and Route Handlers\n\n- Every exported async function in a `\"use server\"` file is a callable POST endpoint, whether or not a page renders a form for it. Each must authenticate and authorize **inside** the action.\n\n```ts\n\u002F\u002F ❌ the page is admin-only, the action is not\n\"use server\";\nexport async function deleteUser(id: string) { await db.user.delete({ where: { id } }); }\n\u002F\u002F ✅\nexport async function deleteUser(id: string) {\n  const session = await auth();\n  if (session?.user.role !== \"admin\") throw new Error(\"forbidden\");\n  await db.user.delete({ where: { id } });\n}\n```\n\n- Authorization done only in `middleware.ts`: middleware matchers miss paths, and Next.js \u003C 15.2.3 \u002F 14.2.25 \u002F 13.5.9 \u002F 12.3.5 let an `x-middleware-subrequest` header skip middleware entirely (CVE-2025-29927). Check in the handler or data layer too.\n- Server components passing whole records to client components serialise every field into the page payload.\n- `NEXT_PUBLIC_*` variables are shipped to the browser.\n\n## 5. Prototype Pollution (CWE-1321) — high confidence only\n\nReport only with a gadget: a recursive merge\u002Fset of user JSON (`lodash.merge`, `_.set` with user paths, hand-written deep merge) where `__proto__` or `constructor.prototype` reaches a property later read for an auth decision, a `child_process` option (`shell`, `env`), or a template option.\n\n```ts\n\u002F\u002F ❌ deepMerge(defaults, req.body) with {\"__proto__\": {\"isAdmin\": true}}\n\u002F\u002F ✅ validate the body against a schema first; build lookups with Object.create(null) or Map\n```\n\n## 6. Templates and Rendering\n\n- EJS `\u003C%- user %>`, Handlebars `{{{ user }}}`, Pug `!= user` → XSS.\n- `res.render(view, req.query)` or `{ ...req.body }` as locals: template options ride along (EJS `outputFunctionName`\u002F`escapeFunction`, CVE-2022-29078 class) → RCE.\n- User-controlled template source compiled with `Handlebars.compile`, `pug.compile`, `ejs.render`.\n\n## 7. Sandboxes and Code Loading\n\n- `vm`\u002F`vm.runInNewContext` is not a security boundary; `vm2` is discontinued after sandbox escapes. Running user code in either is CRITICAL when reachable.\n- `eval`, `new Function`, `require(userPath)`, dynamic `import(userPath)`.\n- `js-yaml` 3.x `load()` instantiates JavaScript types (`!!js\u002Ffunction`) — `safeLoad` or js-yaml 4's `load`.\n- `node-serialize` `unserialize` on input.\n\n## 8. HTTP Clients and Tokens\n\n- axios: an absolute URL passed where a path was expected overrides `baseURL` and sends the configured auth headers to that host (CVE-2025-27152 class) — validate that user-supplied paths are relative.\n- Redirect following by default in axios\u002Fgot\u002Fnode-fetch on user URLs (ssrf-and-url-allowlists).\n- `jsonwebtoken`: `jwt.decode` does not verify; `jwt.verify` without `algorithms`.\n- `crypto.timingSafeEqual` for MACs (throws on length mismatch — compare lengths first); `Math.random` for tokens.\n\n## 9. Express and Fastify Specifics\n\n- `app.set(\"trust proxy\", true)` trusts every hop's `X-Forwarded-For`.\n- `express.static(\".\")` or `express.static(__dirname)` serves source and `.env`.\n- `res.sendFile(path.join(dir, name))` instead of `res.sendFile(name, { root: dir })`.\n- Multer `file.originalname` used as the stored path.\n- A route registered before `app.use(authMiddleware)` runs without it.\n\n## Common Mistakes\n\n- Reporting `$queryRaw` tagged templates, TypeORM parameters or `execFile` arrays as injection.\n- Reporting prototype pollution with no gadget.\n- Reporting `JSON.parse` as unsafe deserialization.\n- Missing that a server action is reachable without the page that renders it.\n\n## Red Flags\n\n- Template literals inside `exec(`, `query(`, `raw(`, `$queryRawUnsafe(`.\n- `shell: true`.\n- `\"use server\"` files with exported mutations and no `auth()` call inside them.\n- `as string` on `req.query` \u002F `req.params` values used in a query.\n- `merge(`, `defaultsDeep(`, `set(` fed with `req.body`.\n\n## References (names and links only)\n\n[Node.js security best practices](https:\u002F\u002Fnodejs.org\u002Fen\u002Flearn\u002Fgetting-started\u002Fsecurity-best-practices) · [Next.js data security](https:\u002F\u002Fnextjs.org\u002Fdocs\u002Fapp\u002Fguides\u002Fdata-security) · CVE-2025-29927, CVE-2025-27152, CVE-2022-29078 · CWE-78, 89, 1321 · [OWASP Top 10:2025](https:\u002F\u002Fowasp.org\u002FTop10\u002F2025\u002F)\n",{"name":5,"source":24,"category":25,"tech_stack":26,"description":7},"original; informed by trailofbits\u002Fskills (CC BY-SA 4.0, ideas only, own wording) and anthropics\u002Fclaude-code security-guidance plugin (ideas only); Node.js, Next.js and library security advisories cited, not reproduced","security","TypeScript & Node","main","910394a0b6db9fc8c9a8f36328ec421d3ebd8b38","catalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fnode-typescript-security-pitfalls",18,"https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper","https:\u002F\u002Ftasktrooper.ai","https:\u002F\u002Fgithub.com\u002Fmakifbaysal","Senior Software Developer","2026-11-15 04:50:29",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add makifbaysal\u002Ftasktrooper --skill node-typescript-security-pitfalls",{"tool":42,"command":43},"bunx","bunx skills add makifbaysal\u002Ftasktrooper --skill node-typescript-security-pitfalls",{"tool":45,"command":46},"pnpm","pnpm dlx skills add makifbaysal\u002Ftasktrooper --skill node-typescript-security-pitfalls","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fnode-typescript-security-pitfalls\u002FSKILL.md",true,[],[51,57,64,71,78,85],{"skillNo":52,"name":53,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7CSVEPQW6J6TD6CS2T5FPNZ","visual-craft","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fvisual-craft\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7CSVAQG91ETHQ0HBNZDG5FR","ux-copy","Use when you write any words a user reads in a mockup or a hand-off - content language and voice, buttons, labels, errors, empty states, confirmations, numbers and dates, and the longest-string check","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fux-copy\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7CSV6H0J38659NDXHJQ8396","screen-mockup-html","Use when you draw screens as the design task's HTML mockup - ONE canvas document holding every screen and every variant side by side, the sanitizer-safe recipe, phone and wide frames, the states grid, static control states, and the loopback self-check with screenshots at 375, 768 and 1440 attached to the task","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fscreen-mockup-html\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7CSV3JFRF3BM3XK52M7YEYR","performance-awareness","How the performance score moves for your role. Use when the score context shows a declining trend, or before handing off work you have not self-checked against every criterion.","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fperformance-awareness\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7CSTZDH00YRF5SCT7BRT9QD","design-variants","Use when a screen design needs variants - how many, variants as side-by-side rows on the one canvas, what makes two variants genuinely different, recommending one, how the human's choice is read, and narrowing to the chosen one in revision","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-variants\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M7CSTV6P3SM3PAE28DB0RF77","design-system-authoring","Use when you derive, change or extend a design system - where tokens live per stack, the DTCG token tree, role-based names for both themes, base vs layer vs drift, the DESIGN.md section order, the inventory format, the contrast check and the lint every proposal returns","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-system-authoring\u002FSKILL.md",[],[]]