Repository navigation
fix(apps): load an app admission policy saved with a utf-8 bom - #34185
Conversation
An app_admission.json saved by a Windows editor carries a leading byte-order mark. The loader handed it to bare json.loads, which refuses the mark, so the gate fell back to deny-all and refused every third-party app, approved ones included. Parse it through user_json.loads_user_json like the other hand-saved config readers. Invalid JSON, UTF-16 and a second mark still fail closed. Closes #32686
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS The fix reuses the existing [DESIGN-REVIEWED] 623c73c Description read[DESCRIPTION-READ] 7011e836219de8a36f49600824613e3e29cccaff0facb68bf208a9dff98c9efc 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 This is a mechanism-level fix that reuses the existing What this change shipsInventory (3 items) — 3 justifiedIntent: an admin who saves
Root cause and siblings:
[FIRST-PRINCIPLES-REVIEWED] 623c73c Description read[DESCRIPTION-READ] 19a58d0d1c418720e855baa8030aa96034b5f50b58b8290240247fc72a8dff2f That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsI checked the one-line reader change, the shared No findings. [OPUS-REVIEWED] 623c73c 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: |
buluoray
left a comment
There was a problem hiding this comment.
Approve on 623c73c. app_admission.json is now parsed via user_json.loads_user_json (apps/admission.py:142, user_json.py:38-43), which strips one leading UTF-8 BOM, so a BOM-saved policy loads as authored instead of deny-all. UTF-16, two BOMs and invalid JSON still hit the unchanged fail-closed branch (test/test_user_json_bom.py:428-455).
|
[operator: bolichen97] Closed and reopened with no code change: PR Readiness was waiting on a Code Review run that records its base (the #33337 rule), and only a new pull request event starts one. The close turned auto-merge off; it is re-armed once this re-run is green. |
|
[operator: bolichen97] Closed and reopened with no code change. Backend Tests shard 4 (Linux and Windows) failed on |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving head 623c73c. The review checked these points. apps/admission.py now parses app_admission.json with the existing loads_user_json helper, which strips exactly one leading UTF-8 mark and raises the same exceptions as json.loads. The dropped import json has no other use in the module. The except Exception branch still falls back to _fail_closed_policy() with the critical SEL event, so UTF-16, two marks and corrupt JSON still deny. No other main commit touches this reader, and none of the open PRs that edit admission.py change it.
Done well: TestAppAdmissionPolicyReader asserts the whole loaded policy and a real allow and deny decision through app_admission_denied. Its two_marks and utf16 cases would catch a fix that strips too much or fails open. The utf8_bom case fails against main's reader, so it pins the bug.
Optional:
- The
docs/system-specs/modules/security.mdparagraph conflicts textually with open #34390. Whichever PR lands second needs a manual rebase and should keep both added sentences. The code merges clean.
Problem / Motivation
Goal: An
app_admission.jsonsaved as UTF-8 with a byte-order mark loads as written, instead of blocking every third-party app.Windows editors and PowerShell 5.1
Set-Content -Encoding UTF8save UTF-8 with a leading byte-order mark (BOM). Whenapp_admission.jsoncarries one,load_app_admission_policycannot read it and falls back to the deny-all policy. An app the policy approves is then refused withapp '<name>' is not on the approved allowlist. The same file without the mark loads fine.Why it matters
An admin who drops the policy on a Windows host with an ordinary editor gets every third-party app install, update, enable, registration, boot and restart refused, approved apps included. The refusal names the allowlist and the log says only "unreadable", so nothing points at the file's encoding.
Not a goal
platform/admission.py, platform governance: an admission policy or governance profile saved as UTF-8 with BOM fails closed to deny-all, because load_admission_policy and ProfileStore._reload parse with bare json.loads #32687).What changed (motivation → approach → change)
A policy file with a BOM was read as deny-all, so every third-party app was refused. The loader decoded it as plain
utf-8, which keeps the mark as the first character, and barejson.loadsrefuses that character.load_app_admission_policyinapps/admission.pynow parses throughuser_json.loads_user_json, the helper the hand-saved config readers use. It drops one leading mark and is otherwise plainjson.loads, with the same exceptions, so the fail-closed branch is unchanged. This is the same move the governance policy reader made in #28425. The security spec's app admission paragraph says so.Backwards compatibility
Compatible: only a file that differs from valid UTF-8 JSON by one leading BOM changes, and it now loads exactly the policy it holds instead of deny-all; every other input reads as before.
Removes nothing: the loader accepts one more spelling of the same policy and refuses everything it refused before.
Tests
test/test_user_json_bom.py::TestAppAdmissionPolicyReader:test_the_policy_loads_as_authored(BOM file and plain control): the loaded policy equals the authored one, an approved app is admitted and an unlisted app is still denied.test_anything_else_still_fails_closed(UTF-16, BOM before invalid JSON, two marks): the loader still returns the deny-all policy.Determinism: the new class passed 20 runs at
-n0, 10 runs at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_app_denial_code.pyandtest/test_install_receipt.py, and the whole file in a shuffled order (seed 22857, 49 ids).Proof: PROVEN test/test_user_json_bom.py::TestAppAdmissionPolicyReader::test_the_policy_loads_as_authored[utf8_bom] (head 623c73c)
Manual verification
N/A — unit coverage sufficient: the change is one parse call, and the tests drive the real loader and gate on the file bytes the issue reports.
Screenshots / video
N/A — no user-visible frontend surface changes.
Related Issues
Closes #32686
Sibling sweep
Swept: git grep -nE "json.loads(" -- 'src/kiro_crew/admission.py'
Sibling: src/kiro_crew/apps/admission.py:142 -- changed here
Sibling: src/kiro_crew/platform/admission.py:745 -- tracked in #32687
Sibling: src/kiro_crew/apps/builtins/auto_improvement/spine/candidate_admission.py:164 -- not affected -- parses a subprocess reply, not a file a person saves
Sibling: src/kiro_crew/dashboard_templates/manifest.py:469 -- tracked in #32685
The sweep's other hits in
platform/admission.pyare not affected::818handsjson.loadsraw bytes, whose encoding detection drops the mark, and:858and:865read a plugin manifest packaged in an installed distribution.Pattern harvest
Rule candidate: semgrep
Pattern: a hand-saved config file read with
read_text(encoding="utf-8")and parsed with barejson.loadsinstead ofuser_json.loads_user_jsonChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)