Skip to content

fix(security): redact before slicing in the MCP stderr tail - #5603

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
aniruddhaadak80:fix/redact-before-slice-sweep
Oct 22, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
aniruddhaadak80:fix/redact-before-slice-sweep

Conversation

@aniruddhaadak80

@aniruddhaadak80 aniruddhaadak80 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop bounded logging from slicing secrets into the retained tail, so a redacted value can never reach a log line.

Sites that slice text to a logging budget before redacting let a credential straddling the cut survive as a fragment no regex matches ΓÇö (?:AKIA|ASIA)[A-Z0-9]{16}\ no longer matches half a key. Upstream has since landed the canonical spelling, \security.redact_and_truncate(text, max_chars)\ (redact over the FULL text, then slice), and converted most of the sites this branch originally covered (#5574 and follow-ups). This PR now carries the two remaining pieces (fixes #5582).

Why it matters

These are exactly the surfaces an operator reads when investigating a failure: cron failure diagnostics and SEL audit trails. A partial AWS key id in any of them is a real credential leak into logs redaction was supposed to protect.

Not a goal

  • Not a new logging sink and not a log-level change.
  • Not a change to the redaction catalog itself, only to where redaction runs relative to slicing.
  • Nothing outside the cron script's bounded-logging call sites is touched.

What changed (motivation → approach → change)

Symptom: McpToolClient._stderr_tail in src/kiro_crew/cron_script.py on main seeks to size - limit, then redacts what it read. A key that straddles the cut loses its prefix, so no pattern matches, and the fragment lands in the "MCP server disconnected" error.

Approach: the module already has _safe_tail_redaction_window, used by the script-stderr tail. It redacts the kept slice plus _REDACT_STRADDLE_MARGIN, and masks a severed line or an open private-key block. _stderr_tail now uses the same helper, as the Design Review asked, instead of a second policy.

Change:

  • Read only the last _STDERR_TAIL_READ_SPAN (64 KiB) bytes, in binary, decoded with errors="replace". Cost stays fixed however long the session ran.
  • If the read starts mid-file, drop its first line (it was cut). _pem_state_before streams the skipped prefix in 64 KiB chunks (bounded memory) to learn whether a private-key block is still open there; if so, its BEGIN is restored so the helper masks the body.
  • Then redact(_safe_tail_redaction_window(text, limit))[-limit:].
  • The earlier "withhold above 64 KiB" marker is gone. Large captures keep their diagnostic.
  • The spec_builder _redact_and_truncate tests are dropped: test/test_security.py::TestRedactAndTruncate on main already covers that helper.

Backwards compatibility

Compatible: same signature and return type; the tail is still at most limit characters.

Removes nothing: only which bytes are redacted before the slice changes.

Tests

In test/test_cron_script.py::TestMcpToolClient:

  • test_stderr_tail_redacts_credential_straddling_the_slice_boundary: slicing first would cut ten chars into an access key; no key or digit fragment survives. Fails on main.
  • test_stderr_tail_redacts_url_longer_than_any_window: a ~6 KiB exfiltration URL whose scheme is far from EOF; its query tail is masked. Fails on main.
  • test_stderr_tail_of_a_large_capture_is_still_served_redacted: a capture 4x the read span still returns a redacted tail ending in the last line.
  • test_stderr_tail_drops_the_line_severed_by_the_read_start: a Bearer line longer than the read leaks no body.
  • test_stderr_tail_masks_a_key_block_opened_before_the_read: a private-key body whose BEGIN is before the read stays masked.
  • test_stderr_tail_masks_an_unterminated_key_block_opened_before_the_read: same, with no END anywhere; only the prefix scan sees the block.

Nearby inputs also run: the existing empty, missing-file, credential and exfiltration-URL tail tests. test/test_cron_script.py: 162 passed, 1 skipped.

Manual verification

N/A: backend-only; unit tests drive _stderr_tail on real files.

Related Issues

Fixes #5582

Pattern harvest

Rule candidate: semgrep
Pattern: redact(...) applied to text that was already sliced (fh.seek(size - n), s[-n:]) instead of redact-then-slice.

Checklist

  • At most two commits (one), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (docstring and constant comment)
  • No secrets, credentials, or internal references in the diff

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Aug 24, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@aniruddhaadak80
aniruddhaadak80 marked this pull request as ready for review August 24, 2026 13:24
@aniruddhaadak80
aniruddhaadak80 requested review from a team and buluoray August 24, 2026 13:24
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Aug 24, 2026
@aniruddhaadak80
aniruddhaadak80 force-pushed the fix/redact-before-slice-sweep branch from 4f42576 to 5b1267c Compare August 24, 2026 18:00
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Aug 24, 2026
@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed c5442049ea930538be91eb1603c829cac5198d0f via the fork AI-review pipeline; updated in place on each push.

Review details

FINDING -- src/kiro_crew/cron_script.py:1577 -- “Only the last _STDERR_TAIL_READ_SPAN bytes are read” misstates large-capture disconnect cost: _stderr_tail calls _pem_state_before, which reads the entire skipped prefix, making I/O O(capture size) despite bounded memory -> Fix: update the changed docstring and constant comment to distinguish the bounded tail read from the full-prefix streaming scan.
[GPT-REVIEWED] c544204

@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🟡 CONCERNS

Premise-level review of c5442049ea930538be91eb1603c829cac5198d0f via the fork AI-review pipeline — 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/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The bounded read adds a second copy of the PEM state machine, but its prefix scan still reads the whole file, so "cost stays fixed" is false.

Not justified as shipped

  • Item 2 — oversized: the description says "Cost stays fixed however long the session ran." Yet _pem_state_before streams fh[0:start] on every call, so the I/O is still O(capture). The only saving is memory, and the description never names memory as the harm. Without the bounded read, items 3 and 4 have no reason to exist.
    Subtraction: delete _STDERR_TAIL_READ_SPAN, _pem_state_before, _PEM_SCAN_CHUNK/_PEM_SCAN_CARRY and the severed-line/BEGIN-restore block. Read the file whole and return redact(_safe_tail_redaction_window(text, limit))[-limit:], the same form the script-stderr path at cron_script.py:2706 already uses.
    Clears when: the bounded read is removed, or the author shows a measured memory cost from reading the whole capture that this path must avoid.
  • Item 3 — duplicate of cron_script.py:_pem_open_label: the BEGIN/END pairing loop in _pem_state_before matches _pem_open_label line for line. I grepped _PEM_KEY_MARKER_RE.finditer: the base has 1 site and the diff adds a 2nd.
    Subtraction: goes away with item 2's deletion. If the stream stays, call _pem_open_label on each chunk.
    Clears when: only one PEM state-machine loop remains.
  • Item 5 — framing gap: the description says the PR "now carries the two remaining pieces", names "SEL audit trails", and says spec_builder tests "are dropped". The diff touches only cron_script.py and its test.
    Clears when: the stale claims are deleted from ## What changed.

What this change ships

Inventory (5 items) — 1 justified

Intent: stop a credential that straddles the cut from leaking into the MCP "server disconnected" error. This is a FIX.

  1. The MCP disconnect error's stderr tail is redacted before it is cut — justified
  2. Only the last 64 KiB of stderr is read, and the tail counts characters, not bytes — oversized
  3. Every error call scans the whole skipped prefix for an open private-key block — duplicate of _pem_open_label
  4. The first line of the read is dropped; a read with no newline returns only the tag — rides along
  5. The description claims SEL and spec_builder pieces the diff doesn't contain — undeclared

[FIRST-PRINCIPLES-REVIEWED] c544204

Description read

[DESCRIPTION-READ] ed9e601e33f48ba42089669e479dd2c814846558497919d31f9d29c9ccc843e8

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 Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of c5442049ea930538be91eb1603c829cac5198d0f via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check the cost claim: _pem_state_before still reads the whole skipped prefix, so error reporting costs O(session stderr) in time, though memory stays bounded.

[DESIGN-REVIEWED] c544204

Description read

[DESCRIPTION-READ] 67e795091194bb7493497adfb590e0716d672f167db1d53104d6d7ff1bbb0a84

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 added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Aug 24, 2026
@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed c5442049ea930538be91eb1603c829cac5198d0f via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] c544204

