Skip to content

refactor(apps): share the proxy's hop-by-hop list with app web origins - #38846

Open
LachlanLindsay wants to merge 1 commit into
kirodotdev:mainfrom
LachlanLindsay:refactor/app-web-origin-followup
Open

LachlanLindsay wants to merge 1 commit into
kirodotdev:mainfrom
LachlanLindsay:refactor/app-web-origin-followup

Conversation

@LachlanLindsay

@LachlanLindsay LachlanLindsay commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: App authors learn from the docs that another app's pages can set and clear their app's cookies, and an app web origin drops every hop-by-hop response header the API proxy drops.

#36967 merged with three points left for a follow-up: the Design Review's doc notes, the cookie wording in the app web origin spec, and the response-header list. #37670 covered the doc notes ("own origin", the no-cors probe, CSRF and Authorization). Two points remain:

  • Spec §18k says a host-only cookie keeps "one app's cookie" from reaching another app's name. That holds for a cookie a backend's response sets. A script on one app's pages can still set a cookie for apps.localhost, which the browser sends to every app origin and the gateway forwards. A Clear-Site-Data: "cookies" from one app origin clears every app's cookies.
  • _DROP_RESPONSE_HEADERS in apps/app_web_origin.py restates the API proxy's hop-by-hop list instead of reading it. The copy has already drifted: it misses Proxy-Authorization.

Why it matters

The docs are what an app author builds against. An app that trusts a session cookie by its name can be handed one by another app's page, and the spec's wording invites exactly that. The second copy of the hop-by-hop list is the shape the First Principles review blocked on the request side of #36967: a name the proxy learns to drop is still relayed here.

Not a goal

  • Keeping one app's cookies from another. Every app origin may count as the one site apps.localhost, and no response header changes what a page's own script can set.
  • Any change to who is served, what is audited, the request strip list, cookie forwarding or the dashboard CSP.
  • Shipping the reachability probe in the App SDK (the Design Review's second note). The API reference documents the probe for apps to run.

What changed (motivation → approach → change)

App authors learn that another app's pages can set and clear their app's cookies, so their app trusts a cookie by a value it issued, never by its name. In code, the app origin reads the API proxy's hop-by-hop list instead of keeping its own copy; the one header that adds, Proxy-Authorization, is a request header no browser reads in a response.

Where Before After
Spec §18k, One site for every app SameSite and CSRF only another app's script can set a cookie for apps.localhost, and Clear-Site-Data: "cookies" clears every app's cookies, so an app trusts a cookie by a value it issued, never by its name
Spec §18k, Response a host-only cookie keeps one app's cookie from another app's name it stops a backend's response setting another app's cookie
Manifest reference, backend.webOrigin SameSite and CSRF only the same cookie rule, in one sentence
Hop-by-hop response headers (apps/app_web_origin.py) a copy of the proxy's list, missing Proxy-Authorization _drop_response_headers(): the proxy's _PROXY_HOP_HEADERS, read through the routes facade, plus Proxy-Connection, Trailer and Clear-Site-Data

The list is read lazily through the facade for the same reason as _drop_request_headers(): the dashboard imports this module on its first response. The module docstring and the comment on Clear-Site-Data say why it is dropped: a browser applies "cookies" to the whole site, which every app origin shares.

Backwards compatibility

Compatible: every header the old list dropped is still dropped. The one addition, Proxy-Authorization, is a request header that no browser reads in a response.

Removes nothing: _DROP_RESPONSE_HEADERS was private to the module with no reader in src/, test/ or website/src/, and _drop_response_headers() returns a superset of it.

Tests

  • New test_every_hop_by_hop_header_the_api_proxy_drops_is_dropped_from_responses: _PROXY_HOP_HEADERS must be a subset of _drop_response_headers(), and every one of those names plus Proxy-Connection and Trailer sent through hardened_response_headers must leave only the gateway's CSP. With main's list in its place, it fails on proxy-authorization.
  • Determinism: 20 runs at -n0, then 10 at -n 4 --dist loadgroup --max-worker-restart=2 with test/test_routes_facade.py and test/test_dashboard_security_headers.py as co-tenants, all green. test/test_app_web_origin.py in a shuffled order (seed 23376): 73 passed.
  • The backend related set (scripts/run_scoped_tests.py, 15 files): 411 passed, 2 skipped. The flake-pattern ratchet: 71 passed. semgrep on the diff: 0 findings.

Gate proof: tree 0782e4f67533; ran 25; skipped mypy=other:this venv lacks the types-requests stub and has an older aiohttp; all 6 errors are in 4 files this diff does not touch, and mypy on src/kiro_crew/apps/app_web_origin.py passes

Manual verification

The two cookie claims were checked in headless Chromium 155, with one loopback server answering for alpha.apps.localhost and beta.apps.localhost:

  • A script on alpha set planted=from-alpha; domain=apps.localhost. beta received it, localhost did not, and a POST from alpha's page to beta carried both it and beta's own SameSite=Strict cookie.
  • A Clear-Site-Data: "cookies" response from alpha cleared alpha's and beta's host-only cookies, and left the cookie on localhost.

Related Issues

Refs #36965

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

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 18, 2026
The app web origin's response drop list restated the API proxy's
hop-by-hop headers instead of reading them, so a name the proxy learns
to drop would still reach the browser from an app origin. It now reads
_PROXY_HOP_HEADERS through the routes facade, as the request side
already does, plus the two hop-by-hop spellings that list lacks and
Clear-Site-Data. Proxy-Authorization, which the copy missed, is now
dropped from responses as well.

The spec said a host-only cookie keeps one app's cookie from reaching
another app's name. It stops a backend's response doing that, but a
script on one app's pages can set a cookie for apps.localhost, which the
browser sends to every app origin and the gateway forwards, and a
Clear-Site-Data "cookies" from one app origin clears every app's
cookies. The spec, the manifest reference and the module docstring say
so, and tell an app to trust a cookie by a value it issued, never by its
name.

Refs kirodotdev#36965
@LachlanLindsay
LachlanLindsay force-pushed the refactor/app-web-origin-followup branch from 52e7e68 to b4ed48e Compare November 18, 2026 01:36
@LachlanLindsay

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/app-kit-platform.md (#35990, a section far from §18k) and four neighbouring files green_age.py flags (acp-client.md, crew-mode.md, shared-crew.md, test/test_shared_crew_teammate_owner_access.py), 1aa4eaee6d -> 88ce21a8df. The diff is unchanged. On b4ed48ebc4 the related backend tests (411 passed), test/test_shared_crew_teammate_owner_access.py (189 passed), the flake-pattern ratchet, semgrep and the pre-push gates pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant