Skip to content

fix(security): block dd output to raw disk devices without if= - #11347

Closed
aniruddhaadak80 wants to merge 1 commit into
kirodotdev:mainfrom
aniruddhaadak80:fix/dd-output-to-device
Closed

aniruddhaadak80 wants to merge 1 commit into
kirodotdev:mainfrom
aniruddhaadak80:fix/dd-output-to-device

Conversation

@aniruddhaadak80

@aniruddhaadak80 aniruddhaadak80 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review findings addressed (force-push 4233d8afe)

  • Security Scope Review — newly-refused search needle: the pattern is now anchored to the command position, ^(sudo\s+)?dd .*of=/dev/(...). Segments arrive stripped and quote-normalized views keep token order, so grep -rn "dd of=/dev/sda" test/ docs/ (raw and dequoted) starts with grep and stays allowed on every platform leg, while bash -c 'dd of=/dev/sda' still denies through the -c payload view. The exact review needle and a select-string spelling are pinned in ALLOWED.
  • GPT 5.6 Review — missing /dev/xvd: xvd joins the device set in both production allowlists (denied_rules.py, skills_script_validator.py) and the golden fixture, with dd of=/dev/xvda pinned in DENIED — the Xen spelling is the root device this repo's own EC2 template provisions (DeviceName: /dev/xvda).
  • The safety-gate constraint is respected: a first draft used a nested prefix-flag run (?:\s+\S+){0,3}, which is_safe_user_regex rejects (the matcher would disable the rule at runtime); the shipped form is the simpler ^(sudo\s+)? that the gate accepts, parity-tested by the existing matcher-shape suite.
  • Local verification: test_denied_commands_security.py + test_skill_script_validator.py + test_security_gate_liveness.py = 1337 passed, 1 skipped (golden parity, ReDoS gates, matcher shape, and the 27,862 budget all inside), black clean on every touched non-baseline file.

Rebase + line-budget re-pin (force-push 78e683253)

Rebased onto current upstream main (48b040c54) via plumbing only (merge-tree → temp index → commit-tree), so the PR merges cleanly against the current base. CI had flagged two real failures on the previous head:

  • Backend Tests (3.12, 2) / Backend Tests (Windows) (2): the security package's liveness ratchet pins the package total with zero headroom (_PACKAGE_LINE_BUDGET = 27_853, measured total on main). The rule's nine new lines in denied_rules.py pushed the merged total to 27,862 and tripped test_the_package_stays_within_its_line_budget. Following the ratchet's stated policy ("the next line added here … has to be re-pinned deliberately, with its reason written above"), _PACKAGE_LINE_BUDGET is re-pinned to the measured 27,862 with the reason documented in the comment block above the number — no headroom, and the per-file cap + facade-share guards stay untouched.
  • SAST (Semgrep): was cancelled mid-run on the prior head (runner shutdown), not a finding; it re-runs on this push.

Coverage Gate, GPT 5.6 Review and Security Scope Review on the old head were stale duplicate-name results superseded by newer passing runs, and PR Readiness was derived from those. An intermediate head (deb4e7905) tripped the Comment History Gate because the ratchet comment narrated its own change ("Raised … for PR #11347"); the comment now states what the budget covers in present tense, which is what that gate asks for.

Problem / Motivation

Goal: Stop dd from silently destroying raw disks and partitions when it is used without an explicit input file.

dd reads stdin by default, so the existing local-destructive-dd-if rule only denies when an if= operand is present. Spellings with only an of=/dev/... target destroy data while the catalog claimed dd coverage:

  • dd of=/dev/sda bs=1M
  • echo hi | dd of=/dev/sda
  • dd </dev/zero of=/dev/sda
  • sudo dd of=/dev/nvme0n1

All were allowed (verified via is_denied).

Why it matters

Destructive without explicit input — piping or stdin still overwrites raw disks/partitions irreversibly. Existing tests only pinned if=…of=… together, so the gap survived review unnoticed.

Not a goal

  • Not a broader rewrite of the denied-command catalog; this adds one rule and leaves the existing if= rule untouched.
  • Not a change to any other tool's deny coverage. Auditing other implicit-stdin tools is a follow-up, not part of this PR.
  • No change to how is_denied normalizes or segments a command; the existing _deny_segment_views / raw split already covers quoting and nesting.
  • No user-visible surface, so no UI or documentation restructuring beyond the security spec wording.

