Repository navigation
fix(fastify): answer 403 for a path the static plugin refuses - #18414
Merged
kamilmysliwiec merged 1 commit intoNov 5, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
@fastify/staticrefuses a request path that holds a null byte (/static/a%00) or a backslash (/static/%5Ca.txt). Before 10.1.10 it threw a plainError('Forbidden')withstatusCode403 and noexposeflag.FastifyAdapter.mapExceptionmaps onlyFastifyErrorand http-errors errors, so this error stayed raw. Nest answered500 Internal server errorand logged a stack trace. Plain Fastify answers 403. A scanner that sends%00or\to a static prefix caused 5xx answers, error logs and 5xx alerts.@fastify/static10.1.10 (fastify/fastify-static#624) throws aFastifyErrorwith codeFST_STATIC_FORBIDDEN_PATHinstead, andmapExceptionalready maps that to a 403HttpException. The peer range of@nestjs/platform-fastifyis 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?
@fastify/staticpeer range is^10.1.10, the first release that throws theFastifyError.integration/send-files/e2e/fastify.spec.tshas aFastify static assetsblock: a served file answers 200, and/static/a%00,/static/%00and/static/%5Ca.txtanswer 403{"statusCode":403,"message":"Forbidden"}. The three 403 tests fail with@fastify/static10.1.9 and pass with 10.1.10.I kept the fix out of
mapExceptionon purpose: a rule such as "anErrorwith a 4xxstatusCodeis anHttpException" would undo #17709, where SDK errors (AWS, Elasticsearch) must stay a 500. TheFastifyErrorcheck 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?
The peer range is raised.
@fastify/staticis 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 rootpackage.jsonandsample/17-mvc-fastifyalready 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-filesandintegration/http-adapters(15 files, 257 passed, 3 skipped),packages/platform-fastify(22 files, 349 passed).