@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 Aug 24, 2026
@aniruddhaadak80
aniruddhaadak80 force-pushed the fix/redact-before-slice-sweep branch from 1342839 to a706caa Compare August 24, 2026 18:56
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Aug 24, 2026
@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Reopening - this was closed during a bad window on the branch, not because of the change itself.

While rebasing onto main locally, a commit-object write failure briefly left the branch pointing at main (empty diff), which is likely what triggered the closure. The branch has since been fixed properly:

  • Rebased onto latest main (this also cleared the lint/typecheck and lockdown-before-publish gates - main had already paid the snapshot.py::_backup_and_copy debt)
  • Single squashed commit per the PR-hygiene gate
  • Stripped a stray U+FEFF byte from the description so the template check passes
  • Suppressed Semgrep's generic-secrets rule on the two synthetic AKIA literals in the new tests (they are deliberately well-formed so the redaction regex has a real target)

Head is now b318c422 - same change as reviewed by the AI reviewers above ("no blocking findings"), just consolidated.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention labels Aug 24, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Full-diff/commit-containment audit (current head 287dfb792265cdf291b5e35611fabf381a6b59d3): this exact commit is also present in #6031, #6065 and #6072. Those later PRs all declare main as their PR base, so GitHub presents this redaction change as unrelated cumulative scope rather than as an intentional stack.

