Repository navigation
fix(security): add JWT auth to fleet endpoint [REN-67] - #98
Conversation
OWASP A01 fix: fleet endpoint now requires JWT Bearer token. Migrated from legacy `from db import` to core.database patterns. Added audit logging via structlog. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Scott Graham (cheddarfox)
left a comment
There was a problem hiding this comment.
Security Review — REN-67
Reviewer: SecEng (Security Engineer)
Scope: OWASP A01 (Broken Access Control) fix for GET /fleet
Verdict: APPROVE (posted as comment due to GitHub self-review restriction)
OWASP A01 Fix Validation
| Check | Result |
|---|---|
| Auth enforcement | PASS — Depends(get_current_user) on endpoint signature; FastAPI will reject requests without valid Bearer token before the handler body executes |
| Legacy import removal | PASS — from db import async_session completely removed; replaced with core.database.get_db_session |
| Audit logging | PASS — structlog logger emits fleet_overview_requested event with user_id on every successful access |
Authentication Chain Verification
Traced the full auth chain:
get_current_user(incore/auth/jwt.py) depends onHTTPBearer(), which extracts theAuthorization: Bearer <token>header. Missing header returns 401 automatically via FastAPI.verify_token()decodes the JWT, validates signature, expiry, and presence ofsubclaim. Invalid/expired tokens return 401.- Refresh tokens are explicitly rejected (token_type must be
ACCESS) — good defense against token confusion attacks. - User is loaded from DB and checked for existence and
is_activestatus. Deleted or deactivated users get 401.
No bypass path exists. The Depends() mechanism is enforced at the framework level before handler execution.
SQL Injection Analysis
- The query
text("SELECT * FROM fleet_overview")is a static string with no user-supplied parameters. No injection vector. fleet_overviewis a PostgreSQL view (confirmed incore/gateway/web/ui/migrations/20240503_fleet_view.sql). The view definition itself uses no dynamic input.- Low-severity note: The endpoint returns all rows from
fleet_overviewwith no filtering by user/tenant. This is appropriate if all authenticated users should see the full fleet, but worth confirming this matches the authorization model. If fleet visibility should be scoped per-user or per-organization, a follow-up story should add row-level filtering.
Code Quality — Ruff
Ruff reports 3 findings on the PR branch version:
- I001 (import sorting) — Auto-fixable with
ruff check --fix. Minor style issue. - B008 x2 (
Depends()in function defaults) — This is a false positive for FastAPI.Depends()in parameter defaults is the canonical FastAPI dependency injection pattern used throughout the codebase (e.g.,core/database.pyline 60 uses the same pattern). The project'spyproject.tomldoes not suppress B008 globally, so this will fire in CI. Recommendation: Add"B008"to theignorelist inpyproject.toml, or add aper-file-ignoresentry for route files. This is not a security issue but will block CI.
Additional Observations
-
Frontend integration note:
core/gateway/web/ui/components/FleetTable.tsxcallsuseSWR('/api/fleet')with the default fetcher, which does not attach anAuthorizationheader. After this PR merges, the fleet table will receive 401 responses unless the SWR global fetcher is configured to include JWT tokens. This is not a security concern (the backend is correctly protected), but a separate frontend story should ensure the fetcher sends credentials. -
Apache 2.0 header: Present and correct for the
core/directory licensing model. -
Session management: Uses
Depends(get_db_session)which provides proper async session lifecycle (created per-request, closed after). No session leaks. -
Result handling:
result.mappings().all()is the correct SQLAlchemy 2.x pattern, replacing the legacydict(row)approach that could fail with newer SA versions.
Security Concerns
- None blocking. The auth implementation is solid and follows the established project patterns.
Verdict: APPROVE
The OWASP A01 vulnerability is properly remediated. The auth chain is complete, non-bypassable, and includes audit logging. The two non-blocking items (ruff B008 suppression and frontend fetcher update) should be tracked as follow-up work.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
from db import async_sessiontocore.database.get_db_sessionDepends(get_current_user)for mandatory JWT verificationresult.mappings().all()patternChanges
core/gateway/web/ui/routes/fleet.py— full rewrite with auth + proper importsLinear
Closes REN-67
Test plan
GET /fleetwithout auth → 401GET /fleetwith valid JWT → 200 + fleet dataGET /fleetwith expired JWT → 401🤖 Generated with Claude Code