fix: hasRequestDecorator/hasReplyDecorator misses constructor-assigned built-in properties#6753
Open
LeSingh1 wants to merge 1 commit into
Open
fix: hasRequestDecorator/hasReplyDecorator misses constructor-assigned built-in properties#6753LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
…-assigned built-in properties
Properties like req.id, req.params, req.body, reply.raw, and reply.log
are set directly in the Request and Reply constructors rather than on
their prototypes. Because of this, hasRequestDecorator('id') returned
false and decorateRequest('id', null) silently succeeded, overwriting
the built-in value and causing a TypeError at request time.
This adds an instanceProperties set to Request and Reply listing those
constructor-assigned string-keyed properties, and teaches
decorateConstructor and the existence helpers to check that set.
hasRequestDecorator('id') now returns true, and decorateRequest('id')
now throws FST_ERR_DEC_ALREADY_PRESENT as expected.
metcoder95
approved these changes
Jun 5, 2026
| if (Object.hasOwn(instance, name) || hasKey(konstructor, name)) { | ||
| if (Object.hasOwn(instance, name) || hasKey(konstructor, name) || hasInstanceProperty(konstructor, name)) { | ||
| throw new FST_ERR_DEC_ALREADY_PRESENT(name) | ||
| } |
Member
There was a problem hiding this comment.
I wonder if this should be named coreProperty rather than instanceProperty, since instanceProperty sounds a bit too general for the issue we are trying to address.
I would also recommend throwing a specific error when users try to override core properties. This would be more educational and would prevent them from searching for decorators they never set. For example, they might otherwise wonder where in their code they decorated request with id.
Example error code: FST_ERR_DEC_CORE_OVERRIDE.
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.
What
hasRequestDecoratorandhasReplyDecoratoronly check the constructor prototype and the decorator props list. But several core properties —req.id,req.params,req.raw,req.query,req.log,req.body,reply.raw,reply.request,reply.log— are assigned directly in theRequestandReplyconstructors, not on their prototypes.This means:
Root cause
checkRequestExistenceanddecorateConstructorinlib/decorate.jsuseObject.hasOwn(prototype, name)andname in prototype. Properties set in the constructor body are never on the prototype, so these checks miss them.Fix
Add an
instancePropertiesset toRequestandReplylisting their constructor-assigned string-keyed properties.decorateConstructorand thecheckRequest/ReplyExistencehelpers now also check this set (walking the parent chain for derived constructors).After the fix:
All 52 existing decorator tests pass. Six new node:test tests cover the bug and the fix.