anantbhandarkar/make-it-right/mir-backend-node-fastify
Claude Code and agent skill by anantbhandarkar/make-it-right
- community
Checking that the SKILL.md file is still in the repository.
Make It Right (Fastify module). Fastify 5 + Node.js specific reliability augmentation. Use alongside mir-backend and mir-backend-node when the target stack is Fastify — it carries the mechanical footguns that the framework-agnostic tiers deliberately omit: schema-first validation and response serialization (and the data-leak risk of skipping the response schema), the fact that additionalProperties:false STRIPS rather than rejects under Fastify's default Ajv settings, the v5 full-JSON-schema requirement, server defaults that ship wide open (requestTimeout 0, connectionTimeout 0, maxParamLength 100, trustProxy false), the reply lifecycle and double-send traps, plugin encapsulation and decorator scoping, hook ordering for authentication, and the Content-Type validation-bypass CVE chain. TRIGGER only when the Node backend stack is Fastify used directly — building, reviewing, or debugging a Fastify route, plugin, hook, schema, or error handler. Always loads TOGETHER WITH mir-backend (the gates) and mir-backend-node (V8 event-loop / process-model concerns: blocking, worker_threads, unhandled rejections, backpressure, timeouts, npm supply chain); this module only adds Fastify library mechanics. SKIP for Express, Hapi, or Koa (each has its own mir-backend-node-<framework> module), SKIP for NestJS even when it runs on the Fastify adapter — that stack loads mir-backend-node-nestjs instead — and SKIP for non-Node runtimes.
Install
npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-node-fastifySKILL.md
The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-node-fastify.
/mir-backend-node-fastify · Make It Right (Fastify)
Bottom tier of the chain: mir-backend (generic gates) → mir-backend-node (V8/Node event-loop model) → this (Fastify library mechanics). Run the gates first; load the Node runtime tier for event-loop and process-model concerns; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (blocking the event loop, worker_threads, unhandled rejections, stream backpressure, timeouts, heap limits, npm supply chain) live in `mir-backend-node` — not here.
Stack assumed (npm registry, 13 Aug 2026): fastify@5.11.3 is latest. Fastify 4 reached end of life on 2025-06-30 and gets no security fixes — the four tag sits at 4.29.1. A 6.0.0-alpha.0 exists on the next tag (published 2026-08-11); it is a pre-release, do not target it. Fastify 5 requires Node ≥ 20, but target Node 22/24 per the runtime tier — Node 20 is EOL.
Minimum patched version is 5.8.5, not just "5.x" — see the CVE chain in Security.
The Fastify footguns AI walks into most
1. Skipping the response schema leaks internal fields
Fastify's JSON serialization is driven by fast-json-stringify using the JSON Schema on the route. The response schema does two things: it makes serialization faster than JSON.stringify, and it strips any field not declared in the schema. With no response schema, Fastify applies no serialization filter at all and the full internal object goes to the client:
Define a response schema for every route, including error responses — a 500 shape without a schema will happily serialize whatever your error object carries.
2. additionalProperties: false STRIPS extra fields — it does not reject them
This is the correction most Fastify code needs. Fastify's default Ajv options are coerceTypes: 'array', useDefaults: true, `removeAdditional: true`, allErrors: false. With removeAdditional: true, a schema that sets additionalProperties: false causes Ajv to delete the unexpected keys and continue — the request succeeds with a 200, and nothing tells you the client sent isInternal: true.
That is safe against mass assignment (the field never reaches your handler) but it hides a misbehaving or hostile client, and it means "we return 400 on unknown fields" is false unless you changed the Ajv options:
Validation itself is also opt-in per section: Fastify validates body, params, querystring, and headers only if you declare a schema for that section. No body schema means request.body is the raw parsed payload — no required-field enforcement, no type coercion, nothing.
Two more Ajv defaults worth knowing because they change values silently: coerceTypes: 'array' turns "5" into 5 and wraps a scalar into a single-element array when the schema says array; useDefaults: true injects schema default values into request.body, so a field you never sent can arrive populated.
3. Fastify 5 requires full JSON schemas — shorthand was removed
The jsonShorthand option is gone. Every schema section needs a complete JSON Schema including type:
The failure is at boot, not at request time, so it is cheap to catch — but AI generates the shorthand form constantly because Fastify 4 examples dominate. The same change makes it easier to swap the validator compiler for Zod or TypeBox if you prefer TypeScript-first schemas.
4. The double-send trap — return the payload OR call reply.send, never both
Fastify routes can either return the payload (Fastify sends it) or call reply.send(payload). Doing both in an async handler sends the response twice and Fastify raises FST_ERR_REP_ALREADY_SENT:
The subtle version: in an async handler that calls reply.send() inside a branch and then falls through, the implicit return undefined is treated as a payload. When you send manually from an async handler, return reply to tell Fastify you have taken over.
5. Plugin encapsulation — decorators and hooks are scoped, not global
Without fastify-plugin (fp), decorators, hooks, and request/reply extensions registered in a child plugin are not visible to sibling plugins or to the parent. AI code that decorates in one plugin and uses it in another without fp fails at runtime with FST_ERR_DEC_MISSING_DEPENDENCY:
Rule: shared infrastructure (DB, Redis, config, auth decorators) → wrap with `fp`. Route groups that should be isolated (own prefix, own hooks) → do NOT use fp. Encapsulation is also the reason a preHandler hook added inside one plugin does not protect routes registered in another — a security-relevant scoping mistake, not just an ergonomic one.
6. Hook ordering — onRequest for auth, setErrorHandler for errors
Hooks run in this order per request:
- Authentication:
onRequest(before any body parsing — fail fast and cheap). - Webhook HMAC signatures are not a `preHandler` job. Stripe, GitHub, Slack and friends sign the exact bytes they sent.
request.bodyis a parsed object; re-serialising it changes key order, whitespace, unicode escaping, and duplicate-key handling, so the digest will not match — and if you make it match by normalising, you are authenticating bytes the provider never signed. Capture the raw buffer withaddContentTypeParser('application/json', { parseAs: 'buffer' }, …)(or@fastify/raw-bodyon that route), compare withcrypto.timingSafeEqual, and parse only after the signature verifies. - Route-level hooks go in the route options (
preHandler: [...]). Do not register a globalpreHandlerwhen you only want auth on some routes. - Errors:
setErrorHandleris the single place for consistent mapping. Express-style(err, req, res, next)does not exist. Handlers registered inside an encapsulated plugin apply only to that scope.
The missing return in a hook is a real defect: reply.send() without returning lets the lifecycle continue to the handler in some flows, which is how "the 401 fired but the row was still updated" happens.
7. Server defaults that are wider than you expect
Verified against the Fastify server reference:
| Option | Default | What it means in production | |
|---|---|---|---|
requestTimeout | 0 | no request timeout — a slow client can hold a connection indefinitely | |
connectionTimeout | 0 | no socket timeout | |
keepAliveTimeout | 72000 ms | must exceed the idle timeout of any load balancer in front, or you get random 502s | |
bodyLimit | 1048576 (1 MiB) | applies per route unless overridden; raising it is a memory decision | |
maxParamLength | 100 | a route param longer than 100 chars 404s — bites when a token or a long slug is in the path | |
trustProxy | false | request.ip is the proxy until you set this | |
caseSensitive | true | /Users and /users are different routes | |
ignoreTrailingSlash | false | /users and /users/ are different routes | |
onProtoPoisoning / onConstructorPoisoning | 'error' | good default — but only for the built-in JSON parser (see Security) |
Also changed in Fastify 5, and each is a startup or runtime failure rather than a warning: the logger option no longer accepts a logger instance (use loggerInstance); semicolon query delimiters are off (useSemicolonDelimiter: true to restore); variadic listen(port, host) was removed in favour of listen({ port, host }); request.connection was removed (use request.socket); a DELETE with Content-Type: application/json and an empty body is now rejected; hasRoute() matches only the exact registered string.
Security
Fastify-specific mechanics. Runtime-level items (SSRF, command injection, prototype pollution in your own merges, path traversal helpers, npm supply chain, secrets in logs) live in mir-backend-node.
Current advisory class: Content-Type validation bypass, three CVEs in one chain
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mir-backend-node-fastify/SKILL.md
Popularity
- Repository stars
- 15
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-node-fastify)