Repository navigation
fix: use @fastify/error for forbidden path errors - #624
Merged
Merged
Conversation
SameRainbows
reviewed
Nov 4, 2026
SameRainbows
left a comment
There was a problem hiding this comment.
Solid improvement and clean alignment with Fastify error conventions.
A few key points verified:
- Standardizing on
@fastify/errorensures frameworks and custom error handlers (like NestJS'sHttpExceptionmapper) properly recognize the error code and 403 HTTP status rather than falling back to unhandled 500s. - Creating
FST_STATIC_FORBIDDEN_PATHinlib/errors.jsmatches the existing plugin error conventions (#599). - Updating
forbiddenPathError()simplifies creation while preserving the expected403 Forbiddenresponse format. - JSDoc annotations and
README.mderror table are cleanly synchronized. - Verified test suite passes with full statement and branch coverage, and all 15 CI matrix checks are green. Ready for maintainer merge.
4 of 12 tasks
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.
Since 10.1.1,
@fastify/staticrejects forbidden request paths such as//foobar.htmlor/static/../index.jswith a plainErrorthat hasstatusandstatusCodeset to 403. Every other error in the plugin uses@fastify/errorsince #599, so the intention seems clear.Fastify itself responds to both kinds of errors with a 403, but frameworks that handle Fastify errors themselves may not. NestJS 12.0.2 and later (nestjs/nest#17709) only treat a
FastifyErroror anhttp-errorserror as an HTTP error. This means that a plainErrorwith astatusCode(such as this one) becomes a 500 and is logged as an unhandled exception.This affects NestJS apps that serve files with
@fastify/static, including the Swagger UI from@nestjs/swagger.@fastify/static,GET /static/../index.js@nestjs/core12.0.1@nestjs/core12.0.2 … 12.3.2,@fastify/static10.1.8@nestjs/core12.3.2, this PRFix
FST_STATIC_FORBIDDEN_PATHerror (403, messageForbidden) inlib/errors.jsfollowing the pattern as #599forbiddenPathError(), replacing the plain errorThe default error response gets the same
codefield as the other errors of the plugin:The error no longer has a
statusproperty, like the other@fastify/errorerrors of the plugin. Nothing in the plugin reads it.Tests
//foobar.html403 test now also checks forcode: 'FST_STATIC_FORBIDDEN_PATH'.npm testpasses with 100% coverage on Node 20, 22, 24 and 26 on Linux. The type tests andnpm run lintpass. There is no benchmark script.Checklist
npm run test && npm run benchmark --if-presentand the Code of conduct