Repository navigation
fix: stop counting Swagger decorators as auth, flag empty and unsupported scans - #31
Conversation
app.get()/router.get() calls are also Hono and Koa syntax, so a Hono app got "express" endpoints and PASS. They now count only when a scanned file imports or requires express or the target's package.json declares it; otherwise a Hono-only scan is NOTHING_ANALYSED.
require(`express`) with a template literal now counts, and an import inside a comment no longer makes a Hono app Express. The status contract (README JSON schema, --help, exit-code wording with requireSpec) lists NOTHING_ANALYSED, and the historical ApiBearerAuth note matches the 0.4.1 defaults.
Second-model reviewThree passes by a different model than the one that wrote the change: a full review at
Minor, not fixed in this PR: Verdict: approve In plain EnglishApiGate said PASS in cases where it had not really checked anything: a repository with no routes it can read, and a Hono app whose routes it mistook for Express routes. It also treated a documentation-only NestJS decorator as a login check. Now those scans say NOTHING_ANALYSED, other frameworks' routes are ignored unless the project uses Express, and the decorator no longer counts as protection. The remaining risk is a project that mixes Express with another framework: there, the other framework's routes can still be read as Express, and the README says so. |
No open issue covers these. All three came from a demo rehearsal of ApiGate 0.4.0 on public repositories. The empty-scan point is related to #9 (closed), which made the score
n/afor a scan with no endpoints; the status still said PASS.What changed
lib/config.mjs).@ApiBearerAuth,@ApiCookieAuthand@ApiSecurityare no longer defaultauth.nestmarkers.@ApiOAuth2and@ApiBasicAuthnever were. These@nestjs/swaggerdecorators only describe the OpenAPI document.c1c2cc4: 20 of 21 endpoints were GUARDED withmatchedAuthMarker: "ApiBearerAuth", while the app's real auth is anAuthMiddlewareapplied with.forRoutes(...)to a few routes.auth.neststill counts them, because a list replaces the defaults.lib/gate.mjs,apigate.js,lib/report.mjs).NOTHING_ANALYSEDin the console, the JSONstatusandgate.status, and the HTML badge.NOTICE:line, which is also the HTML hero text, says that ApiGate reads only Express, Fastify and NestJS routes and OpenAPI 2/3 specs.--fail-on empty(no-endpoints) andrequireSpec(missing-spec) still make it FAIL.aabb901: 0 endpoints and PASS.lib/parsers/express.mjs,lib/inventory.mjs).app.get(...)androuter.get(...)are also Hono and Koa syntax. The Express parser's endpoints now count only when a scanned file imports or requiresexpress, or the target'spackage.jsondeclares it.import()andrequire(), with quotes or a plain template literal. TypeScript files (regex fallback) are checked with comments removed. A commented-out import does not count.package.json.parserCapabilities.express.expressRequiredstates the rule in the JSON report.1e2333d: 2 "express" endpoints fromapps/remix/server/router.ts, which is a Hono app, and PASS.app.use, a mount's middleware; not a path-onlyapp.use('/api/x', helper)), and that anauth.<framework>list replaces the defaults;NOTHING_ANALYSEDin the JSON sample, the exit-code table and--help, and the exit-code wording withrequireSpec;ApiBearerAuthscan note now says it used the old defaults.security.isAuthorized()yields the markerisAuthorized, a path-lessapp.use(requireAuth)guards later routes, andapp.use('/api/scoped', requireAuth)leavesGET /api/scopedOPEN.package.json,package-lock.json, CHANGELOG## [0.4.1] - 2026-11-16, and the README JSON sample"version".Proof
"On main" means the branch's test files run against
53dfed4.test/auth.mjs: NestJS endpoint whose only auth-looking decorator is from @nestjs/swagger → OPENApiBearerAuth: expected "OPEN", got "GUARDED"test/auth.mjs: NestJS endpoint with @UseGuards next to @ApiBearerAuth → GUARDED by UseGuardsexpected "UseGuards", got "ApiBearerAuth"test/gates.mjs: empty directory: NOTHING_ANALYSED, not PASS, and stdout names the supported frameworksexpected "NOTHING_ANALYSED", got "PASS"test/gates.mjs: only an unsupported framework (FastAPI): NOTHING_ANALYSED, not PASSexpected "NOTHING_ANALYSED", got "PASS"test/gates.mjs: only an unsupported JS framework (Hono app.get in .ts and .js): NOTHING_ANALYSED, not PASSexpected "NOTHING_ANALYSED", got "PASS"test/gates.mjs: an express import inside a comment does not make a Hono app Expressexpected "NOTHING_ANALYSED", got "PASS"test/gates.mjs: require(express) with a template literal counts as Expressa323af1(expected "PASS", got "NOTHING_ANALYSED")test/gates.mjs: express declared only in package.json / imported in another scanned file: a router received as a parameter still countstest/gate.mjs"no-endpoints fires only with failOn.emptyInventory ..." now expectsNOTHING_ANALYSEDinstead ofPASSfor the empty case without the opt-in. The golden snapshot and the determinism tests are unchanged and pass.Real repositories
Before: 0.4.0 at
53dfed4. After: this branch at6f057f6. Same clones, same commits.1e2333daabb901266448ac1c2cc4ApiBearerAuth), score 100The NestJS app's real auth is an
AuthMiddlewareapplied with.forRoutes(...), which ApiGate does not read, so OPEN is what it can prove.Gate
npm ci && npm run lint && npm teston Node 22.23.4 at6f057f6, exit 0, 0 failed:npm pack --dry-run: 26 files.git diff --check 53dfed4..HEAD: clean.Not changed
package.jsonis read for the Express rule; apackage.jsoninside a workspace folder is not.