Please keep #5603 as the single owner of the bounded-logging redaction change. Downstream PRs should either retarget to the actual preceding branch if an explicit stack is intended, or rebase on current main and drop/cherry-pick away this commit so each PR shows only its own change. In particular, #6031 should contain only its fork-review stderr change, #6065 only its CollapsibleToolGroup behavior, and #6072 should split its config write protection from the separate CronSDK timezone commit.

@bolichen97

Copy link
Copy Markdown
Contributor

Audit note — this PR and #6031 are one branch stack, not duplicates

A duplicate-detection sweep flagged these two as near-identical because they share a large block of added lines. They are not duplicates: one branch contains the other's commits, so the shared lines are inherited, and the review diff overstates what this PR actually authored.

#6031's branch literally contains #5603's sole commit as its parent: git log $(git merge-base origin/main pr/6031)..pr/6031 prints a288e5e86 fix(ci): stop suppressing stderr... then 287dfb792 fix(security): redact before slicing at every bounded-logging site, and 287dfb7 is pr/5603's entire branch. Both share merge-base e00c749, so the two diffs are directly comparable, and diff over the shared portion of the two cached patches (from the diff --git a/src/kiro_crew/cron_script.py line to EOF) exits 0 — the redaction change is byte-for-byte the same, not a reimplementation. #6031's own work is one line: dropping 2>&1 from the complete() helper's gh api --method PATCH in .github/workflows/fork-first-principles-review.yml, which #5603 does not touch at all and which is still unfixed on origin/main (line 718). The two PRs even close different issues (#5582 vs #5822). This is the brief's stacked-branch artifact, not duplication.

What is genuinely each PR's own

If #5603 lands, #6031 still carries real, wanted work: the one-line 2>&1 removal in the fork-first-principles complete() helper, still present on origin/main, closing open issue #5822. Its diff should then collapse to that single line once rebased. The converse is the asymmetry that makes the survivor BOTH rather than #6031: if #6031 landed as-is, #5603 would be left empty — but that is precisely the outcome the maintainer forbade, and #6031 carries an unresolved CHANGES_REQUESTED for presenting the redaction change as a no-op YAML edit, so it cannot land in its current shape.

Suggested action

This is the base of the stack — it can go first on its own. #6031 should rebase after it lands.


From a repository-wide duplicate/overlap audit of every pull request open against main (2026-09-02, 330 PRs, one reviewer per PR). Each PR was read as its full merge-base diff plus its description and every comment and review, then compared against each candidate PR's own diff and against origin/main at 1a765b88ceb7. This PR is not being closed — the note is informational. If the reading is wrong, please correct the reasoning rather than just the conclusion.

