Repository navigation
fix(security): read snapshots and spec prefixes through the descriptor gate - #11227
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify no supported workflow feeds legitimately hardlinked specs to [DESIGN-REVIEWED] c1e0dc4 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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: |
Opus 4.8 Review — ✅ no blocking findingsReviewed Review detailsI've independently verified the two implementation changes against the descriptor gate they call and the byte-cap/decode logic.
Nothing survives to a grounded (a)/(b)/(c) defect. No findings. [OPUS-REVIEWED] c1e0dc4 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The PR's own harvest rule still matches four ungated validate-then-reopen reads it never names — one, skills.py lazy load, publishes bytes into the turn. Not justified as shipped
What this change shipsInventory (7 items) — 5 justifiedIntent: stop a hardlink alias of a protected file, planted under an innocent name, from leaking bytes into dashboard diff chips or a task's
[FIRST-PRINCIPLES-REVIEWED] c1e0dc4 |
60b4999 to
959ed72
Compare
959ed72 to
55a5cfa
Compare
…r gate Two reads validated a path with hooks.validate_file_path and then re-opened it by NAME: chat_runner._safe_read_snapshot (Path.read_text feeding the dashboard diff chips) and taskrunner._read_spec_prefix (a bare open() for the placeholder's spec prefix). A hardlink alias shares its target's inode under an innocent name, so every name-based check passes while the bytes belong to whatever it aliases; only the opened descriptor's st_nlink reveals it. Both now read through hooks.safe_read_file_bytes_nolink with each canonical path's own parent as within_root, the same gate the prompt and skill readers use. Failure shapes are unchanged: None for the snapshot, an empty prefix for the spec. Closes #8429
…cut it A spec that ENDS mid code point is malformed; holding its tail back turned the read error the caller maps to "" into a silently shorter prefix. The decode is now finalized for any result shorter than the byte cap, and the tail is held back only for a full-length result, the one case the cap itself may have cut, where every complete character before the cut already lies past max_chars. The gate import moves to the module import section.
55a5cfa to
c1e0dc4
Compare
…r gate (kirodotdev#11227) * fix(security): read snapshots and spec prefixes through the descriptor gate Two reads validated a path with hooks.validate_file_path and then re-opened it by NAME: chat_runner._safe_read_snapshot (Path.read_text feeding the dashboard diff chips) and taskrunner._read_spec_prefix (a bare open() for the placeholder's spec prefix). A hardlink alias shares its target's inode under an innocent name, so every name-based check passes while the bytes belong to whatever it aliases; only the opened descriptor's st_nlink reveals it. Both now read through hooks.safe_read_file_bytes_nolink with each canonical path's own parent as within_root, the same gate the prompt and skill readers use. Failure shapes are unchanged: None for the snapshot, an empty prefix for the spec. Closes kirodotdev#8429 * fix(taskrunner): finalize the spec-prefix decode unless the byte cap cut it A spec that ENDS mid code point is malformed; holding its tail back turned the read error the caller maps to "" into a silently shorter prefix. The decode is now finalized for any result shorter than the byte cap, and the tail is held back only for a full-length result, the one case the cap itself may have cut, where every complete character before the cut already lies past max_chars. The gate import moves to the module import section.
What
Two reads validated a file path and then re-opened it by name. Both now read through
hooks.safe_read_file_bytes_nolink, the descriptor gate the prompt and skill readers already use, with each canonical path's own parent aswithin_root.src/kiro_crew/dashboard/chat_runner.py::_safe_read_snapshotvalidate_file_paththenPath.read_textmax_bytes=4 * _MAX_SNAPSHOT + 4,allow_truncate=True,utf-8decode witherrors="replace", universal newlinessrc/kiro_crew/taskrunner.py::_read_spec_prefixopen()on the validated namemax_bytes=4 * max_chars,allow_truncate=True, strict decode (tail held back only on a byte-cap cut), universal newlines,[:max_chars].strip()Closes #8429
Why
validate_file_pathjudges the name. A hardlink alias shares its target's inode but carries its own innocent name:realpathyields the alias,is_symlink()is False,is_sensitive_pathsees an ordinary file, and the bytes belong to whatever it aliases.st_nlinkis the only signal and it is readable only on an open descriptor. The snapshot bytes are published into the dashboard diff chips; the spec prefix lands in the placeholder run'sspec_content. This is the same class #8249 closed for the prompt/skill reads; these two sites were deliberately deferred out of that PR's scope.How
platform_compat.open_file_no_reparse, refusing a link at the final component on every platform),fstats that one descriptor, refusesst_nlink > 1, a non-regular inode, and a sensitive or out-of-within_rootreal path, then reads the same descriptor.within_root=os.path.dirname(validated)is what carries the guarantee onto Windows, whereO_NOFOLLOWdoes not exist._safe_read_snapshotreturnsNonefor every refusal exactly as it did for an unreadable file;_read_spec_prefixreturns""for a refusal, which is what its caller already substitutes for any read error (except Exception: early_content = ""). Invalid UTF-8 in a spec still raises (strict decode, as the text-mode read did) and the caller still maps it to"".4 * max_charsalways yields at leastmax_charscharacters, and4 * _MAX_SNAPSHOT + 4guarantees a file longer than the character cap decodes to MORE than_MAX_SNAPSHOTcharacters whether it was cut at the byte cap or read whole, so_truncate_snapshot's marker is appended exactly when the file exceeds the cap (pinned bytest_truncates_a_large_multibyte_file_with_the_marker). The taskrunner decode is strict to EOF (an incomplete sequence at the end of a short file raises, as any malformed UTF-8 did in the text-mode read, and the caller maps it to""); only a full-length result — the one case the byte cap itself may have cut mid code point — holds the dangling tail back withfinal=False, which loses nothing because every complete character before a cut at4 * max_charsbytes already lies at or past indexmax_chars; newlines are normalized (\r\n,\r->\n) as the replaced text-mode read did.\r\n/\rto\n, as the text-mode reads they replace did. For the snapshot this is load-bearing: the strReplace "before" comes fromhooks.safe_read_file(text mode), so a CRLF "after" that kept its\rwould render every unchanged line as modified in the diff chip (pinned bytest_normalizes_newlines_like_the_text_mode_read_it_replacesin both test files).chat_runner.pydrops the by-namePath.is_file()pre-check; the gate'sS_ISREGon the descriptor is the authoritative check.docs/system-specs/modules/learn-cron-dashboard.md(file-change snapshot paragraph) anddocs/system-specs/modules/taskrunner.md(background admission) describe the gated reads.Tests
Repro admitted on the unmodified base (both hardlink-alias tests served the secret bytes; 7 failures total on base, all green after):
test/test_file_change_snapshots.py::TestSafeReadSnapshot— new:test_withholds_a_hardlink_alias_of_a_protected_file(HOME pinned totmp_path,~/.aws/credentialsplanted,is_sensitive_pathasserted as precondition, alias under an innocent name ->None),test_withholds_a_symlink_to_a_protected_file,test_reads_through_the_descriptor_gate_not_by_name(Path.read_textraises if called),test_normalizes_newlines_like_the_text_mode_read_it_replaces,test_truncates_a_large_multibyte_file_with_the_marker;test_reads_with_explicit_utf8_encoding(which pinned the by-namePath.read_textcall) replaced bytest_reads_utf8_regardless_of_locale.test/test_taskrunner_spec_prefix.py— new file: plain prefix, character (not byte) bound on multi-byte text, CRLF normalization, invalid UTF-8 still raises, an incomplete sequence at EOF still raises, a byte-cap cut mid code point is not an error, missing/directory/protected-name ->"", hardlink alias of a protected file ->"", symlink to a protected file ->"".-n0:test/test_taskrunner.py test/test_taskrunner_coverage.py test/test_handlers_taskrunner_coverage.py test/test_file_change_snapshots.py test/test_taskrunner_spec_prefix.py test/test_chat_runner_coverage.py-> 891 passed.check_subprocess_encoding.py,check_comment_history.py,docs_lint.py,check_lockdown_before_publish.pyall pass.Other
Backend-only (
no-screenshots): no UI change; the diff chips render the same content for every non-aliased file andNone(no chip content) for a refused one, as before.Not touched: the steering descriptor-gate refusal sites (sibling PR #11210 / #8430).
#8249's prompt/skill sites are unchanged.Minor behaviour differences, both deliberate: the snapshot read no longer pulls an arbitrarily large file into memory before truncating (bounded at
4 * _MAX_SNAPSHOT + 4bytes); the spec prefix read is bounded at4 * max_charsbytes instead of a text-moderead(max_chars).Pattern harvest
Rule candidate: grep
Pattern:
validate_file_path(followed within a few lines byopen(,.read_text(,.read_bytes(orPath(...)on the validated value is a validate-then-reopen-by-name read; route it throughsafe_read_file_bytes_nolinkwithwithin_root= the canonical path's parent.