Commit 323da34
Fix/brain endpoint authz (#72)
## Problem
93 of 116 `BrainController` endpoints performed **no authorization** —
only
authentication. `SecurityConfig` asserts `.anyRequest().authenticated()`
and
`JwtAuthenticationFilter` only resolves a principal; neither inspects a
`connectionId`, and no filter/interceptor/aspect fills the gap.
Connections are
private per user (`ConnectionAccessService.resolveAccess` keys on
`ownerUsername`
+ an explicit grant table), so any authenticated user with someone
else's
connection id could read their database intelligence.
**Verified live against the pre-fix binary (v1.2.0):** a CHAT_EDITOR
user pulled
**91 KB of health-score data**, **71 KB of cost-attribution data**, and
**131 table names** from a connection they were never granted — all HTTP
200.
Same calls are 403 after this change.
## Fix
- All 116 endpoints now authorize: `assertCanReadConnectionContent`
(GET),
`assertCanManageConnectionContent` (writes).
- Indirect-ID endpoints (`simulationId`/`experimentId`/`patternId`)
resolve the
owning connection first via three new `getConnectionId` lookups.
- 2 endpoints have no connection scope →
`@PreAuthorize("hasRole('ADMIN')")`.
- `BrainControllerAuthorizationSafetyTest` fails the build if a new
endpoint
ships unguarded.
## Found during hands-on QA (2nd commit)
- `DELETE /brain/calibration/{id}` used a **fully-qualified**
`@DeleteMapping`,
so the first sweep's regex skipped it — a *destructive* endpoint left
open.
The safety test shared the same blind spot and reported "0 unguarded"
while it
was live. Regex hardened; differential-checked (old pattern: 116/0 →
misses;
new: 117/1 → catches).
- Bogus indirect ids returned 500 instead of 404 (access was still
denied).
## Verification
API (curl), real browser session (Chrome DevTools MCP), and DB read-back
all
agree: granted → 200 with real data, ungranted → 403; owner writes still
200
with rows confirmed in Postgres. Adjacent features unaffected.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 088ac35 commit 323da34
6 files changed
Lines changed: 293 additions & 1 deletion
File tree
- backend/src
- main/java/com/dbaagent
- controller
- service/brain
- analysis
- config
- query
- test/java/com/dbaagent/controller
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
352 | 388 | | |
353 | 389 | | |
354 | 390 | | |
| |||
0 commit comments