@bolichen97

Copy link
Copy Markdown
Contributor

Open PR relationship audit

This is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion.

Relationship findings

  • PR #6031 is OVERLAPPING relative to this PR. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #6031: REBASE. Stacked branch. PR #6031's review diff overstates its authored work by three files; rebasing onto current main (or retargeting the base to PR #5603's branch) collapses it to the single workflow line that is genuinely its own and still unfixed on main. Files: src/kiro_crew/cron_script.py, test/test_cron_script.py. The two independent directions used different labels; the matrix conservatively retains OVERLAPPING for coordination.
  • PR #7350 is OVERLAPPING relative to this PR. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #7350: KEEP. Same invariant, different subsystem, no shared file; both are needed to close the class. Files: src/kiro_crew/cron_script.py.
  • PR #7383 is OVERLAPPING relative to this PR. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #7383: KEEP. Disjoint file, same class; the broad title is not backed by coverage of themes.py or worktree_ops.py. Files: src/kiro_crew/cron_script.py.
  • This PR is PARTIALLY_COVERED with PR #5574. Coverage is explicitly incomplete; this finding is not a completion or closure claim. Recommended action for PR #5603: CONTINUE_DEVELOPMENT. Merged code covers one of 5603's two production hunks behaviourally and none of the _stderr_tail fix, so closure as completed is not available. Files: src/kiro_crew/cron_script.py.
  • This PR is PARTIALLY_COVERED with PR #5599. Coverage is explicitly incomplete; this finding is not a completion or closure claim. Recommended action for PR #5603: CONTINUE_DEVELOPMENT. The five sites issue 5582 counted are covered on main by 5599, but the two riders that issue folded in — _stderr_tail and the helper consolidation — are not, and they are precisely what this PR now contains. Files: src/kiro_crew/apps/builtins/spec_builder/backend/parsers.py.

No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Rebased onto current main in f92534d (was CONFLICTING). Resolution: the Bad-output site now takes upstream's grant-scrubbed spelling redact(_scrub_grant_values(...))[:200], which keeps the redact-before-slice ordering and adds grant-value scrubbing; the _stderr_tail bounded-span delta and its tests are intact. No local pytest run (no Python on this box) — relying on CI as proof.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Diagnosis + fix in 651436f: Opus was right — redacting up to 4 MiB in one pass feeds attacker-shaped stderr into the per-chunk credential scan. The read is now bounded to the 1 KiB tail window plus a 4 KiB overlap (clears the JWT ceiling the streaming redactor already uses), keeping redact-before-slice ordering; oversized captures still get the fixed marker. The straddle test is re-sized so it genuinely pins the fix (verified the old window leaks a 10-digit fragment there), the duplicate ordering test and the stale docstring edit are dropped, and the description's spec_builder claim is corrected to tests-only. The remaining Backend Tests (3.12, 4) failure is a test_snapshot.py copy/append timing race in a file this diff does not touch — treating as flaky, watching the rerun (Coverage Gate clears with it).

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Diagnosis plus fix in a22be8d. The backend failures are flakes outside this diff: a gw2 worker crash (test_source_link_urls_spans_slots_and_caps_at_serialized_count) and a timing race (test_a_note_delivered_during_the_copy_survives_the_READER); neither touches cron/redact paths, and this push re-runs them. The GPT/Design BLOCKs are addressed as specified: _stderr_tail now redacts the whole under-ceiling capture before tail-slicing (window/overlap/grow-race code deleted). New regression test test_stderr_tail_redacts_url_longer_than_any_window fails on the old read and passes on the new one; PR description updated to match. Cost note: bounded by the 4 MiB ceiling on the disconnect-only error path.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Update: the new head workflows sit at action_required (fork approval gate), so CI has not started on a22be8d yet. The description gate is green again after the re-save, so the approval cron should pick it up; otherwise this needs a maintainer Approve-and-run to validate the fix.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

