Repository navigation
fix(apps): add an opt-in protected copy for app UI scripts - #35528
KiroCrewCaptain wants to merge 1 commit into
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The Goal promises the dashboard runs only gateway-installed scripts, but the switch ships off. The title says "opt-in" and the description credits a maintainer for the default, so this is a note, not a framing contradiction. Notes
What this change shipsInventory (7 items) — 4 justifiedIntent: stop a sandboxed process from changing the scripts the owner's dashboard runs for an app. A FIX, shipped as opt-in.
[FIRST-PRINCIPLES-REVIEWED] 7c3d2c4 Description read[DESCRIPTION-READ] c948ced9a544d002bc2cc7c39256b1a8450c99399e1cdaef54fd43175c71770e That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change is opt-in and off by default, so it can be walked back, and it serves scripts from a gateway-owned copy that the sandbox masks. Notes
[DESIGN-REVIEWED] 7c3d2c4 Description read[DESCRIPTION-READ] a06d377bd2fab124fc9e395f9b4bc204e0cbee0a6bef90fd663a4b5023cf2786 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 |
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: |
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: |
e856420 to
5563c8a
Compare
66154cf to
c28cbbf
Compare
c28cbbf to
fb785f6
Compare
fb785f6 to
fe1812f
Compare
fe1812f to
5d291bf
Compare
4523097 to
5f366fc
Compare
Human judgment recorded@KiroCrewCaptain recorded a reissue release (class
This decision applies only to this commit. A new push requires a new judgment. |
b639961 to
b9c0457
Compare
|
/ai-review override first-principles 4b9eb5b78f1dcc227d0b11d0d8a6bf19df14fc72 reissue: same dev mode scope ruling by on-call zezhexu for the new head, see #35528 (comment) |
|
AI-review override not recorded: |
|
/ai-review override first-principles b9c0457 reissue: same dev mode scope ruling by on-call zezhexu for the new head, see #35528 (comment) |
Human judgment recorded@KiroCrewCaptain recorded a reissue release (class
This decision applies only to this commit. A new push requires a new judgment. |
b9c0457 to
b90ad87
Compare
|
/ai-review override first-principles b90ad87 reissue: same dev mode scope ruling, approved by on-call bolichen for the new head, see #35528 (comment) |
|
/ai-review override gpt b90ad87 owner-decision: maintainer asked for main's behaviour as the default and the fallback, approved by on-call bolichen, see #35528 (review) |
Human judgment recorded@KiroCrewCaptain recorded a reissue release (class
This decision applies only to this commit. A new push requires a new judgment. |
|
AI-review override not recorded: class |
|
Accepting for this PR: when the config cannot be read, |
|
/ai-review override gpt b90ad87 owner-decision: maintainer asked for main's behaviour as the default and the fallback, approved by on-call bolichen, see #35528 (comment) |
Human judgment recorded@KiroCrewCaptain recorded a owner-decision release (class
This decision applies only to this commit. A new push requires a new judgment. |
|
/ai-review override first-principles 9389f42 reissue: same dev mode scope ruling, approved by on-call bolichen for the new head, see #35528 (comment) |
|
/ai-review override gpt 9389f42 owner-decision: maintainer asked for main's behaviour as the default and the fallback, approved by on-call bolichen, see #35528 (comment) |
Human judgment recorded@KiroCrewCaptain recorded a reissue release (class
This decision applies only to this commit. A new push requires a new judgment. |
Human judgment recorded@KiroCrewCaptain recorded a owner-decision release (class
This decision applies only to this commit. A new push requires a new judgment. |
|
@bolichen97 both of your asks are in on head 9389f42, rebased on today's main:
Also in this head: Checks run locally on this head: the related unit tests, the e2e smoke plus the dashboard Playwright suite (31 passed), and a live gateway smoke with the setting off and on (6/6 pass, including an outside dev root and an uninstall with it off). Could you re-review when you have a moment? AI-assisted, sent by Kiro Crew Captain |
|
The review found one blocking defect in the new copy path on this head.
Done well: with the setting off, the serving path is the same as main's. Optional:
|
buluoray
left a comment
There was a problem hiding this comment.
Request changes on 9389f42. The new opt-in setting agent.apps_ui_protected_copy makes the /apps//ui/ route serve an app's .js/.mjs from a gateway-owned copy under member-records/app-ui/, so a script edited in the sandbox-writable app tree no longer runs in the dashboard origin. Off by default it serves as main does, and both of bolichen97's asks are in. One containment defect blocks: with the setting on, an owner registration of an app whose folder apps/ is a link to a folder outside the install copies that folder's scripts, and the route then serves them with 200. Main answers 400 for the same linked install entry (test_a_symlinked_INSTALL_ENTRY_cannot_vouch_for_its_own_containment). The cause: record_folder (protected_app_ui.py:305-307) passes the unresolved folder, and record() (line 189) checks realpath(ui) against realpath(folder); both resolve through the link, so the check passes. The comment at lines 301-302 says this case copies nothing. I reproduced it on this head: the copy held outside/ui/x.js and GET /apps/linked-app/ui/x.js answered 200 with its bytes. The PR's own review loop found the same defect on this head (comment 6907335160), and nothing has been pushed since. Smallest fix: refuse in record_folder when is_link_or_junction(folder). That also covers the start-up pass, which screens links only when it lists names (line 351), not when it copies. Add one test that registers a linked entry with the setting on and checks the copy is empty. 223 targeted tests pass on the head. On main, all 23 tests in the new file error at import and 2 new route tests fail. CI is green: 96 latest check-runs, 78 success and 18 skipped. PR Readiness is success. The GPT and First Principles lanes carry accepted overrides. Decisive lines: src/kiro_crew/apps/protected_app_ui.py:189, src/kiro_crew/apps/protected_app_ui.py:301-307, src/kiro_crew/apps/protected_app_ui.py:351, src/kiro_crew/apps/routes_static.py:242-258
The dashboard imports an app's UI module into its own origin, and the app's tree is writable from the sandbox. With agent.apps_ui_protected_copy on (off by default, which keeps main's behaviour), scripts (.js, .mjs) are served from a copy under member-records/app-ui/, which the sandbox masks. Install and update take the copy from the source they install inside their transaction; an owner registration copies the app's folder; apps from an older build are copied once after the listener binds. The copy is taken whether or not the setting is on, so turning it on works at once.
buluoray
left a comment
There was a problem hiding this comment.
Approve on df359fd. This supersedes my earlier Request Changes on 9389f42. The blocking defect is fixed. With agent.apps_ui_protected_copy on, record_folder now refuses an apps/<name> that is a link or junction before it copies anything (protected_app_ui.py:306-309). The owner registration and the start-up pass (:406) both go through record_folder, so one check covers both. I re-ran the earlier repro on this head: with the setting on, a linked apps/linked-app pointing outside the install gets no copy, and GET /apps/linked-app/ui/x.js no longer answers 200, after registration or after the start-up pass. With the new check removed, the same repro serves the outside bytes with 200, and the new test test_a_linked_app_folder_is_not_copied_on_registration (test/test_protected_app_ui.py:391) turns red, so the test guards the fix. The other change since my last review wraps the UI-root resolve in routes_static.py:235-264, so a name the OS cannot resolve (an embedded NUL, a link loop) answers 400 instead of a 500; it fails closed and has a test. 226 targeted tests pass on this head. Follow-ups, not blocking: (1) with the setting off, install and update still fail if the copy raises, a successful registration still sends app_reload, and the PR body still says a failed registration copy answers 500 (it answers 201 with app_ui_copy_failed); the body also says off-mode installs succeed wherever main succeeds. (2) record_folder checks the folder once and record() resolves it again, so a swap in between is a narrow race; opening the folder once and copying from that would close it. (3) GPT's downgraded note on manager_install.py:942 (a hard kill between rollback and restore leaves the new copy served) holds and is rare and recoverable. (4) ui.entry like ../api/x.js still reaches the dashboard origin through the app backend; main has the same gap, worth its own issue. Decisive lines: src/kiro_crew/apps/protected_app_ui.py:306-309, src/kiro_crew/apps/protected_app_ui.py:406, test/test_protected_app_ui.py:391, src/kiro_crew/apps/routes_static.py:235-264
Problem / Motivation
Goal: The dashboard runs only the app UI scripts the gateway itself installed, so a sandboxed process cannot change the code that runs in the owner's dashboard session.
The dashboard imports an app's UI module (
/apps/<name>/ui/<entry>) into its own origin (website/src/components/AppHost.tsx,appBundleImport.ts). The route that serves it (apps/routes_static.py:_open_ui_file) reads the bytes from~/.kiro/crew/apps/<name>/ui/. That tree is writable from the OS sandbox:sandbox_leaves.pyseals only a few data paths underapps/, and the app directory can be renamed aside and recreated. The route's checks (pinned open, no links, single link count) bind the file name, never the content. So the script the dashboard runs is whatever was last written to that folder, by anyone who can write it, including a sandboxed agent session.Why it matters
A module imported into the dashboard origin runs with the owner's session and can call owner-only APIs. The sandbox exists so that agent sessions cannot reach those controls. Anyone running a sandboxed agent on content they do not fully trust is affected.
Not a goal
AppHostloads them.What changed (motivation → approach → change)
Symptom: the route serves script bytes from a sandbox-writable folder. Root cause: the only copy of an app's scripts the gateway has is the one in the app's own tree. Fix: the gateway keeps its own copy, in the place it already keeps the owner's per-app decisions (
member-records/, masked in every sandbox mode, see #34177), and serves scripts from there.apps/protected_app_ui.py: copies every regular.js/.mjsfile under aui/directory intomember-records/app-ui/<name>/(links and junctions not followed, single-link files only, same 8 MiB cap as the route,bounded_read), swaps it in atomically and hands back the previous copy so a transaction can restore or drop it; a copy left set aside by a hard stop between the two renames is put back from the protected directory on the next read (never rebuilt from the app tree); an uninstall removes it and every set-aside copy, and first writes a withdrawal mark (cleared by the next recorded copy) so a copy the removal cannot delete is never served; the copy skips the same directories an install skips (node_modules,.git, ...).install_appandupdate_apptake the copy from the source they install, inside their transaction: a failed copy fails the install or update, and a rolled-back update restores the previous copy with the tree, as a separate last step so a failure there never stops the tree and record rollback. Adoption goes throughupdate_app.POST /api/apps/register(owner only) copies a self-managed app's folder after the registration, on the executor; a failed copy answers 500 and asks the owner to register again. The registry pre-registration path, which puts no UI files in the app folder, is unchanged.agent.apps_ui_protected_copy(bool, defaultfalse). Off keeps main's behaviour: the route reads scripts from the app's folder, and an uninstall that cannot write its withdrawal mark goes ahead (logged). On:routes_static._open_ui_fileopens a.js/.mjsrequest under the copy, with the same pinned open and checks as before, and other file types are read from the tree as before. The copy is taken whether or not the setting is on, so turning it on works at once. Per maintainer review: default matches main, and no new regex (_set_aside_copiesuses plain string checks).routes_static._open_ui_file: a.js/.mjsrequest is opened under the copy, with the same pinned open and checks as before. Other file types are read from the app tree as before. A ui root that equals the operator's dev-mode grant AND lies outside the install (only the host-sidekirocrew app dev --confirm-out-of-install-rootgrants that) is served live; a dev root inside the install still serves scripts from the copy.installed.json) that has no copy, under that app's record lock (the lock install and update hold). This runs in_kick_interrupted_update_sweep, off the boot path; a script read that comes first runs the same pass. The marker is written before any app tree is read (a pass that cannot write it copies nothing), so nothing is ever taken from an app tree later. Install and update sources keep hard-linked scripts (the install copies them too); an app's own folder does not. Containment compares against the root's kernel spelling, so a case alias on macOS drops nothing. An uninstall writes the withdrawal mark before it deletes anything and refuses if it cannot, and a rolled-back uninstall clears it. A script that cannot be read fails that app's copy instead of being left out; that app's scripts answer 404 until it is updated, reinstalled or registered again (logged). After the pass, an app the gateway never installed has no copy and its scripts answer 404. A name with no copy and nothing set aside takes no lock and leaves no file.member_records.RECORD_KINDSgainsapp-ui. Docs: App Kit platform contracts §18, and the publishing guide says a self-managed app registers again to ship a UI change.Alternatives considered: sealing
apps/read-only in the sandbox breaks every app backend and agent that writes app data there; hashing at serve time leaves a window between the hash and the stream and has no good answer on a mismatch. Serving a gateway-owned copy keeps streaming as it is and keeps the last installed version working.Backwards compatibility
Compatible: with the setting off (the default), the UI route serves exactly what main serves, and install, update, registration and uninstall succeed wherever main succeeds. The only difference is the extra copy written under
member-records/app-ui/.Removes nothing by default. With the setting on, scripts of a folder under
apps/that no install, update or registration put there answer 404, and a self-managed app that rewrites its scripts without registering again keeps serving the scripts of its last registration.Reader: website/src/components/AppHost.tsx:importAppBundle -- app -- installed apps have a copy; test_a_script_changed_in_the_app_tree_is_served_as_installed
Reader: src/kiro_crew/apps/app_frame.py:_frame_html -- app -- link-preview frames import the same route; installed apps have a copy; test_each_allowed_extension_serves_with_its_content_type
Reader: src/kiro_crew/apps/dev_mode.py:dev_mode_granted_root -- app -- a granted dev-mode root is still served live; test_a_LINKED_ui_root_still_serves_under_the_dev_grant
Reader: src/kiro_crew/apps/routes_install.py:handle_register_external -- app -- a self-managed app's scripts are copied at each owner registration; test_an_owner_registration_takes_the_copy_of_a_self_managed_app
Tests
test/test_protected_app_ui.py(new): a script changed in an installed app's tree is still served as installed; a folder planted after the start-up pass gets 404 for its scripts with no earlier request; non-script files are still read from the tree; an update replaces the copy and an uninstall removes it; a failed update keeps the copy of the version left installed; an app from an older build gets its copy at the start-up pass; a failed start-up copy is not retried from the app tree, and a folder planted later gets no copy; a made-up name leaves no lock file; an owner registration through the route copies a self-managed app's scripts; a copy set aside by a hard stop is put back and served; an uninstall drops set-aside copies too, so a recreated folder gets nothing back.test/test_app_ui_file_route.py: the fixture app now hasinstalled.json; the symlinked-ancestor test keeps its 400 on a.cssfile and checks that a script under a linked directory is not served.test/test_apps_routes_coverage_app_serving.py,test/test_member_records.py,test/test_dashboard_server_composition_contract.py: fixture, record-kind pin and lazy-import map updated.Proof: PROVEN test/test_dashboard_server_composition_contract.py::test_the_lazy_imports_stay_inside_the_functions_that_need_them (head 9389f42)
scripts/local-gate.py: backend related tests 647 passed. The frontend step could not run on this host (npm registry auth); no frontend file changed.test/test_updates_handlers_facade.py::test_every_name_served_from_outside_the_family_is_visible_to_type_checkersfails on main 26e8e9e itself (_running_versionfrom #35088); this PR touches no updates file. Likewisetest/test_wait_discipline_ratchet.py::test_the_scan_matches_known_sitesnamestest/test_update_boot_apply.py, which this PR does not touch.Manual verification
N/A — unit coverage sufficient: the route, install, update, uninstall, registration and upgrade paths are each exercised through the real functions with a temporary data home.
Related Issues
N/A — reported privately.
Sibling sweep
Swept: git grep -n -E 'apps_dir() / name|app_dir(name) / "ui"' -- src/kiro_crew/apps/ src/kiro_crew/dashboard/
Sibling: src/kiro_crew/apps/routes_static.py:232 -- changed here
Sibling: src/kiro_crew/apps/routes_art.py:138 -- not affected -- serves images with a sandbox CSP, never imported as code
Sibling: src/kiro_crew/apps/app_frame.py:646 -- not affected -- loads the same route, so it gets the copy too, inside an opaque-origin frame
Pattern harvest
Rule candidate: review-prompt
Pattern: bytes the dashboard executes in its own origin must come from a gateway-owned location, never from a sandbox-writable tree
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.