Skip to content

fix: drop the ?token= credential from proxied app requests - #30592

Merged
bolichen97 merged 1 commit into
mainfrom
fix/adoption-proxy-forwards-query-token
Nov 5, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/adoption-proxy-forwards-query-token

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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 the Cookie and Authorization headers 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's data/logs/backend.log as "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

  • No change to how the gateway authenticates a request. ?token= still signs a person in and still mints the session cookie.
  • No change to the headers the proxy strips, or to the v1, v2 or principal signature formats.
  • No redaction of the gateway's own access log. That is a separate path and is already handled by credential_patterns.
  • No change to any app repository.

What changed (motivation → approach → change)

Symptom: an adopted app's backend log held the owner's token. Root cause: handle_app_api_proxy built the upstream URL and the signed target from request.rel_url.raw_query_string unchanged, and token_auth reads its credential from that same token parameter.

Change: before the target is built, _forwarded_query in apps/routes_proxy.py drops every token field from the query. A field counts as token after the same single percent-decoding aiohttp applies, so %74oken= is dropped too, because the gateway reads it as token as well. Every other field keeps its exact bytes and its order. A query with no token field is passed on unchanged. The v1, v2 and principal signatures are computed over the target actually forwarded, so they still verify. apps/routes.py names 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 use token as 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 every token field, 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 reads token from 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 its origin/main) reads a token query 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 used token for 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_token mark, 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 token
Reader: 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_query against 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 no token, 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 real token_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.
  • Determinism: both files, 48 tests, 20 serial runs, each in a different shuffled node order (seeds 1-20): 20/20 green. The proxy hop binds port 0 and waits only on the request.

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 from run_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_HOME and XDG directories, loopback only (127.0.0.1 and ::1), stub ACP backend.

  1. POST /api/apps/registry/install {"name":"file-explorer"} → adoption_pending. After a restart, GET /api/apps shows file-explorer with origin: registry. Then POST /api/apps/file-explorer/enable.
  2. GET /apps/file-explorer/api/resolve?path=/tmp&token=<owner token> → 200 {"name": "tmp", "path": "/tmp", "type": "dir", ...}.
  3. Backend log with the fix: "GET /api/resolve?path=/tmp HTTP/1.1" 200. %74oken=<tok>&path=%2Ftmp%2Fa%20b is logged as "GET /api/resolve?path=%2Ftmp%2Fa%20b HTTP/1.1" 200. The log has 0 occurrences of token=.
  4. The same gateway with only the call site reverted logs "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.py all derive from the one raw_qs this 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 5, 2026 17:23
@bolichen97
bolichen97 requested a review from buluoray November 5, 2026 17:23
@bolichen97
bolichen97 enabled auto-merge (squash) November 5, 2026 17:24
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 5ab868a5d0fd7a2b7e567b1faf0887394f1d5fb8 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 5ab868a5d0fd7a2b7e567b1faf0887394f1d5fb8 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • The proxy drops every token field, not only one holding a live credential. That is a reversible contract change for third-party apps. The API-reference warning is the only way an app author learns of it, so name it in the release notes when this ships.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 5ab868a5d0fd7a2b7e567b1faf0887394f1d5fb8 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The fix blocks nothing. One small subtraction is left: the single-entry strip set.

Notes

  • Item 1 — one consumer, generalized: _PROXY_STRIP_QUERY_PARAMS = frozenset({"token"}) is a set of names that only ever holds token, and its only consumer is the in test inside _forwarded_query (grepped _PROXY_STRIP_QUERY_PARAMS: 1 consumer, plus the facade's type-checking import and the spec). Subtraction: replace the frozenset with a plain == "token" comparison inside _forwarded_query, and drop the symbol from the routes.py type-checking group and the spec text.

What this change ships

Inventory (6 items) — 5 justified

Intent: an app backend reached through the app proxy never receives the owner's dashboard or app token from ?token=. This is a FIX.

  1. The proxy drops every token query field, including percent-encoded spellings like %74oken, before forwarding to an app backend — one consumer, generalized: single-name strip set
  2. The v1, v2 and principal signatures cover the reduced target the backend actually receives — justified
  3. A query with no token field reaches the backend byte-for-byte unchanged — justified
  4. The App Kit API reference tells app authors not to name a query parameter token — justified
  5. The owning spec §24 and its module table state the rule — justified
  6. Three signed-proxy tests that pinned the leaked target now pin the stripped one (declared in the description) — justified

[FIRST-PRINCIPLES-REVIEWED] 5ab868a

Description read

[DESCRIPTION-READ] 60b98b1e61d2b3ad163980aabf9acd41f3316c4f744300ebf72408128e703b22

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 5ab868a5d0fd7a2b7e567b1faf0887394f1d5fb8 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 5ab868a

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 5ab868a5d0fd7a2b7e567b1faf0887394f1d5fb8 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 5ab868a5d0fd7a2b7e567b1faf0887394f1d5fb8 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 5ab868a

Verdict parsed from the review's SHA-scoped output markers for commit 5ab868a5d0fd7a2b7e567b1faf0887394f1d5fb8.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 5ab868a5d0fd7a2b7e567b1faf0887394f1d5fb8 false-positive: <reason, 20 to 500 characters>

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
@bolichen97
bolichen97 force-pushed the fix/adoption-proxy-forwards-query-token branch from 166ff7d to 5ab868a Compare November 5, 2026 19:31
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/app-kit/api-reference.md, docs/system-specs/modules/app-kit-platform.md, src/kiro_crew/apps/routes.py since this head went green (3adab5e -> 7e168da); CI re-running.

@bolichen97

Copy link
Copy Markdown
Contributor Author

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 (-n0). Coverage Gate was red only because it fails closed on backend-test=failure. Main had moved in this PR's own files (green_age exit 30), so the rebase onto 7e168da re-runs both shards. On 5ab868a the related backend set (1104 files, 50,578 tests) and the routes facade and proxy set (74 files, 2,932 tests) are green locally. prove.py reports PROVEN.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 5, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: lanes and checks clean on this head.

@bolichen97
bolichen97 merged commit c8c5237 into main Nov 5, 2026
98 checks passed
@bolichen97
bolichen97 deleted the fix/adoption-proxy-forwards-query-token branch November 5, 2026 21:42
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 5, 2026
buluoray pushed a commit that referenced this pull request Nov 6, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants