fix(auth): default-deny API-token route capabilities - #5809
Open
RaresKeY wants to merge 5 commits into
Open
Conversation
RaresKeY
marked this pull request as ready for review
July 28, 2026 16:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This replaces #5680, which GitHub closed during the repository transfer and fork-network separation. The branch has been rebuilt on the current dev history; the implementation scope is unchanged.
Refresh #3150 onto current
devand make bearer-token access default-deny at the middleware boundary. Validody_credentials may reach only explicitly registered method/path capabilities with matching scopes; browser/admin, token-management, session, upload, shell, workspace, Cookbook administration, and other unregistered routes remain unavailable. Supported generic chat/model and unrelated Codex/Claude APIs keep their documented behavior. Only the three temporary companion discovery/model reads remain during this slice. Existing bearer access to generic session, history, upload, and stream routes is intentionally not carried into the explicit capability manifest; the final companion-removal draft then deletes the remaining/api/companion/*bridge.This branch preserves Musaab Hasan's original authored capability commit from #3150, then reconciles the route inventory, owner-scoped model behavior, ASGI path normalization, production-middleware coverage, retired Cookbook scopes, and current tests. Existing tokens may retain legacy Cookbook strings, but those strings are inert and new tokens cannot mint them.
This draft follows #5678 and PR #5679, the focused implementation for #5676, and must merge before the companion-removal draft. After those prerequisites merge, this branch should be rebased and its temporary path/Cookbook overlap deduplicated before review for merge. It must not merge directly on current
dev: until #5676 lands, the old token forms still submit the Cookbook scopes retired here.Target branch
dev, notmain.Linked Issue
Fixes #3149
Part of #5674
Type of Change
Checklist
dev.How to Test
python -m pytest -q tests/test_api_token_capabilities.py tests/test_api_token_middleware_integration.py tests/test_api_token_routes.py tests/test_api_token_user_route_gate.py tests/test_auth_policy.py tests/test_auth_regressions.py tests/test_session_owner_attribution.py. The isolated focused run passes all 126 tests.POST /api/v1/chatandGET /api/models, while the same valid token receives non-enumerating403responses on unregistered or wrong-scope routes.LOCALHOST_BYPASS, model inventory stays scoped to the token owner, and bearer requests cannot trigger endpoint refreshes.403; this intentional compatibility break is why the companion-removal follow-up is part of the ordered stack./api/codex/cookbook/*request receives the generic403before its handler even when the stored token carries legacy Cookbook scopes, and verify new token creation rejects those retired scopes.python -m pytest -q. The isolated full suite completes with 4,740 passing and 5 skipped tests. Its 12 failures exactly match the clean current-devrunner baseline: the omitted.env.example, one offline URL-join check, two backup-recovery checks, and eight offline web-fetch checks.Visual / UI changes — REQUIRED if you touched anything that renders
Not applicable. No UI or rendering files are changed.