Commit 43a217b
committed
fix(auth): enforce is_active check + extend DB-backed proxy auth to primary MCP path
Second follow-up addressing findings from a deeper security + design review:
SECURITY FIX (critical):
- _authenticate_proxy_user() now enforces user_info.is_active, matching the
JWT path's check in _enforce_revocation_and_active_user (:398-399).
Without this, a disabled user - including a disabled admin - could still
authenticate via trusted-proxy mode and keep their pre-disable
authorizations. Raises 401 'Account disabled' for inactive users.
PRIMARY MCP TRANSPORT GAP (critical):
- streamablehttp_transport._set_proxy_user_context() previously hardcoded
teams=[] and is_admin=False, so on the primary MCP entry point
(_StreamableHttpAuthHandler.authenticate) proxy-authenticated users
still received public-only access. Only the stateful-session fallback
path at :1953 went through the enriched helper.
- Rewritten as an async function that performs the same DB lookup,
team/admin resolution, is_active enforcement, and platform-admin
bootstrap as the REST helper. Returns None on success or
{detail, headers} on failure so the caller can send a 401 via
self._send_error().
- Call site at _StreamableHttpAuthHandler.authenticate awaits the helper
and sends 401 on rejection.
DISPATCH-KEY FIX (S1/S2):
- Proxy payload now includes token_use='session' so downstream dispatchers
(main.py:2870, streamablehttp_transport.py:1998) route through
resolve_session_teams() - the canonical 'single policy point' per
AGENTS.md - rather than treating the proxy payload as an API-token
payload with embedded teams.
DOCS + TEST HYGIENE (S3/S4a):
- require_auth docstring updated to describe the DB-enriched proxy path,
bootstrap flow, and request.state caching.
- Misleading test test_jwt_auth_with_proxy_enabled renamed to
test_mcp_client_auth_mode_skips_proxy_path with accurate docstring
and comment explaining why 'anonymous' is the expected outcome.
- Stale comment 'Proxy auth path - identical to require_auth' updated
to accurately describe the shared-helper relationship.
DENY-PATH REGRESSION TESTS (AGENTS.md security invariant):
- test_proxy_auth_disabled_user_raises_401: non-admin disabled user -> 401
- test_proxy_auth_disabled_admin_raises_401: disabled admin -> 401 (no
elevation via is_admin=True on a deactivated record)
- test_proxy_auth_payload_has_token_use_session: dispatch-key contract
- 4 pre-existing tests updated to supply DB mocks instead of relying on
the old unvalidated proxy shape.
Signed-off-by: Jonathan Springer <jps@s390x.com>1 parent 9ab37cc commit 43a217b
4 files changed
Lines changed: 262 additions & 35 deletions
File tree
- mcpgateway
- transports
- utils
- tests/unit/mcpgateway
- transports
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4527 | 4527 | | |
4528 | 4528 | | |
4529 | 4529 | | |
4530 | | - | |
4531 | | - | |
| 4530 | + | |
| 4531 | + | |
| 4532 | + | |
| 4533 | + | |
| 4534 | + | |
| 4535 | + | |
| 4536 | + | |
| 4537 | + | |
| 4538 | + | |
| 4539 | + | |
| 4540 | + | |
4532 | 4541 | | |
4533 | 4542 | | |
4534 | | - | |
| 4543 | + | |
| 4544 | + | |
| 4545 | + | |
| 4546 | + | |
| 4547 | + | |
| 4548 | + | |
| 4549 | + | |
4535 | 4550 | | |
4536 | | - | |
4537 | | - | |
4538 | | - | |
4539 | | - | |
4540 | | - | |
4541 | | - | |
4542 | | - | |
4543 | | - | |
4544 | | - | |
4545 | | - | |
4546 | | - | |
| 4551 | + | |
| 4552 | + | |
| 4553 | + | |
| 4554 | + | |
| 4555 | + | |
| 4556 | + | |
| 4557 | + | |
| 4558 | + | |
| 4559 | + | |
| 4560 | + | |
| 4561 | + | |
| 4562 | + | |
| 4563 | + | |
| 4564 | + | |
| 4565 | + | |
| 4566 | + | |
| 4567 | + | |
| 4568 | + | |
| 4569 | + | |
| 4570 | + | |
| 4571 | + | |
| 4572 | + | |
| 4573 | + | |
| 4574 | + | |
| 4575 | + | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
| 4581 | + | |
| 4582 | + | |
| 4583 | + | |
| 4584 | + | |
| 4585 | + | |
| 4586 | + | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + | |
| 4590 | + | |
| 4591 | + | |
| 4592 | + | |
| 4593 | + | |
| 4594 | + | |
4547 | 4595 | | |
4548 | 4596 | | |
4549 | 4597 | | |
| |||
4673 | 4721 | | |
4674 | 4722 | | |
4675 | 4723 | | |
4676 | | - | |
4677 | | - | |
| 4724 | + | |
| 4725 | + | |
| 4726 | + | |
| 4727 | + | |
| 4728 | + | |
| 4729 | + | |
4678 | 4730 | | |
4679 | 4731 | | |
4680 | 4732 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
442 | 442 | | |
443 | 443 | | |
444 | 444 | | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
445 | 455 | | |
446 | 456 | | |
447 | 457 | | |
| |||
451 | 461 | | |
452 | 462 | | |
453 | 463 | | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
454 | 468 | | |
455 | 469 | | |
456 | 470 | | |
| |||
464 | 478 | | |
465 | 479 | | |
466 | 480 | | |
| 481 | + | |
467 | 482 | | |
468 | 483 | | |
469 | 484 | | |
| |||
483 | 498 | | |
484 | 499 | | |
485 | 500 | | |
486 | | - | |
| 501 | + | |
487 | 502 | | |
488 | 503 | | |
489 | 504 | | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
490 | 517 | | |
491 | 518 | | |
492 | 519 | | |
| |||
496 | 523 | | |
497 | 524 | | |
498 | 525 | | |
499 | | - | |
| 526 | + | |
| 527 | + | |
500 | 528 | | |
501 | 529 | | |
502 | 530 | | |
503 | | - | |
| 531 | + | |
| 532 | + | |
504 | 533 | | |
505 | 534 | | |
506 | 535 | | |
| |||
Lines changed: 50 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
4871 | 4871 | | |
4872 | 4872 | | |
4873 | 4873 | | |
4874 | | - | |
| 4874 | + | |
4875 | 4875 | | |
4876 | 4876 | | |
4877 | 4877 | | |
| |||
4888 | 4888 | | |
4889 | 4889 | | |
4890 | 4890 | | |
4891 | | - | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
4892 | 4907 | | |
4893 | 4908 | | |
4894 | 4909 | | |
| |||
4924 | 4939 | | |
4925 | 4940 | | |
4926 | 4941 | | |
4927 | | - | |
| 4942 | + | |
| 4943 | + | |
| 4944 | + | |
| 4945 | + | |
| 4946 | + | |
| 4947 | + | |
| 4948 | + | |
| 4949 | + | |
| 4950 | + | |
| 4951 | + | |
| 4952 | + | |
| 4953 | + | |
| 4954 | + | |
| 4955 | + | |
| 4956 | + | |
| 4957 | + | |
4928 | 4958 | | |
4929 | 4959 | | |
4930 | 4960 | | |
| |||
4960 | 4990 | | |
4961 | 4991 | | |
4962 | 4992 | | |
4963 | | - | |
| 4993 | + | |
| 4994 | + | |
| 4995 | + | |
| 4996 | + | |
| 4997 | + | |
| 4998 | + | |
| 4999 | + | |
| 5000 | + | |
| 5001 | + | |
| 5002 | + | |
| 5003 | + | |
| 5004 | + | |
| 5005 | + | |
| 5006 | + | |
| 5007 | + | |
| 5008 | + | |
4964 | 5009 | | |
4965 | 5010 | | |
4966 | 5011 | | |
| |||
0 commit comments