Skip to content

fix(apps): load an app admission policy saved with a utf-8 bom - #34185

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/32686-app-admission-bom
Nov 11, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/32686-app-admission-bom

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An app_admission.json saved 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 UTF8 save UTF-8 with a leading byte-order mark (BOM). When app_admission.json carries one, load_app_admission_policy cannot read it and falls back to the deny-all policy. An app the policy approves is then refused with app '<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

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 bare json.loads refuses that character.

load_app_admission_policy in apps/admission.py now parses through user_json.loads_user_json, the helper the hand-saved config readers use. It drops one leading mark and is otherwise plain json.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=2 beside test/test_app_denial_code.py and test/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.py are not affected: :818 hands json.loads raw bytes, whose encoding detection drops the mark, and :858 and :865 read 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 bare json.loads instead of user_json.loads_user_json

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

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
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 9, 2026 23:19
@bolichen97
bolichen97 requested a review from Zedmor November 9, 2026 23:19
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 623c73c18c03071112784ebc59563b6121e62b12 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 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

The fix reuses the existing loads_user_json helper that the governance reader already uses. It removes nothing and leaves the fail-closed branch unchanged.

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

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

This is a mechanism-level fix that reuses the existing user_json.loads_user_json. The two unfixed siblings each have a tracking issue.

What this change ships

Inventory (3 items) — 3 justified

Intent: an admin who saves app_admission.json with a Windows editor gets the policy they wrote, not a deny-all that refuses every third-party app. FIX.

  1. An app_admission.json with one leading UTF-8 BOM now loads as authored instead of failing closed to deny-all — justified
  2. UTF-16, two marks and invalid JSON after a BOM still fail closed (pinned by tests) — justified
  3. The security spec's app admission paragraph now states that one leading BOM is accepted — justified

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 623c73c18c03071112784ebc59563b6121e62b12 — this comment is updated in place on each push.

Review details

I checked the one-line reader change, the shared loads_user_json helper, and the new tests, and found no defect. The discovery pass produced no candidates.

No findings.

[OPUS-REVIEWED] 623c73c

Verdict parsed from the review's SHA-scoped output markers for commit 623c73c18c03071112784ebc59563b6121e62b12.

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

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 623c73c18c03071112784ebc59563b6121e62b12 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 623c73c

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 9, 2026 23:48

@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 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).

@bolichen97 bolichen97 closed this Nov 10, 2026
auto-merge was automatically disabled November 10, 2026 19:26

Pull request was closed

@bolichen97 bolichen97 reopened this Nov 10, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[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.

@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 10, 2026
@bolichen97 bolichen97 closed this Nov 11, 2026
@bolichen97 bolichen97 reopened this Nov 11, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Closed and reopened with no code change. Backend Tests shard 4 (Linux and Windows) failed on test/test_session_markdown.py::test_a_condition_one_opener_is_closed_as_the_parser_reads_it[long-s]. That is main's break, tracked in #34654: the run tested a merge on main d4f82fbaf6, whose setup.cfg still allowed markdown-it-py 4.3.0. #34646 capped it below 4.3 and merged after that. This PR's merge ref now sits on f4d64c6da8, which carries the cap, so the re-run tests a tree with the fix. Nothing was pushed, so the approval stands. Auto-merge is armed once this re-run is green.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 11, 2026
@KiroCrewCaptain
KiroCrewCaptain merged commit 77ac559 into main Nov 11, 2026
284 of 297 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/32686-app-admission-bom branch November 11, 2026 09:52

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.md paragraph conflicts textually with open #34390. Whichever PR lands second needs a manual rebase and should keep both added sentences. The code merges clean.

@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants