Skip to content

DevTime v0.8.0 - routes as your app serves them

Latest

Choose a tag to compare

@Shakargy Shakargy released this 30 Nov 21:58
667b869

DevTime v0.8.0 - routes as your app serves them

Most real applications do not declare a route with its full URL and its guard
on one line. They mount routers under prefixes and guard them at the mount:

app.use(requireAuth);
app.use("/admin", requireAdmin, adminRouter);   // routes/admin.ts: router.get("/users", ...)
admin_router = APIRouter(prefix="/admin")

@admin_router.get("/users", dependencies=[Depends(get_current_active_superuser)])

DevTime v0.7.0 looked at each file on its own. For both apps above it reported
admin-authorization as NOT_APPLICABLE: the /admin prefix lived on the mount
and the APIRouter, and a route on a variable named admin_router was not
recognized at all. So a new unguarded route added to that router was invisible
to dtc review too.

v0.8.0 resolves every route along the chain that serves it:

Admin Authorization
Status: SUPPORTED
  - 2 of 2 administrative route(s) have an authorization guard on the route, its
    router, or the mount that serves it.
  - GET /admin/users is guarded by requireAdmin (where its router is mounted,
    src/server.ts:14).

No cloud, no telemetry, no AI, no code execution - unchanged.

What is resolved

For each route, DevTime composes the served path (mount prefixes + router
prefix + declared path), every guard that runs first, and the files the
answer depends on
.

Express:

  • app.use("/prefix", ...guards, router) followed through relative ESM and
    CommonJS imports, default and named exports, and nested routers.
  • Order matters, as in Express: app.use(requireAuth) guards routers mounted
    after it, and router.use(guard) guards routes declared after it.
  • Chained routers (const api = Router().use(a).use(b),
    export default Router().use("/api", api)), router.route(path).post(...)
    chains, and mounts registered in a forEach over an array of
    { path, route } literals.

FastAPI:

  • Routes on any router variable, not only app and router.
  • APIRouter(prefix=..., dependencies=[...]),
    include_router(..., prefix=..., dependencies=[...]), and
    FastAPI(dependencies=[...]), followed through absolute and relative imports.
  • Depends and Security on the route decorator and in the handler's
    parameters, including Annotated aliases such as CurrentUser defined in
    another module.
  • A prefix computed at runtime (settings.API_V1_STR) is kept as
    {settings.API_V1_STR}, never guessed.

Editing only the file that mounts a router now makes a result about its routes
STALE, and dtc review attributes a guard removed from a mount to that file.

A new claim: write route authentication

mutating-routes-authenticated: "Routes that change state (POST, PUT, PATCH,
DELETE) require authentication." Almost every web application has write
routes, so this claim applies nearly everywhere, and inside dtc review it
catches the most common thing a reviewer misses: a new write endpoint with no
auth.

Write Route Authentication
Status: WEAK
  - 3 of 4 write route(s) require authentication on the route, its router, or the
    mount that serves it.
  - 3 route(s) are public by design (...) and are not counted: POST /auth/login,
    POST /auth/signup, POST /webhooks/stripe.
Missing evidence:
  - Authentication evidence for: POST /exports (src/server.ts)

Sign-in, sign-up, token and password-reset endpoints, OAuth callbacks, webhooks,
and health checks are excluded only when no guard was found on them, and are
always listed by name. A missing guard is WEAK, never CONTRADICTED.

Route test association

  • Tests are matched against the served path: a supertest request to
    /admin/reports now associates with router.get("/reports") mounted at
    /admin.
  • A path parameter matches any value (/users/42 matches /users/:id); a
    request that matches one route exactly is not also credited to a
    parameterized one.
  • Requests built from f-strings and template literals keep their placeholders:
    client.get(f"{settings.API_V1_STR}/items/") matches a route served under
    that prefix.

Measured on real repositories

Every repository below was scanned with both the published 0.7.0 and this
release. Billing and JWT claim statuses and concept detection did not change
on any of them, except where noted.

Repository What 0.8.0 resolves
full-stack-fastapi-template 23 of 23 routes mounted through include_router under {settings.API_V1_STR}. Route test association 20 of 23 (0.7.0 matched none, because its tests request f-string URLs). Write routes: 12 of 13 authenticated; the one without a guard is POST /private/users, which the template mounts only when ENVIRONMENT == "local".
Netflix Dispatch 286 of 290 routes mounted, with guards from include_router(..., dependencies=[...]) and PermissionsDependency role checks. Write routes: 168 of 172 authenticated; the other 4 are Slack endpoints on a router DevTime did not find mounted, and the report says so.
node-express-realworld-example-app 19 of 20 routes mounted through Router().use(...) chains and an anonymous default export, served under /api.
node-express-boilerplate Mounts registered in a forEach loop resolved; routes served under /v1/auth and /v1/users. Route test association went from WEAK to SUPPORTED (14 of 14), because its supertest requests use the full URLs.
proshop-v2 router.route(...).post(protect, admin, ...) chains extracted. Flags POST /api/upload with no authentication guard. It also lists the register and login endpoints (POST /api/users, POST /api/users/auth), because nothing in those names marks them as public; the report calls this missing evidence, not proof. Concept detection gains Admin Permissions here, from the newly extracted admin-guarded routes.
Cal.com Admin authorization moves from WEAK to UNKNOWN: its one admin route is a Next.js route handler whose guards DevTime cannot read yet, which is what UNKNOWN means.

Scan time is unchanged (Cal.com, 5,750 files: about 19 to 20 seconds with
either version on a warm cache).

Found while building it

Running the new resolver on real repositories surfaced two ways it could have
reported SUPPORTED without real evidence. Both were fixed before release and
both are regression tests:

  • Middleware that attaches an identity was counted as authentication. On
    hackathon-starter, app.use(passport.session()) made every route look
    authenticated. passport.initialize(), passport.session(),
    clerkMiddleware(), auth.optional, express-jwt with
    credentialsRequired: false, and an Express currentUser middleware now
    never count: they load a user but reject no one.
  • A middleware's arguments were read as its identity. On
    node-express-boilerplate, validate(authValidation.register) counted as
    authentication because its argument mentions auth. A guard is now
    recognized by the function it calls, never by what it passes.

Two smaller ones: a route handler's name (listSuperusers) is no longer read
as a guard; only middleware before it is, plus an explicit check written inline
in the handler. And a decorator stacked above a Python route decorator does not
protect the route (it wraps what was already registered), so it is not counted.

Compatibility

  • New claim mutating-routes-authenticated. No claim id, command, or MCP tool
    was renamed or removed. JSON stays at schema_version 2.
  • admin-authorization now reports UNKNOWN rather than WEAK when the only
    admin routes without a guard are ones whose guards DevTime cannot resolve.
  • Route labels now show the served path (GET /admin/users) instead of the
    declared one (GET /users). The first dtc verify --list after upgrading can
    therefore show route claims as STALE; run dtc scan and dtc verify.
  • Scans recorded by an earlier version still verify, with v0.7.0 behavior for
    their routes. Run dtc scan to get route resolution.
  • New scan signal kinds (router_def, route_use, dependency_alias) appear
    in dtc verify's evidence summary. Concept detection ignores them.

Limits

Path aliases (@/routes), re-exports through index files, routers built by a
function call, Next.js route handlers, NestJS guards, Flask blueprints, and
Django views are not resolved yet. Guards are recognized by name, so a custom
guard with an unusual name is not recognized. Everything DevTime cannot resolve
is reported as unresolved or unmounted, never as protected. See LIMITATIONS.md
section 6c.

Notes

  • 274 passing tests (59 new): every Express and FastAPI resolution shape above,
    mount order, prefixed guards, mounts inside tests being ignored, unresolvable
    imports, legacy scan rows, the guard classifier including both false positives
    found on real repositories, served-path matching, freshness through a mount
    file, and review attribution.

Names

  • PyPI distribution: devtime-ei. Python import: devtime. CLI: dtc.