Repository navigation
fix(core,microservices): run transient global enhancers on controllers - #17993
Merged
kamilmysliwiec merged 1 commit intoOct 8, 2026
Merged
Conversation
micalevisk
suggested changes
Oct 2, 2026
micalevisk
left a comment
Member
There was a problem hiding this comment.
address the comments left by github-advanced-security
A global guard, pipe, interceptor or filter with transient scope never ran on a static controller. Nest created it, but the route and the message handler ran without it. A transient global auth guard left every such route open. The router and the microservice listener build the handlers of a static controller without an inquirer id. The global lookup returns early in that case and never reads the transient enhancers. The injector also did not create a per-controller instance for a static controller. The injector now loads the enhancers of a static controller with the controller as inquirer. The router and the listener pass the controller id when they build its handlers. A transient global enhancer now gets one instance per controller, the same as a transient dependency. Each controller keeps its instance across requests. A transient enhancer set on a controller or a method now gets one constructed instance per controller too. Before, the controllers shared one instance whose constructor never ran. Default and request scoped global enhancers behave as before. Closes nestjs#17991
johnnyhuirilef
force-pushed
the
fix/transient-global-enhancers
branch
from
October 2, 2026 21:27
1e57794 to
2465226
Compare
Contributor
Author
|
Thanks @micalevisk! π Good catch. The test route returned the |
4 of 6 tasks
kamilmysliwiec
added a commit
that referenced
this pull request
Oct 16, 2026
@nestjs/graphql builds the handlers of a static resolver through ExternalContextCreator.create() without an inquirer id, so the context creators returned only the singleton global enhancers, and Injector#loadProvider() never constructed the transient enhancers of a static provider. A transient APP_GUARD never ran on such resolvers, while it still guarded the REST routes of the same application, and a transient APP_INTERCEPTOR was not applied. As #17993 did for controllers, the bootstrap load of a static entry provider now constructs its transient enhancers with the provider as the inquirer, and ExternalContextCreator.create() defaults a missing inquirer id to that provider's wrapper id. Transient global guards and interceptors now run on default-scoped resolvers (a call the guard denies is rejected), and a transient guard bound with @UseGuards() to a resolver method gets a constructed instance. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-J6VYP0AI.
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
PR Type
What is the current behavior?
Issue Number: #17991
Closes #17991
Hi! π A global guard, pipe, interceptor or filter with transient scope never runs on a static controller. This includes the message handlers of microservice controllers. Nest creates it, but the handler runs without it. A transient global auth guard leaves every route on a static controller open.
The router and the microservice listener build the handlers of a static controller without an inquirer id.
getGlobalMetadata()returns early in that case and never reads the transient enhancers. The injector also does not create a per-controller instance for a static controller.I ran the repro on 12.1.2:
What is the new behavior?
The injector now loads the enhancers of a static controller with the controller as inquirer. The router and the microservice listener pass the controller id when they build its handlers. A transient global enhancer now gets one constructed instance per controller, the same as a transient dependency. Each controller keeps its instance across requests, and
INQUIRERis the controller.The same repro against a local build of this branch:
Does this PR introduce a breaking change?
Default and request-scoped global enhancers behave as before. Nothing exported changes.
Two behavior changes are worth a note:
@UseGuards(),@UsePipes(),@UseInterceptors()or@UseFilters()on a static controller now gets one constructed instance per controller. Before, the controllers shared one instance, and its constructor never ran, so injected dependencies wereundefined. The spec covers a method-level guard. I also checked a controller-level guard, pipe and interceptor by hand.onModuleInitrun once more for each static controller. Three existing assertions intransient-scope.spec.tscount this extra instance (4 β 5).Other information
The specs use a real app with real HTTP requests and a real TCP microservice. They cover these cases:
One case is out of scope. Static GraphQL resolvers call
ExternalContextCreator.create()without an inquirer id, so a transient global guard still does not run there. A fix there needs@nestjs/graphqlto pass the resolver as inquirer, and it can also need a small change in core to load the enhancers for resolvers. I am happy to open an issue for it. π