Skip to content

Health: only real login checks in app.use() hide open Express endpoints (#72) - #85

Merged
haydenschmitty merged 1 commit into
haydenschmitty:mainfrom
ahmedjanwar:fix/72-express-global-guard
Nov 15, 2026
Merged

haydenschmitty merged 1 commit into
haydenschmitty:mainfrom
ahmedjanwar:fix/72-express-global-guard

Conversation

@ahmedjanwar

Copy link
Copy Markdown
Contributor

What this changes

Fixes #72. An app-wide app.use(...) counted as a login check whenever any guard-like word appeared in its arguments, which turned off the open-endpoint check for every route behind it. In the issue's words, "No open endpoints" then looks like a clean result.

Following the directions suggested in the issue:

  • Strings are ignored. A header name like 'X-Refreshed-Token' in cors({ exposedHeaders: [...] }) no longer counts as a check.
  • Middleware that never turns anyone away is skipped: cors, helmet, body parsers, express.static, express-session, passport.session(), rate limiters and similar.
  • "guard" alone isn't enough for a .use(). Because such a guard clears every route after it, the name must also say what it checks (authGuard, requireUser, verifyToken). createShutdownGuard() no longer counts.

The arguments of .use(...) are now read with brackets balanced, one argument at a time. Before, the match stopped at the first ), so a real check listed after other middleware, as in app.use(cors(), requireUser), was missed and those routes were reported as open. That case is now found too.

It also fixes the small . bug noted in the issue. For a project that is one repo at its root, the title now reads "None of your endpoints check who is calling". Issue ids are unchanged, so existing "Not a problem" choices still apply.

I didn't change the shared isGuardName, to stay clear of #73. Naming the app-wide guard in the Health panel, the issue's third suggestion, needs a UI change, so I've left it out of this PR. I'm happy to follow up if you'd like it.

How I tested it

  • New tests/express-global-guard.test.mjs, built on the issue's sample (TypeScript, Express, one repo):
    • strings inside cors and express.json options don't count;
    • session, passport.session() and helmet don't count;
    • createShutdownGuard() doesn't count;
    • real app-wide checks still protect: requireAuth, authGuard, verifyToken(), jwt({...}), and cors(), requireUser;
    • the title has no ..
  • All 5 tests fail without the change and pass with it.
  • Mapped node-express-realworld-example-app (TypeScript, Express, one repo) before and after the change: Health's issues are identical.
  • Also ran it on a FastAPI project of my own (one repo, Python and plain JS) to check nothing else changed. (Its own app-wide @app.middleware("http") guard isn't recognised yet, but that's a separate FastAPI case, not touched here.)

Checklist

  • No new dependencies
  • Anything the map shows people is in plain language
  • No secret values stored or printed
  • No details of a real private project in code, comments, docs or screenshots
  • npm test passes (207 passed, 1 platform skip)
  • claude plugin validate . passes
  • CHANGELOG.md updated, if people will notice the change

…ts (haydenschmitty#72)

An app-wide app.use(...) counted as a login check whenever any
guard-like word appeared in its arguments, which turned off the
open-endpoint check for every route behind it:

- words inside strings, like a header named 'X-Refreshed-Token' in
  cors({ exposedHeaders: [...] }), are ignored
- middleware that never turns anyone away (cors, helmet,
  express-session, passport.session(), body parsers...) is skipped
- a name that only says "guard" (createShutdownGuard) needs a word
  saying what it checks (authGuard, requireUser, verifyToken)

The arguments are now read with brackets balanced, so a real check
listed after other middleware, as in app.use(cors(), requireUser),
is found too; before, the match stopped at the first ")".

The "None of your endpoints check who is calling" title no longer
shows "." for a project that is a single repo at its root.
@haydenschmitty

Copy link
Copy Markdown
Owner

Merged and released in 0.9.0. Thank you!

Update with claude plugin update floorplan@floorplan.

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.

Health: any app.use() with a guard-like word turns off the open-endpoint check

2 participants