Skip to content

fix(apps): add an opt-in protected copy for app UI scripts - #35528

Open
KiroCrewCaptain wants to merge 1 commit into
mainfrom
sec/app-ui-import-integrity
Open

KiroCrewCaptain wants to merge 1 commit into
mainfrom
sec/app-ui-import-integrity

Conversation

@KiroCrewCaptain

@KiroCrewCaptain KiroCrewCaptain commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

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.py seals only a few data paths under apps/, 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

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.

  • New apps/protected_app_ui.py: copies every regular .js / .mjs file under a ui/ directory into member-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_app and update_app take 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 through update_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.
  • New setting agent.apps_ui_protected_copy (bool, default false). 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_file opens a .js / .mjs request 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_copies uses plain string checks).
  • routes_static._open_ui_file: a .js / .mjs request 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-side kirocrew app dev --confirm-out-of-install-root grants that) is served live; a dev root inside the install still serves scripts from the copy.
  • Upgrade path: right after the listener binds, after the interrupted-update sweep, one pass copies every installed app folder (a folder with 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_KINDS gains app-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 has installed.json; the symlinked-ancestor test keeps its 400 on a .css file 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_checkers fails on main 26e8e9e itself (_running_version from #35088); this PR touches no updates file. Likewise test/test_wait_discipline_ratchet.py::test_the_scan_matches_known_sites names test/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

  • 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

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@KiroCrewCaptain
KiroCrewCaptain requested a review from a team as a code owner November 11, 2026 19:57
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 7c3d2c4981eb9a809932825c56c7e10879e29527 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 11, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 7c3d2c4981eb9a809932825c56c7e10879e29527 — 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 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

  • Item 1 — oversized: with the setting off (the default), every install, update, registration and boot still writes member-records/app-ui/ copies that nothing reads. "The copy is taken whether or not the setting is on, so turning it on works at once" is what pays for that. Subtraction: none smaller. A copy taken from the tree when the setting is turned on would read the sandbox-writable tree, which is what the Goal rules out.
  • Item 5 — undeclared: the description says "a failed copy answers 500". The diff answers status=201 with resp["code"] = "app_ui_copy_failed". Grep finds zero in-repo readers of that code (only the route that sets it and its test). Subtraction: drop the code/warning fields, or make the description match the 201.
  • Item 6 — undeclared: a successful registration now calls _announce_app_ui_changed, so an open dashboard reloads the app's UI.

What this change ships

Inventory (7 items) — 4 justified

Intent: stop a sandboxed process from changing the scripts the owner's dashboard runs for an app. A FIX, shipped as opt-in.

  1. New setting agent.apps_ui_protected_copy, off by default; on, app .js/.mjs are served from the gateway's copy — oversized (copies are taken even while it is off)
  2. Install, update and uninstall keep, roll back and remove a protected script copy; a failed copy now fails the install or update — justified
  3. A one-time pass after the listener binds copies the scripts of apps an older build installed — justified
  4. With the setting on, scripts of an app folder the gateway never installed answer 404 — justified
  5. A registration whose script copy fails answers 201 with a code/warning, not the 500 the description states — undeclared
  6. Registration now makes an open dashboard reload the app's UI — undeclared
  7. Uninstall writes a withdrawal mark first, and refuses if it cannot while the setting is on — justified

[FIRST-PRINCIPLES-REVIEWED] 7c3d2c4

Description read

[DESCRIPTION-READ] c948ced9a544d002bc2cc7c39256b1a8450c99399e1cdaef54fd43175c71770e

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 11, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

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

  • With agent.apps_ui_protected_copy off (the default), the goal in the description isn't met on a stock install. The dashboard still imports scripts from the folder the sandbox can write to. Track the default flip as a named follow-up so the copy that gets written but not read doesn't become permanent dead weight.
  • A self-managed app's copy is still taken from its own sandbox-writable folder when the owner registers it again. Anything planted before that registration gets protected along with the real scripts. Say this in the publishing-guide text.

[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 .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 11, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 7c3d2c4981eb9a809932825c56c7e10879e29527 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 7c3d2c4

Verdict parsed from the review's SHA-scoped output markers for commit 7c3d2c4981eb9a809932825c56c7e10879e29527.

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

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 7c3d2c4981eb9a809932825c56c7e10879e29527 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7c3d2c4

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

@KiroCrewCaptain
KiroCrewCaptain force-pushed the sec/app-ui-import-integrity branch 2 times, most recently from e856420 to 5563c8a Compare November 11, 2026 23:28
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 11, 2026
@KiroCrewCaptain
KiroCrewCaptain force-pushed the sec/app-ui-import-integrity branch 2 times, most recently from 66154cf to c28cbbf Compare November 12, 2026 01:11
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 12, 2026
@KiroCrewCaptain
KiroCrewCaptain force-pushed the sec/app-ui-import-integrity branch from c28cbbf to fb785f6 Compare November 12, 2026 02:37
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 12, 2026
@KiroCrewCaptain
KiroCrewCaptain force-pushed the sec/app-ui-import-integrity branch from fb785f6 to fe1812f Compare November 12, 2026 03:13
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 12, 2026
@KiroCrewCaptain
KiroCrewCaptain force-pushed the sec/app-ui-import-integrity branch from fe1812f to 5d291bf Compare November 12, 2026 04:31
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 12, 2026
@KiroCrewCaptain
KiroCrewCaptain force-pushed the sec/app-ui-import-integrity branch 3 times, most recently from 4523097 to 5f366fc Compare November 12, 2026 07:19
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@KiroCrewCaptain recorded a reissue release (class reissue) for the first-principles AI finding on b63996111aac8b3b2bf70bc5e16f9458c0a6f56e.

same dev mode scope ruling by on-call zezhexu for the new head, see #35528 (comment)

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 13, 2026
@KiroCrewCaptain
KiroCrewCaptain force-pushed the sec/app-ui-import-integrity branch from b639961 to b9c0457 Compare November 13, 2026 15:35
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

/ai-review override first-principles 4b9eb5b78f1dcc227d0b11d0d8a6bf19df14fc72 reissue: same dev mode scope ruling by on-call zezhexu for the new head, see #35528 (comment)

@github-actions

Copy link
Copy Markdown
Contributor

AI-review override not recorded: 4b9eb5b78f1dcc227d0b11d0d8a6bf19df14fc72 is not the current PR head. Re-run the command with b9c04572e1562a871e0bb071c69ae55b99c88a0b.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

/ai-review override first-principles b9c0457 reissue: same dev mode scope ruling by on-call zezhexu for the new head, see #35528 (comment)

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@KiroCrewCaptain recorded a reissue release (class reissue) for the first-principles AI finding on b9c04572e1562a871e0bb071c69ae55b99c88a0b.

same dev mode scope ruling by on-call zezhexu for the new head, see #35528 (comment)

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Nov 13, 2026
@KiroCrewCaptain
KiroCrewCaptain force-pushed the sec/app-ui-import-integrity branch from b9c0457 to b90ad87 Compare November 15, 2026 19:33
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

/ai-review override first-principles b90ad87 reissue: same dev mode scope ruling, approved by on-call bolichen for the new head, see #35528 (comment)

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

/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)

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@KiroCrewCaptain recorded a reissue release (class reissue) for the first-principles AI finding on b90ad87d448073c56ab44dc84868864edebdfeb8.

same dev mode scope ruling, approved by on-call bolichen for the new head, see #35528 (comment)

This decision applies only to this commit. A new push requires a new judgment.

@github-actions

Copy link
Copy Markdown
Contributor

AI-review override not recorded: class owner-decision needs a link to the owner's decision comment (https://github.com/<owner>/<repo>/pull/<n>#issuecomment-<id>) in the reason. Use /ai-review override <fable|gpt|design|ux|first-principles|scope|all> <current-sha> <class>[ #N]: <reason, 20 to 500 characters>, where <class> is one of false-positive, not-applicable, pre-existing, evidence-supplied, infra-failure, reissue, deferred, owner-decision. What each class needs: docs/ci/ci-and-reviews.md#risk-release-records.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 15, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

Accepting for this PR: when the config cannot be read, agent.apps_ui_protected_copy reads as off, which is main's behaviour. This follows the maintainer review asking for main's behaviour as the default and the fallback (#35528 (review)). Decision by on-call bolichen.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

/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)

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@KiroCrewCaptain recorded a owner-decision release (class owner-decision) for the gpt AI finding on b90ad87d448073c56ab44dc84868864edebdfeb8.

maintainer asked for main's behaviour as the default and the fallback, approved by on-call bolichen, see #35528 (comment)

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 15, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

/ai-review override first-principles 9389f42 reissue: same dev mode scope ruling, approved by on-call bolichen for the new head, see #35528 (comment)

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

/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)

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@KiroCrewCaptain recorded a reissue release (class reissue) for the first-principles AI finding on 9389f42bd1d33925c249e533fc7c082a53468ade.

same dev mode scope ruling, approved by on-call bolichen for the new head, see #35528 (comment)

This decision applies only to this commit. A new push requires a new judgment.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@KiroCrewCaptain recorded a owner-decision release (class owner-decision) for the gpt AI finding on 9389f42bd1d33925c249e533fc7c082a53468ade.

maintainer asked for main's behaviour as the default and the fallback, approved by on-call bolichen, see #35528 (comment)

This decision applies only to this commit. A new push requires a new judgment.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

@bolichen97 both of your asks are in on head 9389f42, rebased on today's main:

  • The default matches main. agent.apps_ui_protected_copy is off by default, and an unreadable config also reads as off.
  • No new regex. _set_aside_copies uses plain string checks.

Also in this head: protected_app_ui is now imported inside the functions that use it, which keeps the MCP pre-list import budget at its ceiling (the Backend Tests 3.12 shard 6 red on the last 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

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator Author

The review found one blocking defect in the new copy path on this head.

  1. src/kiro_crew/apps/protected_app_ui.py:189 (called from record_folder, around line 305). Trigger: agent.apps_ui_protected_copy is on, apps/<name> is a symlink or junction to a folder outside the install, and the owner registers the app (POST /api/apps/register). Outcome: record() checks realpath(ui_dir) against os.path.realpath(container). Both resolve through the link, so the check passes and the target's ui/*.js files are copied. The route then serves that copy. Main refuses the same linked install entry with 400 (test_a_symlinked_INSTALL_ENTRY_cannot_vouch_for_its_own_containment). The comment at lines 301-302 says this case copies nothing, but it copies the target's scripts. This was reproduced on the head tree: apps/linked-app -> ../outside, and after record_folder the copy holds outside/ui/x.js. Smallest fix: in record_folder, refuse when is_link_or_junction(folder). capture_existing already screens links this way. The other option is to check containment against the unresolved realpath(apps_root)/name. Add one test with the setting on that plants a link at apps/<name>, registers the app, and asserts that the copy is empty and the script answers 404 or 400.

Done well: with the setting off, the serving path is the same as main's. pinned_root stays None and the anchor equals main's resolved install path.

Optional:

  • manager_install.py:396 and :904: with the setting off, install and update still fail when record() raises. Uninstall swallows that error. Either apply the uninstall rule to them, or correct the Backwards-compatibility section, which says install and update succeed wherever main succeeds.
  • routes_install.py:522: with the setting off, a registration now sends app_reload. An open dashboard tab then reloads, which main did not do. Consider sending it only when the setting is on.
  • The What changed section says a failed registration copy answers 500. The code and its test answer 201 with code: app_ui_copy_failed.

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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

readiness: checking Automated validation is still running

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants