Repository navigation
feat(nest): detect global guards and setGlobalPrefix - #21
Merged
Merged
Conversation
Contributor
Author
Second-model review
Verdict: approve. In plain EnglishNestJS apps usually switch on login protection once for the whole app, and ApiGate missed that and reported every endpoint as unprotected. It now detects that app-wide guard, honors the usual "this endpoint is public" markers, and adds the app-wide path prefix such as |
This was referenced Nov 15, 2026
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.
Closes #11
What changed
lib/parsers/nest.mjs: a pre-pass over every scanned file (comments stripped) collects{ provide: APP_GUARD, useClass: X }anduseExisting: Xproviders,app.useGlobalGuards(new X(...))calls andapp.setGlobalPrefix(...). Each global guard's class name becomes an auth marker on every Nest endpoint, and classification still goes through the configuredauth.nestnames. A literal prefix is applied and a literalexcludearray is honored. A non-literal or conflicting prefix leaves the endpointsresolved: falsewith the new reasonglobal-prefix-not-static-string.publicDecorators(defaultPublic,SkipAuth,AllowAnonymous), read inlib/config.mjsand passed bylib/inventory.mjs. A controller or method that carries one of them stays OPEN despite a global guard.@Get(...)are now read, and a method declared on the anchor line (@Get() list() {}) no longer takes the decorators of the next method.lib/capabilities.mjs:parserCapabilities.nest.globalGuardDetectionistrue, with new keysglobalGuardRules,globalPrefix,publicDecoratorsand the new reason.lib/report.mjs: the global-guard limitation now says what is and is not detected..apigate.config.example.jsonandCHANGELOG.md[Unreleased].test/parser-nest.mjs, plustest/config.mjsandtest/capabilities.mjs. Fixtures:test/fixtures/nest-global/(the issue's reproduction),nest-global-edge/,nest-global-nonliteral/andnest-global-orgonly/.main(docs: remove links to private Stelnyx repositories #19 and chore(deps): clear audit advisories, bump ESLint 10, drop Node 18 #20) is merged into the branch. The only overlap was the[Unreleased]CHANGELOG section, which now has oneAdded, oneChangedand oneFixedlist.Proof per acceptance criterion
node apigate.js test/fixtures/nest-globalreportsGET /api/usersGUARDED (JwtAuthGuard),POST /api/usersGUARDED (JwtAuthGuard) andGET /api/users/healthOPEN (Public), all resolved; the summary line readsENDPOINTS: 3 (2 guarded, 1 open, 0 unknown, 0 intentional-public).test/parser-nest.mjsasserts the same three postures.parserCapabilities.nest.globalGuardDetection === true(test/capabilities.mjs).test/fixtures/nest-global-orgonly/(useClass: OrgGuard). The README states the rule: a global guard counts as auth only when its class name is inauth.nest.npm testpasses. No golden number moved:test/golden-apigate.mjsandtest/determinism.mjsuse the Express sample app and pass unchanged, and the existing Nest fixtures give the same endpoints as onmain.test/parser-nest.mjsgave 12 passed and 8 failed; after it, all 21 pass (including the review round's new test).Gate
npm ci && npm run lint && npm testat 451cb9b, after the merge ofmain(so with ESLint 10):N passed, 0 failed.Behavior change to know before upgrading
The anchor-line fix also applies to apps without a global guard. A one-line method such as
@Get("two") two() {}no longer borrows the@UseGuards(...)of the method below it, so an endpoint that was wrongly reported GUARDED can now show as OPEN. That is the correct result, not a regression.Not done (documented in README, capabilities and the report)
useFactoryanduseValueproviders, guards passed as a variable, nested braces in the provider literal.RouterModulepath trees and versioning are out of scope in the issue.excludematches the un-prefixed path only. Themethodof a{ path, method }entry is not checked, so excludingGET pingalso un-prefixesPOST ping.samples/*reports were not regenerated.Suggested labels: enhancement