Repository navigation
fix: drop the ?token= credential from proxied app requests - #30592
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The fix strips the credential at the one place the forwarded URL and all three signed targets get their query from, and the in-tree reader that matters is listed. Notes
[DESIGN-REVIEWED] 5ab868a Description read[DESCRIPTION-READ] 3f39e691ff27d64c0688fe68b0c068f69ac7779ce1bb125ed6797c7739dc8f53 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix blocks nothing. One small subtraction is left: the single-entry strip set. Notes
What this change shipsInventory (6 items) — 5 justifiedIntent: an app backend reached through the app proxy never receives the owner's dashboard or app token from
[FIRST-PRINCIPLES-REVIEWED] 5ab868a Description read[DESCRIPTION-READ] 60b98b1e61d2b3ad163980aabf9acd41f3316c4f744300ebf72408128e703b22 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
The app proxy dropped the cookie and authorization headers before forwarding to an app backend, but built the upstream request-target from the raw query string verbatim. token_auth reads the dashboard and app token from the `token` query parameter, so a page calling its own backend with ?token= handed the owner's credential to the backend, which logged it. Former built-ins now run as registry apps, so this reaches every adopted app. _forwarded_query removes every `token` field, matched after the same percent-decoding aiohttp applies, and keeps every other field's exact wire bytes and order. The v1, v2 and principal signatures are computed over the forwarded target, so they still verify. Part of #26967
166ff7d to
5ab868a
Compare
|
Attribution for the two backend reds on 166ff7d (run https://github.com/kirodotdev/KiroCrew/actions/runs/42074238116). Neither test touches the app proxy:
Both classes pass 5/5 locally at that head ( |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved: lanes and checks clean on this head.
The app proxy dropped the cookie and authorization headers before forwarding to an app backend, but built the upstream request-target from the raw query string verbatim. token_auth reads the dashboard and app token from the `token` query parameter, so a page calling its own backend with ?token= handed the owner's credential to the backend, which logged it. Former built-ins now run as registry apps, so this reaches every adopted app. _forwarded_query removes every `token` field, matched after the same percent-decoding aiohttp applies, and keeps every other field's exact wire bytes and order. The v1, v2 and principal signatures are computed over the forwarded target, so they still verify. Part of #26967 (cherry picked from commit c8c5237)
Problem / Motivation
Goal: An app backend reached through the app proxy never receives the owner's dashboard or app token from a
?token=query parameter.The app proxy (
/apps/<name>/api/...) drops theCookieandAuthorizationheaders before it forwards a request, but it copied the query string to the backend unchanged. The gateway accepts the dashboard and app token as?token=, so when an app page called its own backend with that parameter, the backend got the owner's token and logged it. The campaign smoke run found it in file-explorer'sdata/logs/backend.logas"GET /api/resolve?path=/tmp&token=eyJ... ".Why it matters
The former built-ins now install as registry apps (#26967), so this reaches every adopted app and every third-party app. Any app backend that logs its request line, as file-explorer's does, writes a live owner credential into the app's own data directory. That credential opens the whole dashboard, not just the app.
Not a goal
?token=still signs a person in and still mints the session cookie.credential_patterns.What changed (motivation → approach → change)
Symptom: an adopted app's backend log held the owner's token. Root cause:
handle_app_api_proxybuilt the upstream URL and the signed target fromrequest.rel_url.raw_query_stringunchanged, andtoken_authreads its credential from that sametokenparameter.Change: before the target is built,
_forwarded_queryinapps/routes_proxy.pydrops everytokenfield from the query. A field counts astokenafter the same single percent-decoding aiohttp applies, so%74oken=is dropped too, because the gateway reads it astokenas well. Every other field keeps its exact bytes and its order. A query with notokenfield is passed on unchanged. The v1, v2 and principal signatures are computed over the target actually forwarded, so they still verify.apps/routes.pynames the two new symbols in the facade's type-checking group. The owning spec (§24 and the module table) and the App Kit API reference now state the rule. The API reference also tells app authors not to usetokenas one of their own query parameter names.Backwards compatibility
Breaking: an app backend reached through the proxy no longer receives a query field named
token. The diff already removes everytokenfield, not only one whose value is a live credential, because no in-tree or first-party app reads one. Writer sweep on origin/main @ d775742: no in-tree process backend readstokenfrom its query (git grep -nE "parse_qs|query\.get\(" -- src/kiro_crew/apps/builtins). The one hit,aws_control/backend/routes_parts/drive.py:215, is an in-process route and does not go through this proxy. None of the 14 app repositories under KiroCrewCaptain (kirocrew-app-*, each at itsorigin/main) reads atokenquery parameter in a backend or UI fetch. Their only?token=uses are gateway sign-in URLs in capture and e2e scripts, plus one test fixture. A third-party app that usedtokenfor its own data was already fragile: the gateway reads that name as a credential on every request, so with no session cookie such a request is refused.Reader: src/kiro_crew/apps/routes_proxy.py:_proxy_principal -- app -- reads the
auth_from_query_tokenmark, never the query, so the principal kind is unchanged (test_real_middleware_owner_query_link_receives_none)Reader: src/kiro_crew/apps/builtins/aws_control/backend/routes_parts/drive.py:_handle_drive_list -- app -- in-process route, not proxied, so it still gets its pagination
tokenReader: src/kiro_crew/apps/proxy_auth.py:verify_proxy_request -- app -- verifies over the target the backend received, which is the target signed (
test_the_backend_receives_no_token_and_the_signatures_verify)Tests
test/test_app_proxy_query_credential.py(new). It runs_forwarded_queryagainst a table:token, repeated, bare, empty and percent-encoded names are dropped, and look-alike names, values, empty fields and trailing separators are kept byte for byte. It also does a real proxy hop to a loopback backend. The backend's request-target carries notoken, and the shipped v1 and v2 verifiers accept the signatures over that target.test/test_gateway_appkit_endpoints_signed_proxy.py: the three?token=link tests go through the realtoken_auth_middleware. They now check that the backend's target is/api/claim-test, with the token removed, and verify the principal claim over that target. Before this change they pinned the leak.Proof: PROVEN test/test_app_proxy_query_credential.py::test_the_backend_receives_no_token_and_the_signatures_verify[path=%2Ftmp&token=owner-credential&q=a+b%20c-/api/resolve?path=%2Ftmp&q=a+b%20c], test/test_app_proxy_query_credential.py::test_the_backend_receives_no_token_and_the_signatures_verify[token=owner-credential-/api/resolve], test/test_app_proxy_query_credential.py::test_the_backend_receives_no_token_and_the_signatures_verify[%74oken=owner-credential&path=/tmp-/api/resolve?path=/tmp], test/test_gateway_appkit_endpoints_signed_proxy.py::TestSignedPrincipalProxy::test_real_middleware_owner_query_link_receives_none, test/test_gateway_appkit_endpoints_signed_proxy.py::TestSignedPrincipalProxy::test_real_middleware_owner_query_link_on_mixed_internal_path_receives_none (head 5ab868a)
Local gates: black/isort/flake8 on changed files,
mypy src/kiro_crew(4191 files, clean), comment-history, brand, subprocess-encoding, file-line-cap, docs-lint and the flake-pattern ratchet all pass. The related backend set fromrun_scoped_tests.py(1104 files, 50,578 tests) is green.Manual verification
The original repro, run against an isolated gateway built from this worktree: temporary
KIROCREW_HOMEand XDG directories, loopback only (127.0.0.1and::1), stub ACP backend.POST /api/apps/registry/install {"name":"file-explorer"}→adoption_pending. After a restart,GET /api/appsshowsfile-explorerwithorigin: registry. ThenPOST /api/apps/file-explorer/enable.GET /apps/file-explorer/api/resolve?path=/tmp&token=<owner token>→ 200{"name": "tmp", "path": "/tmp", "type": "dir", ...}."GET /api/resolve?path=/tmp HTTP/1.1" 200.%74oken=<tok>&path=%2Ftmp%2Fa%20bis logged as"GET /api/resolve?path=%2Ftmp%2Fa%20b HTTP/1.1" 200. The log has 0 occurrences oftoken=."GET /api/resolve?path=/tmp&token=<REDACTED> HTTP/1.1" 200(redacted here). That is the leak.The backend answering 200 shows it accepted the gateway's signature over the reduced target.
Related Issues
Part of #26967
Sibling sweep
Swept: git grep -nE "raw_query_string|query_string|raw_path_qs" -- src/kiro_crew
Swept: git grep -nE "ws_connect|ClientSession()|session.request(" -- src/kiro_crew/apps
Sibling: src/kiro_crew/apps/routes_proxy.py -- changed here
Sibling: src/kiro_crew/dashboard/handlers_instances.py -- not affected -- it forwards to the owner's own peer gateways, which authenticate with their own credential, not to an app backend
The forwarded URL, the v1/v2 HMAC target and the principal claim target in
routes_proxy.pyall derive from the oneraw_qsthis PR filters.Pattern harvest
Rule candidate: review-prompt
Pattern: "a forwarding proxy strips credential headers but passes the request's query string through unchanged, although the gateway also accepts a credential as a query parameter"
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)