What changed (motivation → approach → change)

  • Root cause: the rule keyed on the input half (if=) instead of the destructive half (raw-disk of=).
  • Approach: add a second deny row keyed on of=/dev/<block-device> with a narrow device allowlist (sd/hd/vd/nvme/mmcblk/loop/dm-/md/dasd/disk/) so of=/dev/null and of=disk.img stay allowed.
  • Change:
    • src/kiro_crew/security/denied_rules.py — new local-destructive-dd-of-device (dd .*of=/dev/(sd|hd|vd|nvme|mmcblk|loop|dm-|md|dasd|disk/).*)
    • test/fixtures/denied_commands_golden.json — golden entry
    • test/test_denied_commands_security.py — bump 112→113 + new TestDdOutputToDeviceDenied (12 denied incl. sudo/quoted/nested, 5 allowed)
    • src/kiro_crew/skills_script_validator.py — same pattern in the skill gate
    • test/test_skill_script_validator.py — validator test
    • docs/system-specs/modules/security.md — destructive block wording
    • test/test_security_gate_liveness.py — _PACKAGE_LINE_BUDGET re-pinned 27,853 → 27,862 (the rule's measured nine lines), reason written above the number per the ratchet's policy
    • Normalized via the existing _deny_segment_views / raw split — no new view needed; covers quoting and nesting.

Backwards compatibility

Compatible: this is a pure addition to the deny catalog. No accepted spelling stops being accepted except the previously-permitted destructive dd of=/dev/<raw-device> forms, which are exactly the defect being fixed. of=/dev/null, of=disk.img, and every non-/dev/ target remain allowed, and the 5 benign-target tests pin that.

Tests

  • New unit: TestDdOutputToDeviceDenied::test_of_device_without_if_is_denied (12 cases including bash -c 'dd of=/dev/sda') and test_benign_of_targets_stay_allowed (5 cases)
  • test_rejects_dd_output_to_device in the skill validator
  • Existing suite: pytest test/test_denied_commands_security.py — 1020 passed, 1 skipped (full); test/test_skill_script_validator.py — 54 passed

Manual verification

Repro via is_denied before/after: the 4 bypasses above flip from allowed→denied; benign of=disk.img, of=/dev/null stay allowed. The liveness package total was measured from the rebased tree file-by-file (argv_floor.py 4132 + shell_normalizer.py 3802 + paths.py 3791 + __init__.py 3653 + denied_rules.py 3152 + …) and sums to exactly 27,862.

Screenshots / video

N/A — no UI.

Related Issues

N/A

Pattern harvest

Rule candidate: denied_rules — device-write without an input operand is a class (dd is the instance); the other implicit-stdin tools should be audited with narrow device sets.

Checklist

  • At most two commits (one is the norm), 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 (if applicable)
  • No secrets, credentials, or internal references in the diff

@aniruddhaadak80
aniruddhaadak80 requested review from a team and bolichen97 September 16, 2026 17:50
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 16, 2026
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 66b106fe585fd3e99fae52d623720f71f8013d0d 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 that the budget numbers in the description match the diff: it says 27,853 → 27,862, but the hunk re-pins _PACKAGE_LINE_BUDGET = 28_399 → 28_408.

[DESIGN-REVIEWED] 66b106f

Description read

[DESCRIPTION-READ] 27e5a75ff61e8429ff3c9d90e9fd5b82085b29d6779a175327f5eab633f8c33c

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 Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 66b106fe585fd3e99fae52d623720f71f8013d0d 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: PASS

The description says the budget was re-pinned 27,853 → 27,862, but the diff changes 28_399 → 28_408. Re-measure it on the current base before merge.

Not justified as shipped

  • Item 5 — undeclared, rides along: test_skill_script_validator.py reformats three unrelated tests (test_rejects_network_import_from_and_socket_alias, test_rejects_aliased_dangerous_attribute, test_benign_match_pattern_still_passes). The description never mentions this. No behaviour changes.

What this change ships

Inventory (5 items) — 4 justified

Intent: stop the agent from wiping a raw disk with dd when the command has no if= operand (dd reads stdin by default). This is a FIX.

  1. Shell gate now refuses dd … of=/dev/<raw disk>, including the sudo form, bash -c nesting and the xvd device prefix — justified
  2. Skill-script validator now rejects dd of=/dev/<raw disk> in a script body — justified
  3. Security spec's list of blocked destructive commands now names the dd of=/dev/… case — justified
  4. Security package line budget re-pinned +9 for the new rule — justified
  5. Three unrelated skill-validator tests reformatted — undeclared, rides along

[FIRST-PRINCIPLES-REVIEWED] 66b106f

Description read

[DESCRIPTION-READ] d0fd71933eec426cd72b66dfcc5270120147917fc5749e09d1e15524b00eb637

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 Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — 🔴 changes requested (blocking)

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

2 of 2 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

BLOCKING -- src/kiro_crew/security/denied_rules.py:1149 -- Executable paths and sudo options bypass the new disk-write guard

pattern="^(sudo\\s+)?dd .*of=/dev/(sd|xvd|hd|vd|nvme|mmcblk|loop|dm-|md|dasd|disk/).*",
With sandboxing off and passwordless sudo, sudo /bin/dd of=/dev/sda bs=1048576 count=1 </dev/zero → HookManager.on_tool_call → is_denied returns None → approval permits overwriting the disk’s partition metadata; sudo -n dd likewise bypasses.
Anchor: residual/security
Fix: Recognize dd by executable basename and parse sudo options before checking its of= operand, preserving the command-position restriction.

BLOCKING -- src/kiro_crew/security/denied_rules.py:1149 -- The device alternatives omit macOS block and raw disks

pattern="^(sudo\\s+)?dd .*of=/dev/(sd|xvd|hd|vd|nvme|mmcblk|loop|dm-|md|dasd|disk/).*",
On an unconfined macOS host with authorized sudo and an unmounted writable disk, sudo dd of=/dev/disk2 bs=1048576 count=1 </dev/zero → HookManager.on_tool_call → is_denied returns None → approval permits destroying partition metadata; /dev/rdisk2 also escapes.
Anchor: residual/crash-data-loss-corruption
Fix: Add disk[0-9] and rdisk[0-9] alternatives to both new device patterns and the golden entry.

[BLOCK-MERGE] 66b106f
[GPT-REVIEWED] 66b106f

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1: Unbounded harm (irreversible disk wipe). The base rule at src/kiro_crew/security/denied_rules.py:1140 (dd if=.*) never matched an of=-only spelling, so this gap existed before the PR and the PR narrows it. Even so, sudo -n dd and /bin/dd are realistic things an unattended agent would type. The only conditions are sandbox "off" (sandbox.py:10058, an ordinary operator setting) and sudo, which is not an extreme combination. The FLAG bar is not met.

F2: Unbounded harm. sudo dd of=/dev/disk2 and /dev/rdisk2 are the standard macOS spellings for writing to a disk, and the patch's alternatives (disk/ only) leave both out. The only condition is a macOS host running with the sandbox off. That is a plausible combination, so no rarity argument applies.

[ADJUDICATION] 66b106fe585fd3e99fae52d623720f71f8013d0d total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 66b106fe585fd3e99fae52d623720f71f8013d0d

[ADJUDICATION-FENCED] 66b106fe585fd3e99fae52d623720f71f8013d0d fenced=2 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/security/denied_rules.py:1149 -- With the sandbox off and sudo available, an agent's ordinary `sudo -n dd` or `/bin/dd of=/dev/sda` gets past the new rule and wipes the disk for good; that combination is plausible, and the gap having existed before this PR does not make it rare.
UPHOLD-FENCED F2 src/kiro_crew/security/denied_rules.py:1149 -- `/dev/diskN` and `/dev/rdiskN` are the standard macOS raw-disk paths, so on an unconfined macOS host `sudo dd of=/dev/disk2` gets past the new rule; that is a common combination, not an extreme one.
[GPT-ADJUDICATED-FENCED] 66b106fe585fd3e99fae52d623720f71f8013d0d

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 66b106f

@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 Sep 16, 2026
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — 🟡 CONCERNS

Which legitimate operations does 66b106fe585fd3e99fae52d623720f71f8013d0d newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

the reviewer's own judgement; no confirmed regression

Scope-Verdict: CONCERNS

TIGHTENING: Two guards got stricter. The deny-rule catalog has a new row in src/kiro_crew/security/denied_rules.py: id="local-destructive-dd-of-device", pattern="^(sudo\\s+)?dd .*of=/dev/(sd|xvd|hd|vd|nvme|mmcblk|loop|dm-|md|dasd|disk/).*". The skill-script validator has a new unanchored regex in src/kiro_crew/skills_script_validator.py: re.compile(r"\bdd\s+.*of\s*=\s*/dev/(sd|xvd|hd|vd|nvme|mmcblk|loop|dm-|md|dasd|disk/)", re.I). Both refuse one threat: a dd invocation that points of= at a raw disk device with no if=, which wipes the disk from stdin ("dd reads stdin by default, so the if=-keyed row alone left the of=-only spelling allowed").

ADJUDICATED: 17 candidates, 0 confirmed newly-refused

The rule-catalog half is the part the classifier can check. The candidates work the boundary of the device-prefix set and the ^dd command-position anchor:

  • Pseudo-devices next to the refused prefixes: /dev/stdout, /dev/stderr, /dev/shm/… (beside /dev/sd), /dev/tty, and sudo … of=/dev/null.
  • Writes with no if= to regular files: a relative path, /tmp, a build output directory.
  • Read-only operations on the same device name: lsblk /dev/sda.
  • The threat needle quoted outside command position: git log --grep, git commit -m, rg, findstr.
  • Daily maintainer operations in the touched area: dd --version, gh pr view.

No verdict came back confirmed for this review, so there is no regression to report.

PLATFORM COVERAGE:

  • posix: the diff's main assumption is posix /dev/<name> device paths and a bare dd (optionally sudo dd) at command position. The posix rows probe both: device names one prefix off the refused set (/dev/stderr, /dev/shm, /dev/stdout, /dev/tty, /dev/null), the sudo prefix, and stdin-fed writes with no if= into ordinary files.
  • windows: the anchor ^(sudo\s+)?dd makes an assumption about the program spelling. The windows rows probe it with dd.exe writing to a drive-letter path (C:\Temp\…), a PowerShell pipeline into MSYS dd with .\ backslash relative paths, and a cmd.exe findstr search that quotes the needle.
  • any: used only for strings with no path, separator or executable name: dd --version, git log --grep, git commit -m, gh pr view.
  • Gap: I wrote no row for macOS /dev/diskN or /dev/rdiskN targets. Those are refusal-coverage questions (whether the rule is strict enough), which belong to another reviewer, not to this lane's over-refusal question.

UNADJUDICATED: The _DESTRUCTIVE regex added to src/kiro_crew/skills_script_validator.py is not a tool-call shell gate, so the classifier cannot rule on it.

  • Call path:
    • A generated skill script reaches validate_skill_script(filename, content) from two places: skills_script_validator.py:464, which is the pending-skill review, and history_consolidation.py:3141, which is history consolidation.
    • It then runs rx.search(content) over the whole script source.
    • The search has no command-position anchor and no quote awareness. . stops at newlines, so it matches within a single line.
  • Effect of a match: the script gets a "destructive: dd of=/dev/" finding, and ok=False.
  • Why it can over-match: unlike the catalog row, this regex fires on any word dd followed by whitespace with of=/dev/<prefix> later on the same line. That includes string literals, docstrings and comments.
  • Legitimate inputs I would have submitted:
    • A disk-imaging helper skill whose help text reads print("usage: dd of=/dev/sdX is refused; write to an image file instead").
    • A comment such as # never run: dd of=/dev/xvda in a safety-checking script.
    • A script line that pairs a dd token with a device path for reporting, not execution: log.info("dd status: of=/dev/nvme0n1 not touched").
    • A script that only reads devices: subprocess.run(["lsblk", "/dev/sda"]). This should stay allowed, and it does, because there is no dd\s+ before it.
  • What this leaves open: none of these got a verdict. The over-match on prose inside skill-script source is a narrowing concern I can argue but not confirm. A safer shape would require dd at a shell command boundary (^\s*, or after ['"], ;, |, &&) rather than anywhere on the line.

[SCOPE-REVIEWED] 66b106f

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 14 classified, 0 newly refused, 14 still allowed.
  • ubuntu-latest (platform posix): 14 classified, 0 newly refused, 14 still allowed.
  • windows-latest (platform windows): 7 classified, 0 newly refused, 7 still allowed.

No candidate flipped from allowed to refused.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Fixed in f99fda7: the Backend Lint red was the black-baseline graduate rule - this PRs edits left test_skill_script_validator.py black-clean while still listed, so I pruned that one line from .github/black-baseline.txt (verified the other touched files are either clean or still listed). GPT and Security Scope reviews are advisory; PR Readiness should clear once lint is green.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 18, 2026
@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

CI triage: Backend Windows(8) fails with an autonudge asyncio CancelledError (untouched surface), frontend on the systemic bn/fr catalog tests. No push - rerun should clear.

@dwu96 dwu96 added the needs-pr-triage PR scanner: awaiting automated triage label Sep 22, 2026
@NicholasRBowers NicholasRBowers added drive-to-green PR claimed by drive-to-green pipeline and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 22, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days with failing CI. I've assessed the blockers and they appear resolvable — I'll push fixes directly to this branch as a co-author.

Assessment: Four blockers, all mechanical and all inside the PR's stated intent (block raw-disk dd writes); the approach — a second deny row keyed on the output half — stays exactly as you designed it.

  1. Base drift — Denial Differential fails on all three OS with deny_diff: classifier ... failed: worker: sensitive_path_refusal is absent from this tree, i.e. the branch predates a corpus addition on main. The branch is also CONFLICTING. A rebase onto current main addresses both.
  2. Fail-open device set (GPT 5.6 BLOCKING + Design Review CONCERNS) — disk/ requires a trailing slash, so macOS /dev/disk0 and /dev/rdisk0 never match, and /dev/xvda (Xen/EC2) and /dev/nbd0 are absent. The rule's own claim ("raw-disk writes are refused") is not yet true for those spellings. I'll extend the enumeration to the spellings the reviewers named.
  3. Over-match narrowing (Security Scope Review BLOCK) — pattern="dd .*of=/dev/..." is an unanchored re.search on the whole command line with no \b on dd , so a read-only rg -n "dd .*of=/dev/sd" …, git grep, or an echo of a runbook line is newly refused. I'll anchor dd to argv-program position as that review recommends, without widening or retiring the row.
  4. Twin-guard divergence — the catalog pattern and skills_script_validator._DESTRUCTIVE disagree on the word boundary, so the two guards refuse different inputs. I'll align them, and declare the .github/black-baseline.txt prune in the description (First Principles flagged it as riding along undeclared).

The remaining reds are unrelated to this diff and are expected to clear on the rebase + re-run: Backend Tests (Windows) (8) is the autonudge CancelledError you already triaged, and the frontend reds are the systemic catalog tests.

If you'd prefer I don't touch this PR, add the pr-no-autofix label.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 26, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Oct 1, 2026
@aniruddhaadak80
aniruddhaadak80 force-pushed the fix/dd-output-to-device branch from b18777d to 1e29407 Compare October 1, 2026 18:31
@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream/main @ 8ab2a0edd and force-pushed. This branch previously conflicted, and the tip also carried unrelated changes from a bad rebase — 506 lines in test/test_security.py that had nothing to do with this rule (a redaction import refactor, a socket import, a JOSE header helper). Those are gone; the diff is now 96 insertions across 7 files and is scoped to this fix.

Two things were resolved rather than taken from either side:

The spec file. The old tip's docs/system-specs/modules/security.md was three unrelated main commits behind and reverted them (member-memory-bindings disposition prose, the sandbox.py facade split note, and the _DOCUMENT_LINK_RE redaction section). Only the Destructive operation blocks line is this PR's, so that is the only line changed; the rest of the file is main's current text.

The line budget. _PACKAGE_LINE_BUDGET conflicted because main re-pinned it to 28,025 for redaction._DOCUMENT_LINK_RE after this branch was written. Per the ratchet's own stated policy the number is re-measured off the tree, not summed from the delta: clean main measures 28,025, this branch measures 28,034, so the rule's nine lines are the whole delta. The new pin and its reason sit above the number.

.github/black-baseline.txt also appeared in the old diff; that hunk is already absorbed on main, so no baseline change is needed here.

Verification run on this branch (Windows host, Python 3.12.10):

  • pytest test/test_denied_commands_security.py test/test_security_gate_liveness.py test/test_skill_script_validator.py — 1354 passed, 1 skipped, including TestIsDeniedReDoSResistance and the re-pinned test_the_package_stays_within_its_line_budget.
  • The rule exercised directly against 9 argv shapes: dd of=/dev/sda, dd if=/dev/zero of=/dev/sda, sudo dd of=/dev/xvda, dd of=/dev/nvme0n1, dd of=/dev/sda1 all denied; dd if=/etc/passwd of=backup.img, dd if=/dev/sda of=disk.img, dd if=input.txt of=output.txt, echo hello | dd of=out.txt all allowed. 0 failures.
  • scripts/deny_diff.py --base upstream/main --head HEAD on the security-conductor golden-paths corpus — no regressions on both --platform posix and --platform windows.
  • mypy on both touched source files — no issues. black --check clean on the four non-baselined files; skills_script_validator.py is in black-baseline.txt and is deliberately left unformatted, per the ratchet's rule that a baselined file is not reformatted by a PR that merely touches it.

The one shard that was red on the previous run, Backend Tests (3.12, 3), failed in test/test_mcp_preflight.py::TestOnePassAtATime — a module this PR does not touch. Flagging it as likely inherited rather than caused by this diff; the rebase should confirm.

@NicholasRBowers — this one was in the sweep's "inactive with failing CI" bucket. It is a real security fix with a real rule and no maintainer decision outstanding, so it looks mergeable once the lanes re-run. Requesting review.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 1, 2026
dd with no if= operand reads stdin by default, so a command that points
only of= at a raw disk device (sd/xvd/hd/vd/nvme/mmcblk/loop/dm-/md/
dasd/disk/) destroys it while looking like a copy. The new
local-destructive-dd-of-device denied rule matches that argv shape, and
the golden fixtures pin the refusals, including the stdin-only form and
the innocuous of=-to-file forms that must stay allowed.

The pattern is anchored to the command position (^(sudo\s+)?dd), so a
search that quotes the needle -- grep -rn "dd of=/dev/sda" test/ docs/
-- is no longer refused while the command it documents stays denied.
Segments arrive stripped and payload views come from the -c/eval
carriers only, so bash -c 'dd of=/dev/sda' still reaches the rule
through its payload view.

The device set gains xvd: this repo's own EC2 template roots instances
at /dev/xvda, so the Xen spelling is the ordinary case on hosts Kiro Crew
provisions.

Rebased onto upstream/main 8ab2a0e. The security package's liveness
ratchet pins the package total with no headroom, so the rule's nine lines
trip test_the_package_stays_within_its_line_budget; _PACKAGE_LINE_BUDGET
is re-pinned to the measured 28,034 (clean main measures 28,025) and the
comment above the number states what the budget now covers, per the
ratchet's stated policy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aniruddhaadak80
aniruddhaadak80 force-pushed the fix/dd-output-to-device branch from 1e29407 to 66b106f Compare October 3, 2026 07:08
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 3, 2026
@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream/main @ 139de6e and force-pushed. This PR was merge-conflicting and its checks all predated the current tip.

One conflict, in test/test_security_gate_liveness.py: the _PACKAGE_LINE_BUDGET ratchet, which both sides had raised with their own documented reason -- this branch for the local-destructive-dd-of-device rule, main for the ssh self-target floor's boot-time warm-up. Resolved by keeping both reasons and re-pinning to the total measured on the merged tree rather than summing either side's delta. The file's own rule is that the number is the measured package total with no headroom, so the re-pin is a measurement, not a negotiation:

28,408 = sum of len(splitlines()) over src/kiro_crew/security/*.py on the merged tree

The gate accepts it: test_the_package_stays_within_its_line_budget passes at exactly that value.

Verified on the rebased tip: 1,383 passed, 1 skipped across test_security_gate_liveness.py, test_denied_commands_security.py and test_skill_script_validator.py. One commit, and now 0 behind main.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 4, 2026

Copy link
Copy Markdown
Contributor

PR triage (2026-10-05): REBASE needed, then CONTINUE-DEVELOPMENT

I checked this against origin/main @ ef61a9aaf6. The branch is 276 commits behind its merge base 139de6ecc and is dirty: git merge-tree reports a content conflict in test/test_security_gate_liveness.py. main has since re-pinned _PACKAGE_LINE_BUDGET to 28_415, so the ratchet has to be re-measured on the merged tree again.

Relationship check: no open or merged PR adds a dd of=/dev/... rule. On main, local-destructive-dd-if (dd if=.*) and the skill validator's \bdd\s+if= still miss of=-only spellings, so this PR is not duplicate and not superseded. Other open PRs that add catalog rows (#8262, #16244) touch the same len(BUILTIN_DENIED_RULES) == 112 pin, golden fixture and line budget. Those collisions are mechanical only. Whichever PR lands second has to re-bump the count.

Residual coverage, re-checked on head 66b106fe: I ran is_denied on these spellings and all of them still return None:

  • sudo -n dd of=/dev/sda
  • /bin/dd of=/dev/sda
  • sudo /bin/dd of=/dev/sda
  • env dd of=/dev/sda
  • time dd of=/dev/sda
  • sudo dd of=/dev/disk2
  • sudo dd of=/dev/rdisk2

This is the same concern the GPT 6.1 review already raised, so I'm not filing a separate change request. The gap existed before this PR, and the PR narrows it rather than introducing it. One thing worth noting: the ^ anchor makes this row narrower than its sibling dd if=.*, which is unanchored and catches /bin/dd if=.... Per AGENTS.md ("a regex spelling-chase is a review smell"), the reviewers should decide whether to keep closing spellings or to state that the OS sandbox is the real control for raw-device writes.

iamwhatever pushed a commit that referenced this pull request Oct 8, 2026
…perand

dd reads stdin by default, so the existing local-destructive-dd-if rule
(keyed on an input-file operand) left the of=-only spelling allowed: a
dd write to a raw disk device destroys data even when the command names
no input. Add local-destructive-dd-of-device, keyed on a raw-disk of=
target and anchored to the command position so a search that merely
quotes the needle stays allowed. Mirror the gap fix in the skills
script validator. Narrow device set keeps of=/dev/null and of=disk.img
allowed; /dev/xvda is the Xen root device this repo's EC2 template
provisions.

Re-pins the security package line budget to the measured total (one
rule entry plus its description) and bumps the catalog count 112 -> 113.

Fixes #17893
Replaces #11347 by @aniruddhaadak80

Co-authored-by: ANIRUDDHA ADAK <127435065+aniruddhaadak80@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Oct 8, 2026
…perand

dd reads stdin by default, so the existing local-destructive-dd-if rule
(keyed on an input-file operand) left the of=-only spelling allowed: a
dd write to a raw disk device destroys data even when the command names
no input. Add local-destructive-dd-of-device, keyed on a raw-disk of=
target and anchored to the command position so a search that merely
quotes the needle stays allowed. Mirror the gap fix in the skills
script validator. Narrow device set keeps of=/dev/null and of=disk.img
allowed; /dev/xvda is the Xen root device this repo's EC2 template
provisions.

Re-pins the security package line budget to the measured total (one
rule entry plus its description) and bumps the catalog count 112 -> 113.

Fixes #17893
Replaces #11347 by @aniruddhaadak80

Co-authored-by: ANIRUDDHA ADAK <127435065+aniruddhaadak80@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Oct 8, 2026
…perand

dd reads stdin by default, so the existing local-destructive-dd-if rule
(keyed on an input-file operand) left the of=-only spelling allowed: a
dd write to a raw disk device destroys data even when the command names
no input. Add local-destructive-dd-of-device, keyed on a raw-disk of=
target and anchored to the command position so a search that merely
quotes the needle stays allowed. Mirror the gap fix in the skills
script validator. Narrow device set keeps of=/dev/null and of=disk.img
allowed; /dev/xvda is the Xen root device this repo's EC2 template
provisions.

Re-pins the security package line budget to the measured total (one
rule entry plus its description) and bumps the catalog count 112 -> 113.

Fixes #17893
Replaces #11347 by @aniruddhaadak80

Co-authored-by: ANIRUDDHA ADAK <127435065+aniruddhaadak80@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Oct 9, 2026
…perand

dd reads stdin by default, so the existing local-destructive-dd-if rule
(keyed on an input-file operand) left the of=-only spelling allowed: a
dd write to a raw disk device destroys data even when the command names
no input. Add local-destructive-dd-of-device, keyed on a raw-disk of=
target, with the same shape as the sibling dd-if row: a dd word plus an
of=/dev/<raw-disk> operand anywhere in the command, with no
command-start anchor. Mirror the gap fix in the skills script validator.

Dropping the anchor keeps the rule short and uniform with dd-if, and
catches every prefix form (sudo, env, timeout, /bin/dd), a subshell and
bash -c '...'. The accepted side effect, exactly as the dd-if row
already has, is that a search or quote of the needle is refused too. The
device set is deliberately narrow -- of=/dev/null and of=disk.img stay
allowed -- and covers /dev/xvda, the Xen root device this repo's EC2
template provisions. No new parsing, no new device names, no special
cases.

Re-pins the security package line budget to the measured total (one
rule entry plus its description) and bumps the catalog count 112 -> 113.

Fixes #17893
Replaces #11347 by @aniruddhaadak80

Co-authored-by: ANIRUDDHA ADAK <127435065+aniruddhaadak80@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Oct 9, 2026
…perand

dd reads stdin by default, so the existing local-destructive-dd-if rule
(keyed on an input-file operand) left the of=-only spelling allowed: a
dd write to a raw disk device destroys data even when the command names
no input. Add local-destructive-dd-of-device, keyed on a raw-disk of=
target, with the same shape as the sibling dd-if row: a dd word plus an
of=/dev/<raw-disk> operand anywhere in the command, with no
command-start anchor. Mirror the gap fix in the skills script validator.

The pattern opens with a \bdd\s word boundary -- the same boundary the
validator twin already carries -- so it is a dd WORD, not the tail of
"add" or "odd". Dropping the command-start anchor keeps the rule short
and catches every prefix form (sudo, env, timeout, /bin/dd), a subshell
and bash -c '...'. The accepted side effect, exactly as the dd-if row
already has, is that a search or quote of the needle is refused too. The
device set is deliberately narrow -- of=/dev/null and of=disk.img stay
allowed -- and covers /dev/xvda, the Xen root device this repo's EC2
template provisions. No new parsing, no new device names, no special
cases.

Re-pins the security package line budget to the measured total (one
rule entry plus its description) and bumps the catalog count 112 -> 113.

Fixes #17893
Replaces #11347 by @aniruddhaadak80

Co-authored-by: ANIRUDDHA ADAK <127435065+aniruddhaadak80@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Oct 9, 2026
…perand

dd reads stdin by default, so the existing local-destructive-dd-if rule
(keyed on an input-file operand) left the of=-only spelling allowed: a
dd write to a raw disk device destroys data even when the command names
no input. Add local-destructive-dd-of-device, keyed on a raw-disk of=
target, with the same shape as the sibling dd-if row: a dd word plus an
of=/dev/<raw-disk> operand anywhere in the command, with no
command-start anchor. Mirror the gap fix in the skills script validator.

The pattern opens with a \bdd\s word boundary -- the same boundary the
validator twin already carries -- so it is a dd WORD, not the tail of
"add" or "odd". Dropping the command-start anchor keeps the rule short
and catches every prefix form (sudo, env, timeout, /bin/dd), a subshell
and bash -c '...'. The accepted side effect, exactly as the dd-if row
already has, is that a search or quote of the needle is refused too. The
device set is deliberately narrow -- of=/dev/null and of=disk.img stay
allowed -- and covers /dev/xvda, the Xen root device this repo's EC2
template provisions. No new parsing, no new device names, no special
cases.

Re-pins the security package line budget to the measured total (one
rule entry plus its description) and bumps the catalog count 112 -> 113.

Fixes #17893
Replaces #11347 by @aniruddhaadak80

Co-authored-by: ANIRUDDHA ADAK <127435065+aniruddhaadak80@users.noreply.github.com>

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

Thanks for this. Reviewed locally at head 66b106f. The three touched suites pass on the head (1383 passed, 1 skipped), and the comment-history check is clean. Requesting changes for these reasons:

  1. The new row refuses commands that only mention a device later in the line (kiro_crew/security/denied_rules.py:1149, ^(sudo\s+)?dd .*of=/dev/(...)). is_denied matches the whole string first, and ^dd .* runs across ;, && and |. So any command that starts with a harmless dd and has of=/dev/sd… anywhere after it is refused. Each of these is allowed on main and refused on this head:

    • dd of=out.img; echo of=/dev/sda
    • dd of=b.img && git commit -m 'note: dd of=/dev/sda is refused'
    • dd --help | grep of=/dev/sd
    • dd of=out.img && echo 'wrote, next: of=/dev/sda'
  2. Common ways of launching dd still get through. The ^(sudo\s+)? anchor only covers a bare dd or sudo dd at the start. These all write to /dev/sda and are allowed on this head: env dd of=/dev/sda, timeout 60 dd of=/dev/sda, /bin/dd of=/dev/sda, /usr/bin/dd of=/dev/sda, (dd of=/dev/sda), sudo -n dd of=/dev/sda, nice dd of=/dev/sda, LC_ALL=C dd of=/dev/sda, exec dd of=/dev/sda, command dd of=/dev/sda.

  3. The skill-script pattern is unanchored (kiro_crew/skills_script_validator.py:31, \bdd\s+.*of\s*=\s*/dev/...). It rejects a script whose comment or string literal only mentions the device. Two examples: # dd usage notes: copy then of=/dev/sda is never used and HELP = 'run dd with of=/dev/sdX only on a scratch disk'.

  4. The branch conflicts with main in test/test_security_gate_liveness.py (the line-budget pin). Backend Lint & Type Check on this head fails because test/test_skill_script_validator.py is now black-clean and needs removing from the formatting baseline (python3 scripts/check_black_formatting.py --update-baseline).

Suggested direction: an earlier PR for this issue (#17894) was closed by its author, who asked for an argv-level check instead of another text pattern. That check would sit beside the existing argv-structural floor. Parse each segment into argv, skip leading wrappers (sudo and its flags, env/VAR= assignments, timeout, nice, exec, command, and a path prefix on the program), and refuse only when the program actually being run is dd and its of= operand resolves to a raw block device. With that check, quoted text, a later segment, or a grep for the command can never match, and the wrapped spellings above are covered.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you @aniruddhaadak80 for spotting this dd gap.

Closing this because of a maintainer design decision. When the same fix (#17894) was closed on 2026-10-09, the call was that a regex deny rule is the wrong tool here: each fix either over-blocks harmless commands or leaves bypasses (#18569). The gap should be solved by a non-regex approach that reads command structure. That comment thanks you for raising it.

Your branch is kept. If you want to try a structural approach, a new PR is welcome.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 16, 2026
@mbriones98 mbriones98 removed the drive-to-green PR claimed by drive-to-green pipeline label Oct 16, 2026
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) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants