Skip to content

fix(fastify): answer 403 for a path the static plugin refuses - #18414

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
pavstev:fix/fastify-static-refusal-status
Nov 5, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
pavstev:fix/fastify-static-refusal-status

Conversation

@pavstev

@pavstev pavstev commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

@fastify/static refuses a request path that holds a null byte (/static/a%00) or a backslash (/static/%5Ca.txt). Before 10.1.10 it threw a plain Error('Forbidden') with statusCode 403 and no expose flag. FastifyAdapter.mapException maps only FastifyError and http-errors errors, so this error stayed raw. Nest answered 500 Internal server error and logged a stack trace. Plain Fastify answers 403. A scanner that sends %00 or \ to a static prefix caused 5xx answers, error logs and 5xx alerts.

@fastify/static 10.1.10 (fastify/fastify-static#624) throws a FastifyError with code FST_STATIC_FORBIDDEN_PATH instead, and mapException already maps that to a 403 HttpException. The peer range of @nestjs/platform-fastify is still ^10.1.2, so an app that keeps 10.1.2 to 10.1.9 in its lockfile still gets the 500.

Issue Number: N/A

What is the new behavior?

  • The @fastify/static peer range is ^10.1.10, the first release that throws the FastifyError.
  • integration/send-files/e2e/fastify.spec.ts has a Fastify static assets block: a served file answers 200, and /static/a%00, /static/%00 and /static/%5Ca.txt answer 403 {"statusCode":403,"message":"Forbidden"}. The three 403 tests fail with @fastify/static 10.1.9 and pass with 10.1.10.

I kept the fix out of mapException on purpose: a rule such as "an Error with a 4xx statusCode is an HttpException" would undo #17709, where SDK errors (AWS, Elasticsearch) must stay a 500. The FastifyError check that exists already covers this case.

For comparison, Express and the Node adapter answer 404 for these paths, because their static handlers fall through to Nest. Fastify answers 403, as the plugin intends.

Does this PR introduce a breaking change?

  • Yes
  • No

The peer range is raised. @fastify/static is an optional peer dependency, so an app that uses 10.1.2 to 10.1.9 gets a peer warning and should update the plugin. Nothing else changes for it. The root package.json and sample/17-mvc-fastify already use 10.1.10, since #18397 bumped them yesterday. This PR finishes that bump for the peer range, which Renovate does not touch.

Other information

Checks run: npm run lint, npm run build, integration/send-files and integration/http-adapters (15 files, 257 passed, 3 skipped), packages/platform-fastify (22 files, 349 passed).

@kamilmysliwiec
kamilmysliwiec merged commit a838e0e into nestjs:master Nov 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants