Commit bb8b895
fix(security): stop the fail-closed check conflating same-named tables across schemas
The previous commit matched a protected table against a query's tables by
adding both the qualified name and its bare part to each side, then
intersecting. That collapsed public.customer_profiles and
marts.customer_profiles to the same key, so protecting one refused queries
against the other -- with a message naming a table the user never referenced.
This product added multi-schema support in #55 and an acme_erp fixture with
crm/sales/finance/hr/inventory in #65, so same-named tables across schemas are
the expected shape here, not a corner case. Over-blocking is the safe
direction, which is exactly why it would have survived review and surfaced
later as unexplained refusals.
Matching is now asymmetric, because the two sides carry different information.
ConnectionChatAccessPolicyService.qualifyTable() drops the schema when it is
"public", so a bare PROTECTED name means public.<table> -- it is not unknown. A
bare REFERENCE in a query is genuinely unknown: it resolves through the session
search_path and could be any schema.
reference unqualified -> match on bare name (ambiguous, so block)
protected public -> a qualified reference must actually say public
both qualified -> exact match
Every bypass stays closed: an unqualified reference to a protected table is
still refused, and hr.salaries still matches a bare "salaries".
Also replaces a characterization test asserting the opposite. It was written
before qualifyTable's public-collapsing was discovered and encoded the wrong
belief that a bare protected name is ambiguous; the case genuinely worth
pinning is a bare reference, which it now covers.
Verified: 17/17 in UserDataAccessPolicyServiceTest. Regression baseline on the
same suite selection unchanged at 8 failures / 16 errors (414 run vs 412
before, the delta being these two tests passing).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 70a1472 commit bb8b895
2 files changed
Lines changed: 80 additions & 16 deletions
File tree
- backend/src
- main/java/com/dbaagent/service
- test/java/com/dbaagent/service
Lines changed: 44 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | | - | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
367 | 369 | | |
368 | 370 | | |
369 | 371 | | |
370 | 372 | | |
371 | 373 | | |
372 | 374 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
| |||
383 | 384 | | |
384 | 385 | | |
385 | 386 | | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
390 | 413 | | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
| 414 | + | |
| 415 | + | |
396 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
397 | 425 | | |
398 | 426 | | |
399 | 427 | | |
400 | 428 | | |
401 | 429 | | |
402 | | - | |
| 430 | + | |
403 | 431 | | |
404 | 432 | | |
405 | 433 | | |
406 | 434 | | |
407 | | - | |
| 435 | + | |
408 | 436 | | |
409 | 437 | | |
410 | 438 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
204 | 240 | | |
205 | 241 | | |
206 | 242 | | |
| |||
0 commit comments