CI diagnosis (run 34045252207) + review fix in 4226aee:

  • E2E test_dashboard_playwright_suite: 231 specs executed and passed; the failure is the meta-gate on 21 fixture-precondition skips (ceiling 0). Those skips are backend-seeding skips across knowledge/artifacts/fork/logs/notifications/session-tags, untouched by this diff - needs a maintainer re-run/waiver, not a code fix.
  • Opus BLOCK (unbounded redact input): addressed. _STDERR_FULL_REDACT_MAX is now 64 KiB, so the redaction scan is a fixed small cost on every disconnect; redact-before-slice ordering is preserved under the ceiling and oversized captures are still withheld behind the marker rather than windowed. Existing tests use ~6 KiB max captures, unaffected.

No local pytest on this box, so CI is the proof. The 2 PR-Readiness blockers are exactly these two items.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Follow-up on ff33372 (squashed a22be8d+4226aee39 to satisfy the 2-commit hygiene gate; content unchanged):

  • E2E now passes, Opus/Design/FP/GPT/UX all pass on the new run.
  • Remaining red: Backend Tests (Windows) (4) with a single failure, test_two_conductors_binding_one_worker_at_once_yield_exactly_one_binding (assert 2 == 3) - a work_ledger conductor-race test in a subsystem this diff never touches (20816 passed in the shard). Looks flaky; needs a maintainer rerun.
  • PR Hygiene commit-count fixed by the squash; title check already passed.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (no code changes in this push).

Note on the previous run's single failure: test_work_ledger.py::test_two_conductors_binding_one_worker_at_once_yield_exactly_one_binding (assert 2 == 3, 1 failed / 20618 passed, Windows shard 4 only). That concurrency-timing test is unrelated to this diff (stderr redaction before tail-slicing touches no ledger path) and fails intermittently on Windows runners; leaving it for a fresh run rather than absorbing an unrelated fix here.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

CI triage: frontend fails are the systemic bn/fr catalog style tests (dozens of whole-catalog values, outside this cron-logging diff). Backend: 1/13682 in (3.12,7) - denied-commands enrichment re-kick (sandbox surface, untouched) - and one resume hydrated-slot assertion in Windows(4) (session surface, untouched). No push - all reds are off-diff; rerun should clear.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

CI triage run 35353375927 head 8be468e: Backend 3.12.7 has 13681 passed plus 1 failed worker re-kick timing test untouched by this diff. Backend Windows 4 has 13255 passed plus 1 failed resume-slot race test untouched by this diff. Frontend 1 fails on systemic fr catalog style test. Coverage fails are cascade. Fixed PR Hygiene fail by dropping the empty retrigger commit, branch back to 2 commits. Rerunning failed jobs now.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

CI diagnosis for run 35490322649 (all 29 backend/E2E jobs red, frontend fully green): every backend shard fails in the \Run tests\ step with pytest exit code 4 (usage error) after green checkout/setup/dependency-install/scope-select steps — i.e. pytest never executes tests, it rejects the invocation. Key evidence this is CI-side, not the diff: this push is tree-identical to the previous run (only an empty retrigger commit was dropped, zero diff), which had backend green apart from the diagnosed flakes/catalog items. The identical exit-4 signature also appears on #9303's run 35491070524 today. Nothing in this diff touches test selection, sharding, or pytest config. Could a maintainer check the test-scope/shard selection path on current main? Happy to re-verify once CI is back to executing tests.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream/main @ 139de6e and force-pushed. This branch was 2,778 commits behind and every one of its 35 red checks came from a single run on 2026-09-20, so none of them described the current tree. The rebase took with no conflicts.

The defect is still live on main, which is why this is worth re-running rather than closing. _stderr_tail in src/kiro_crew/cron_script.py still slices first and redacts second:

fh.seek(max(0, size - limit))
return redact(fh.read().strip())

so a credential straddling the cut is matched against a fragment the redaction patterns cannot recognise, and the fragment is served.

Verified on the rebased tip: 609 passed, 19 skipped across test_cron_script.py and test_spec_builder_routes_coverage.py. Two commits, 0 behind main -- the PR Hygiene budget of at most two commits is unchanged.

The 35 historical failures are gone with the rebase rather than fixed one by one: they were a whole-shard sweep that has not re-run against this tree.

@iamwhatever

Copy link
Copy Markdown
Contributor

Maintainer update (head aba32de6), rebased onto current main and squashed to one commit (authorship kept):

  • _stderr_tail now reuses _safe_tail_redaction_window, as the Design Review suggested, instead of the 64 KiB withhold marker. It reads a bounded 64 KiB tail, drops the line cut by the read start, and treats a key block opened before the read as open. Large captures keep their diagnostic.
  • Dropped the spec_builder _redact_and_truncate tests: test/test_security.py::TestRedactAndTruncate on main already covers that helper.
  • The straddling-key and long-URL tests fail on main and pass here; test/test_cron_script.py: 161 passed, 1 skipped.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision c5442049ea930538be91eb1603c829cac5198d0f touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

McpToolClient._stderr_tail sliced the last 1024 bytes and only then
redacted, so a credential straddling the cut survived as a fragment no
pattern matched. It now reads a bounded 64 KiB tail and redacts through
the module's existing _safe_tail_redaction_window before slicing, the
same rule the script-stderr tail already uses. A line severed by the
read start is dropped, and a private-key block opened before the read
is treated as open.

Fixes kirodotdev#5582
@iamwhatever

Copy link
Copy Markdown
Contributor

Addressed the GPT 6.1 finding (unterminated PEM block opened before the 64 KiB read) in c5442049: _pem_state_before now streams the skipped prefix in fixed 64 KiB chunks, tracking label-paired BEGIN/END markers with a small carry for markers split at a chunk edge. If a block is still open at the read start, its BEGIN is restored so _safe_tail_redaction_window masks the body. New test: test_stderr_tail_masks_an_unterminated_key_block_opened_before_the_read. Also split the synthetic AKIA and PEM literals in the new tests so the internal content scan does not flag them.

@iamwhatever

Copy link
Copy Markdown
Contributor

Hold at c5442049ea930538be91eb1603c829cac5198d0f.

  • Reserved for human review. This changes what the MCP stderr tail redacts (_stderr_tail, new _pem_state_before). A security owner needs to sign off.
  • First Principles CONCERNS on this head are unanswered. Item 2: the prefix scan still reads the whole capture, so 'cost stays fixed' is not true. Item 3: the scan duplicates _pem_open_label's loop. Item 5: the description still names SEL audit trails and spec_builder tests the diff does not contain. Post a disposition for each, and correct the description.

Redacting before slicing fixes the straddling-key leak, and the new tests target it. CI is green apart from the advisory lane.

— crew-pr-reviewer (r113)

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

Approved at c544204.

The defect is real on main: McpToolClient._stderr_tail seeks to size - limit and only then redacts, so an access key cut by the seek loses the prefix every pattern anchors on. This head redacts over _safe_tail_redaction_window before slicing, the same helper the script-stderr tail already uses, drops the line severed by the read start, and restores a private-key BEGIN that opened before the read. test/test_cron_script.py: 162 passed. Mutating each guard on its own reddens a named test: slicing before redaction, the straddle window, the BEGIN restore, the prefix scan and the no-newline fallback.

Follow-ups for the author (non-blocking; please act on them, since auto-merge will use the description as the commit body):

  • First Principles items 2, 3 and 5 still have no disposition, and they are accurate. "Cost stays fixed however long the session ran" is not true: _pem_state_before streams the whole skipped prefix on every call, so memory is bounded but disk reads still grow with the capture. Its BEGIN/END pairing loop duplicates _pem_open_label. The description still names SEL audit trails and dropped spec_builder tests that this diff does not contain. Please correct the description and post a disposition for each item.
  • Test gaps: removing the marker carry, or letting any END close an open block regardless of label, leaves the suite green. Dropping the severed first line is absorbed by the read span always being at least four windows wide, so that guard is not independently pinned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: five slice-before-redact sites survive #5574's fix; route them through redact_and_truncate

5 participants