See how your app actually fits together. An interactive, plain-English map of your codebase, drawn by Claude or Codex.
JavaScript ai-codingarchitecture-diagramclaudeclaude-codeclaude-code-plugincodebase-visualizationcodexcodex-plugindeveloper-toolsonboardingopenaivibe-coding
fix(health): read an Express route's checks from its own arguments
Rudy Celekli225d1c91aebd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e23549b..415b6d1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,9 @@# Changelog+## Unreleased++- **Health reads each Express route's own checks:** a sign-in check in front of a handler defined elsewhere (`router.post('/books', requireAuth, createBook)`) was missed, so the endpoint was reported as open to anyone. The other way round, a route could borrow the check of the route below it, and a handler whose name sounds like a check (`updateUser`) was taken for one, so some open endpoints weren't reported. Fixed by @rudycelekli.+## 0.6.1 (2026-11-01)- **Fewer false alarms in Health** (thanks to the user who reported these):diff --git a/docs/development.md b/docs/development.mdindex 9293632..d2e4ed9 100644--- a/docs/development.md+++ b/docs/development.md@@ -80,7 +80,7 @@ The tests use Node's built-in test runner, so there's nothing to install (`npm t| `parsing.test.mjs` | imports, endpoints, web requests and doc comments, per language and framework || `helpers-lib.test.mjs` | globs, file types, command-line flags, fallback names || `secrets.test.mjs` | Health finds secrets, masks them, and ignores placeholders |-| `health.test.mjs` | which endpoints Health calls open to anyone (FastAPI sample in `fixtures/`) |+| `health.test.mjs` | which endpoints Health calls open to anyone (FastAPI and Express samples in `fixtures/`) || `stack-health.test.mjs` | Health's checks for Supabase row-level security, Firebase rules, Stripe webhook signatures, secret keys in public variables and CORS, with look-alikes each must leave alone, and a whole sample app done wrong and done right || `firebase.test.mjs` | Firebase Cloud Functions: callables and onRequest functions as endpoints, the website's calls to them, Screens, Health, background functions (React + Firebase sample in `fixtures/`) || `blueprint.test.mjs` | a map planned from a PRD before any code exists: plan.json errors, endpoints and calls, Screens, the design review, refreshing and switching to the real code (sample PRD in `fixtures/`) |diff --git a/skills/floorplan/scripts/lib/health.mjs b/skills/floorplan/scripts/lib/health.mjsindex a5cb39e..c861af9 100644--- a/skills/floorplan/scripts/lib/health.mjs+++ b/skills/floorplan/scripts/lib/health.mjs@@ -345,9 +345,18 @@ function jsRoutes(src, f, out) {out.push(rec);return;}- // the route call's own arguments: router.post('/x', requireAuth, async (req, res) => …)+ // the route call's own arguments before its handler: router.post('/x', requireAuth, async (req, res) => …),+ // or router.post('/x', requireAuth, createOrder) where the last one is the handlerconst head = lines.slice(r.line - 1, r.line + 4).join('\n');- const args = (/\.\w+\(\s*["'`][^"'`]*["'`]\s*,([\s\S]*?)(?:async\s*)?(?:\(\s*req\b|function\b|\breq\s*=>|\(\s*\{|\(\s*c\s*\)|\(\s*ctx\b)/.exec(head)?.[1] || '');+ const call = /\.\w+\(\s*["'`][^"'`]*["'`]\s*,/.exec(head);+ let args = '';+ if (call) {+ let depth = 1, j = call.index + call[0].length;+ for (; j < head.length && depth; j++) { if (head[j] === '(') depth++; else if (head[j] === ')') depth--; }+ const own = head.slice(call.index + call[0].length, depth ? j : j - 1);+ const fn = /(?:async\s*)?(?:\(\s*req\b|function\b|\breq\s*=>|\(\s*\{|\(\s*c\s*\)|\(\s*ctx\b)/.exec(own);+ args = fn ? own.slice(0, fn.index) : own.slice(0, Math.max(0, own.lastIndexOf(',')));+ }const mw = (args.match(/[A-Za-z_$][\w$.]*/g) || []).map((x) => x.split('.').pop()).find(isGuardName);const next = routes[idx + 1]?.line || r.line + 60;const body = lines.slice(r.line - 1, Math.min(next - 1, r.line + 60)).join('\n');diff --git a/tests/fixtures/express-named-handlers/package.json b/tests/fixtures/express-named-handlers/package.jsonnew file mode 100644index 0000000..cb1f8e4--- /dev/null+++ b/tests/fixtures/express-named-handlers/package.json@@ -0,0 +1 @@+{ "name": "express-named-handlers", "private": true, "type": "module", "dependencies": { "express": "^4.19.0" } }diff --git a/tests/fixtures/express-named-handlers/server/auth.js b/tests/fixtures/express-named-handlers/server/auth.jsnew file mode 100644index 0000000..82f8107--- /dev/null+++ b/tests/fixtures/express-named-handlers/server/auth.js@@ -0,0 +1,4 @@+export function requireAuth(req, res, next) {+ if (!req.headers.authorization) return res.status(401).end();+ next();+}diff --git a/tests/fixtures/express-named-handlers/server/controllers.js b/tests/fixtures/express-named-handlers/server/controllers.jsnew file mode 100644index 0000000..01d320b--- /dev/null+++ b/tests/fixtures/express-named-handlers/server/controllers.js@@ -0,0 +1,4 @@+export const listBooks = (req, res) => res.json([]);+export const createBook = (req, res) => res.json({ saved: true });+export const updateUser = (req, res) => res.json({ saved: true });+export const createNote = (req, res) => res.json({ saved: true });diff --git a/tests/fixtures/express-named-handlers/server/index.js b/tests/fixtures/express-named-handlers/server/index.jsnew file mode 100644index 0000000..cfbcbb8--- /dev/null+++ b/tests/fixtures/express-named-handlers/server/index.js@@ -0,0 +1,6 @@+import express from 'express';+import books from './routes/books.js';++const app = express();+app.use('/api', books);+app.listen(3000);diff --git a/tests/fixtures/express-named-handlers/server/routes/books.js b/tests/fixtures/express-named-handlers/server/routes/books.jsnew file mode 100644index 0000000..bfeb376--- /dev/null+++ b/tests/fixtures/express-named-handlers/server/routes/books.js@@ -0,0 +1,16 @@+import express from 'express';+import { requireAuth } from '../auth.js';+import { listBooks, createBook, updateUser, createNote } from '../controllers.js';++const router = express.Router();++// a check before a handler defined elsewhere+router.post('/books', requireAuth, createBook);+// public, with a handler whose name only sounds like a check+router.get('/books', listBooks);+router.put('/users/:id', updateUser);+// open, even though the next route has a check+router.post('/notes', createNote);+router.delete('/notes/:id', requireAuth, async (req, res) => { res.json({ deleted: true }); });++export default router;diff --git a/tests/health.test.mjs b/tests/health.test.mjsindex 83cccb4..f90b1d7 100644--- a/tests/health.test.mjs+++ b/tests/health.test.mjs@@ -54,3 +54,11 @@ test('FastAPI: checks added where a router is included count as sign-in checks',// over several lines; a database session alone (orders) protects nothingassert.deepEqual(openEndpoints(graph), ['POST /orders']);});++test('Express: a check before a named handler counts, and each route is judged on its own arguments', () => {+ const graph = buildFixture('express-named-handlers');+ assert.equal(graph.routes.length, 5, `expected the sample's 5 endpoints, found ${graph.routes.length}`);+ // router.post('/books', requireAuth, createBook) is protected; a handler named like a check+ // (updateUser) isn't a check, and a check on the next route doesn't protect the one before it+ assert.deepEqual(openEndpoints(graph), ['GET /api/books', 'POST /api/notes', 'PUT /api/users/:id']);+});