Repository navigation
fix: load an admission policy or governance profile saved with a bom - #35384
Conversation
An admission policy or governance profile saved as UTF-8 with a byte-order mark (the default for Notepad's "UTF-8 with BOM" and PowerShell 5.1 Set-Content -Encoding UTF8) failed closed to deny-all: both readers decoded strict UTF-8, kept U+FEFF, and handed it to bare json.loads, which refuses it. Parse both with user_json.loads_user_json, the helper every hand-saved JSON reader uses and the one the security policy reader moved to in PR #28425. It drops one leading mark and is otherwise json.loads, so the fail-closed arms are unchanged: invalid JSON after a mark, two marks and UTF-16 still fail closed. The admission seed check still hashes the same bytes. Closes #32687
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: both readers now go through the existing BOM helper, and every other input still fails closed. [DESIGN-REVIEWED] 3492bf3 Description read[DESCRIPTION-READ] 3c436a55ba7bd1df45dbfcaab27091cce1134a8ed2f65056bdaffaa0d2aad9e7 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 Nothing blocks. Both readers now parse through the existing Notes
What this change shipsInventory (3 items) — 3 justifiedIntent: a fleet admission policy or governance profile saved with a UTF-8 BOM by a Windows editor loads as written instead of failing closed to deny-all. This is a FIX (#32687).
[FIRST-PRINCIPLES-REVIEWED] 3492bf3 Description read[DESCRIPTION-READ] f4a09f939a2e99114bf7649ffb7d4ea9ee8a799fc61dde9e3ce0e0642ecd589f That sha256 names the PR description this verdict read. 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: |
buluoray
left a comment
There was a problem hiding this comment.
Approve on 3492bf3. An admission policy or governance profile saved with one UTF-8 BOM now loads as authored instead of deny-all; UTF-16, two marks and invalid JSON still fail closed, and no reader can load a file as looser than its contents. Decisive lines: src/kiro_crew/platform/admission.py:746, src/kiro_crew/platform/governance_profiles.py:765, src/kiro_crew/user_json.py (loads_user_json = json.loads(text.removeprefix("\ufeff")))
|
[operator: bolichen97] |
Problem / Motivation
Goal: A fleet admission policy or governance profile saved as UTF-8 with a byte-order mark loads as written, instead of failing closed to deny-all.
Windows editors and PowerShell 5.1
Set-Content -Encoding UTF8save UTF-8 with a leading byte-order mark (BOM). When the admission policy carries one,load_admission_policylogsadmission policy at <path> is unreadable; failing closedand returns the fail-closed policy: modeenforce, an empty allowlist and a required signature. When a governance profile carries one,ProfileStorelogsprofile <name>.json is invalid; falling back to deny-all (fail-closed)and the profile's surface resolves to deny-all. The same files without the mark load fine.Why it matters
An operator who edits either file with an ordinary Windows editor gets every plugin refused (an edition with a companion plugin does not start), or the profile's surface denied, and a governed fleet whose profile has no recoverable bind refuses to boot. The log says "unreadable" or "invalid", so nothing points at the file's encoding.
Not a goal
apps/admission.py), fixed for apps admission: an app_admission.json saved as UTF-8 with BOM fails closed to deny-all, because load_app_admission_policy parses with bare json.loads #32686.What changed (motivation → approach → change)
An admission policy or governance profile saved with a BOM now loads as written instead of as deny-all. Both readers decoded the file as strict UTF-8, which keeps the mark as the first character U+FEFF, then handed the text to bare
json.loads, which refuses it ("Unexpected UTF-8 BOM").load_admission_policy(platform/admission.py) andProfileStore._reload(platform/governance_profiles.py) now parse withuser_json.loads_user_json, the helper the hand-saved config readers use; the security policy reader moved to it in #28425. It drops exactly one leading mark and is otherwisejson.loadswith the same exceptions, so every fail-closed path is untouched. The admission seed check still hashes the same text.governance.md's byte-order-mark paragraph names the two readers.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 or profile it holds instead of deny-all; every other input reads as before.
Removes nothing: both readers accept one more spelling of the same document and refuse everything they refused before.
Tests
test/test_user_json_bom.py:TestAdmissionPolicyReader::test_the_policy_loads_as_authored(BOM file and plain control):load_admission_policyreturns the authored policy.TestAdmissionPolicyReader::test_anything_else_still_fails_closed(UTF-16, BOM before invalid JSON, two marks): it still returnsenforce, an empty allowlist and a required signature.TestGovernanceProfileReader::test_the_profile_parses(BOM file and plain control): the store holds the parsed profile, with nothing unrecoverable and no deny-all fallback.TestGovernanceProfileReader::test_anything_else_still_falls_back_to_deny_all(the same three inputs): the profile still falls back to deny-all.Determinism: the two new classes (10 ids) passed 20 runs at
-n0, 10 runs at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_platform_admission.pyandtest/test_governance_profiles.py, and the whole file in a shuffled order (seed 32687, 59 ids).Proof: PROVEN test/test_user_json_bom.py::TestAdmissionPolicyReader::test_the_policy_loads_as_authored[utf8_bom], test/test_user_json_bom.py::TestGovernanceProfileReader::test_the_profile_parses[utf8_bom] (head 3492bf3)
Manual verification
N/A — unit coverage sufficient: the change is one parse call in each reader, and the tests drive the real readers on the file bytes the issue reports.
Screenshots / video
N/A — no user-visible frontend surface changes.
Related Issues
Closes #32687
Sibling sweep
Swept: git grep -nE "json.loads(" -- 'src/kiro_crew/platform/.py' 'src/kiro_crew/platform/**/.py'
Sibling: src/kiro_crew/platform/admission.py:746 -- changed here
Sibling: src/kiro_crew/platform/governance_profiles.py:765 -- changed here
Sibling: src/kiro_crew/apps/admission.py:142 -- not affected -- already parses with the same helper (#34185)
Sibling: src/kiro_crew/platform/governance.py:738 -- not affected -- its text comes from read_endorsed_config_text, which already strips one mark
The sweep's other hits are not affected:
admission.py:819(read_policy_trust_root) handsjson.loadsraw bytes, whose encoding detection drops the mark;:859and:866read a plugin manifest packaged in an installed distribution,app_update_request.pyandupdate_stepup.pyread records the gateway writes, and thepolicy_distribution_*,enterprise_policy_*andwheel_engine.pyhits parse network bodies, an env var or a wheel.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: ...)