Skip to content

fix: scope largeArrayMechanism options per build() call - #899

Merged
Tony133 merged 2 commits into
mainfrom
fix/large-array-mechanism-global-state
Oct 16, 2026
Merged

Tony133 merged 2 commits into
mainfrom
fix/large-array-mechanism-global-state

Conversation

@mcollina

Copy link
Copy Markdown
Member

Scopes largeArraySize and largeArrayMechanism to each build() call instead of module-level state.

Previously these two values were module globals that build() mutated and never reset, so any unrelated build() call opting into largeArrayMechanism: 'json-stringify' leaked into every serializer built afterwards — even ones built with no options. That silently disabled the schema filtering (missing fields / additionalProperties: false) for unrelated schemas, which is what Fastify relies on to redact fields from responses.

The fix moves both options onto the per-build context object and branches on them there. A regression test builds a serializer without options after a json-stringify build and asserts filtering is still applied.

Fixes GHSA-jqm2-x2jx-52q2.

largeArraySize and largeArrayMechanism were module-level state that build()
mutated and never reset, so an unrelated build() call opting into
'json-stringify' for its own schema leaked into every serializer built
afterwards, even ones built with no options. This silently defeated the
documented schema filtering (missing fields / additionalProperties: false).

Move both values onto the per-build context and branch on them there.
Add a regression test that builds a serializer without options after a
json-stringify build and asserts filtering is preserved.

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Tony133
Tony133 merged commit 5f69709 into main Oct 16, 2026
20 checks passed
@Tony133
Tony133 deleted the fix/large-array-mechanism-global-state branch October 16, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants