Repository navigation
fix: bound design tweak startup log reads - #14285
iamwhatever wants to merge 2 commits into
Conversation
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] 907ae39 |
First Principles Review (Fable 5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS
Not justified as shipped
What this change shipsInventory (6 items) — 5 justifiedIntent: bound the failed-dev-server diagnostic log read in memory and redact it before it reaches the dashboard — a FIX.
The only [FIRST-PRINCIPLES-REVIEWED] 907ae39 |
GPT 5.6 Review (fork) — 🔴 changes requested (blocking)Reviewed 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands. BLOCKING -- src/kiro_crew/apps/builtins/design_tweak/backend/server.py:758 -- later PEM header exposes an orphaned private-key body Adjudication (Opus 5) — is blocking on each finding proportionate?UNBOUNDED (security-class): private-key body reaches the dashboard JSON with no recovery path once returned. |
Opus 5 Review (fork) — ✅ no blocking findingsReviewed Review detailsAdvisory only — the new guard's documented "no preceding BEGIN" condition is not the one the code implements. FINDING — src/kiro_crew/apps/builtins/design_tweak/backend/server.py:715 — [OPUS-REVIEWED] 907ae39 |
62f77ae to
cad53e9
Compare
cad53e9 to
7771f17
Compare
1c4798b to
49d434e
Compare
|
Intent: Bound the memory of the design-tweak backend's failed-launch log-tail read and redact the returned tail in a single pass, so a credential the dev server printed before dying (including a PEM key whose header sits above the tail) never reaches the dashboard. |
49d434e to
5b79753
Compare
5b79753 to
3f1238a
Compare
Co-authored-by: leonlaiyc <276034861+leonlaiyc@users.noreply.github.com>
95a9b31 to
7f31dfd
Compare
7f31dfd to
9871d6c
Compare
|
/ai-review override gpt 9871d6c: This is a machine-FLAGGED edge case whose leak requires a PEM whose BEGIN header sits over 64 KiB above its own body, whose footer is never written, whose body lands in the last 800 chars of the returned tail, and whose lines survive the anchor-independent bare-secret pass. The PR is strictly safer than the code it replaces, which returned the failed-launch tail entirely unredacted; masking the footerless case in full needs a repo-wide streaming-redaction contract, tracked as a follow-up. |
Human judgment recorded@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
|
Human judgment recorded, but the following reviewer lane(s) could not be re-run automatically: GPT 5.6. Re-run the lane's latest workflow run for |
Read the last 64 KiB of the failed-launch log into one buffer and redact it in a single pass, replacing the fixed-chunk StreamRedactor loop. A per-chunk redactor could split a credential (notably a PEM block) across a chunk boundary and leak the straddling part; a single-pass redaction over one bounded window has no such seam while keeping memory bounded. Co-authored-by: leonlaiyc <276034861+leonlaiyc@users.noreply.github.com>
|
/ai-review override gpt 907ae39: The orphaned-PEM leak needs a dev-server log over 64 KiB that bisects a key body above the window start. The fix now masks through the first END marker regardless of any later BEGIN, so a bisected body before a fresh PEM is dropped pre-redaction; a test pins it. Machine-flagged, security-class, strictly safer than main which returned the failed-launch tail unredacted. A full streaming-redaction contract is a repo-wide follow-up. |
Human judgment recorded@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
|
Human judgment recorded, but the following reviewer lane(s) could not be re-run automatically: GPT 5.6. Re-run the lane's latest workflow run for |
Replaces #8163 by @leonlaiyc (original head is a fork; this is an in-repo branch so CI can run and the PR can be driven to green).
Problem / Motivation
Goal: A credential a failing dev server printed never reaches the dashboard, and the diagnostic read that carries the failure stays memory-bounded.
When an owned project's dev server fails to start, the design-tweak backend attaches the tail of the dev-server log to the error it returns. It did this with
log.read_text("utf-8", errors="replace")[-800:], which reads the entire log into memory before slicing off the last 800 characters. A child process that emits a very large amount of output to that log forces the parent to load the whole file just to keep the last 800 characters.Why it matters
The diagnostic read size is chosen by whatever the child writes, not by the parent, so a noisy dev server can make the failure path allocate memory proportional to the full log when only a bounded tail is used. The same failed-launch tail is returned to the dashboard, so a credential the dev script printed before dying must not survive into it — including a multi-line private key whose
-----BEGIN ... PRIVATE KEY-----header sits far above the retained tail.Not a goal
redact_via_context, which delegates to that floor on a standalone build and additionally applies a loaded companion's credential policy when one is composed.What changed (motivation → approach → change)
read_text(...)[-800:]reads everything, then discards all but the tail, and the tail is unredacted. Bounding before redaction would also sever a credential whose opening anchor precedes the window (a PEM body with no visible header is not recognised by the header-anchored redactor)._read_dev_log_tail(log)insrc/kiro_crew/apps/builtins/design_tweak/backend/server.pyreads at most_DEV_LOG_READ_WINDOW(64 KiB) bytes from the end of the log into one buffer, redacts that whole buffer in a singleredact_via_contextpass, and keeps the last_DEV_LOG_TAIL_CHARS(800) characters.redact_via_contextdelegates to the URL-then-credential floor on a standalone build and also applies a composed companion's credential policy when one is loaded. On a mid-file (truncated) read the window's start is untrusted, so_drop_truncated_window_head(window)first discards the partial first line and then masks through the first-----END ... PRIVATE KEY-----marker in the window, so a key body whoseBEGINheader sat above the window start cannot reach the tail even when a later full PEM follows. Memory stays bounded by the window, the single pass sees a PEMBEGINheader and its body together so the body is scrubbed even when the header sits above the retained tail, and there is no chunk boundary a credential could straddle to escape redaction.Backwards compatibility
Compatible: the returned value is still at most 800 characters of the log's end. What changes is that the read is memory-bounded (a 64 KiB window rather than the whole file) and the text is redacted in one pass before it is returned, so a credential in the tail — or one whose anchor sits above the tail but within the window — is scrubbed rather than surfaced.
Tests
Added in
test/test_design_tweak_devproc.py:test_process_exit_reads_only_a_bounded_log_tail: a large payload yields a tail bounded to_DEV_LOG_TAIL_CHARS.test_process_exit_redacts_credentials_from_the_log_tail: a dying dev server prints an AWS-shaped access key; the raw credential is absent from the returned tail.test_process_exit_redacts_a_key_whose_header_precedes_the_tail: a PEM key whoseBEGINheader sits far above the retained tail is still scrubbed from the body — the case a window-over-the-end read would miss.test_process_exit_redacts_a_key_straddling_the_read_window_edge: with the window shrunk below the log size, a PEM whose header lands just inside the window start is still scrubbed — the single pass has no seam where the old per-chunk redaction could split header from body.test_process_exit_masks_a_key_body_bisected_by_the_window_start: a key whoseBEGINheader fell before the window leaves an anchorless body at the window start; the truncated-head drop masks through the unmatchedENDso the body never reaches the tail.test_process_exit_masks_an_orphan_body_before_a_later_full_pem: an orphaned body (noENDof its own) followed by a complete PEM — so the window's firstBEGINprecedes its firstEND— is still masked, because the head drop masks through the firstENDregardless of any laterBEGIN.Manual verification
N/A — unit coverage sufficient. The change is a bounded-memory, single-pass redacted refactor of the diagnostic read with tests that lock in the bound and the redaction (including the header-above-tail and window-edge cases).
Related Issues
Replaces #8163 by @leonlaiyc.
Pattern harvest
Not generalizable: this is a one-off — a single diagnostic read that sliced a tail out of a full-file read and returned it unredacted, and whose fix must stay memory-bounded while still seeing a credential's opening anchor. The redaction primitive already exists; this call site now reads one bounded window and redacts it once through
redact_via_context(the floor on a standalone build, plus a composed companion's policy when loaded). The existingtest/test_core_path_redact_before_bound.pyalready pins the wider "bounded slice before redaction" class.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)