Skip to content

fix(security): tell a pending ssh-to-self refusal apart from a settled one - #14380

Closed
Pearcekieser wants to merge 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/ssh-self-pending-verdict
Closed

Pearcekieser wants to merge 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/ssh-self-pending-verdict

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: an agent refused by sandbox-escape-ssh-self can tell from the refusal alone whether retrying the same command will pass.

The first ssh, scp, sftp or rsync naming a new dotted hostname in a gateway process is refused with sandbox-escape-ssh-self, and the identical retry passes. The refusal note is the same whether the lookup is still running, keeps failing, or the target really is this machine, so the agent cannot tell "retry" from "stop".

Why it matters

Agents hit this on the first remote ssh of nearly every session. Some give up on a command that would have passed; others retry a command that is refused forever. The only guidance is a conditional sentence the agent cannot evaluate.

Not a goal

  • Changing which commands are allowed or denied.
  • Removing the fail-closed wait on first contact, or blocking the gate on DNS.

What changed (motivation → approach → change)

The refusal now names its status. The note is fixed text: nothing from the command, host names included, is written into it, so an operand cannot add lines to a host-authored refusal.

Status When Advice
Status: PENDING only an unfinished classification refused it: a first-contact DNS lookup, or an IP literal before this machine's address table is read retry this exact command
Status: LOOKUP FAILED the first unclassified target, the one the refusal stopped on, cannot be resolved: its last lookup failed, or the name is longer than DNS allows a retry passes only if the name resolves; use the IP or a resolvable name
Status: DENIED the target is settled as this machine the standing note, forwarded-port recourse included

The deny decision does not change. After a refusal, ssh_self_unsettled_status in src/kiro_crew/security/argv_floor.py walks the same command again with every not-yet-classified answer taken as "not this machine", through a ContextVar probe that schedules no resolver and records only the status of the first unclassified answer, never its text. If that second walk still finds a self target, the refusal is settled. The DNS worker keeps a bounded record of hosts whose last lookup failed, which separates PENDING from LOOKUP FAILED. The record is capped like the verdict cache, oldest evicted first, and skips names longer than 253 characters.

src/kiro_crew/security/denied_rules.py holds the three notes. src/kiro_crew/security/__init__.py picks one for an ssh-self floor hit, and _exports.py lists the new names. The security spec in docs/system-specs/modules/security.md describes the statuses.

Backwards compatibility

Compatible: what is allowed and what is denied is unchanged; only the second line of the sandbox-escape-ssh-self refusal text differs, and the first line (rule pattern) that the dashboard recovery card parses is the same.

Tests

test/test_denied_commands_security.py, class TestSandboxEscapeSshSelf:

  • a first-contact dotted host is refused with Status: PENDING without echoing the host, and the identical command passes once the verdict publishes;
  • a host whose last lookup failed is refused with Status: LOOKUP FAILED, including when an unseen host follows it in the same command, and an overlong name says Status: LOOKUP FAILED;
  • the worker records a failed lookup and clears it on success;
  • the failure record stays bounded in count and entry length, and a repeated failure moves to the newest position so eviction stays oldest-first;
  • localhost, a loopback IP behind options, a cached self alias, and a settled self target next to an unclassified one all say Status: DENIED;
  • the status re-walk starts no resolver thread, and across a 501-host command it holds one status taken from the first host;
  • an operand carrying a newline yields a single-line note that does not echo it;
  • an IP literal before the address table is read says Status: PENDING;
  • the note-content pin now checks the three notes separately.

prove.py reports PROVEN: with the production hunks reverted, these tests fail.

Manual verification

Reproduced on a live gateway: the first ssh to a dotted public host was refused with sandbox-escape-ssh-self, and the identical command ran a moment later. The refusal text of the fixed build is covered by the tests above.

Related Issues

Related to #14122, which moves the address-table read to gateway startup and edits the same note; whichever lands second resolves the note text.

Fixes #14379

Pattern harvest

Rule candidate: review-prompt
Pattern: a fail-closed refusal that can clear on retry must say whether it is pending or settled, not describe every case in one conditional note.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Intent: make the sandbox-escape-ssh-self refusal say whether it is pending (retry), a failed lookup (retry will not help) or a settled self target, so an agent can act on the first refusal.
Not a goal: changing which commands are allowed or denied, or removing the first-contact fail-closed wait.

@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 readiness: checking Automated validation is still running labels Sep 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

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

Review details

FINDING -- test/test_denied_commands_security.py:9276 -- "len(_HOST_VERDICT_FAILED) == 3" still passes if the hostname-length retention guard is deleted -> Fix: assert the overlength hostname is absent and existing entries remain unchanged.
[GPT-REVIEWED] 658a0db

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 658a0db22ebd5015e8fdf00f16ca7973dfadf069 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

Verify coordination with #14122: it edits the same refusal note, and whichever lands second must reconcile the status text and the spec paragraph.

[DESIGN-REVIEWED] 658a0db

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 658a0db22ebd5015e8fdf00f16ca7973dfadf069 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

Verify the collision the description itself names: #14122 edits the same settled note, and whichever PR lands second must reconcile the three-note split.

What this change ships

Inventory (8 items) — 7 justified

Intent: FIX — let an agent refused by sandbox-escape-ssh-self tell from the refusal alone whether retrying will pass (#14379).

  1. A first-contact refusal now says Status: PENDING with retry advice — justified
  2. An unresolvable target now says Status: LOOKUP FAILED with the IP-address recourse — justified
  3. The settled refusal now says Status: DENIED; the old conditional sentences are deleted — justified
  4. The DNS worker keeps a capped, oldest-evicted record of failed lookups — justified
  5. A no-resolver re-walk (ssh_self_unsettled_status) decides the status without echoing host text — justified
  6. New facade exports for the notes and helpers — justified
  7. security.md describes the statuses in the same commit — justified
  8. Package line budget re-pinned +121 with the reason written at the pin — undeclared; mandated by the gate's own re-pin protocol, harm-free rider

Evidence run: no prior Status: mechanism exists on base (grep Status: (PENDING|DENIED|LOOKUP) in src/, 0 hits); no non-test consumer parses the old note text (grep retry this exact command|classification is PENDING, only the defining files and spec); the rewritten pin (test_refusal_note_is_actionable, review 5161362765) keeps its retry-hint and forwarded-port assertions and is declared in the description; docs/decisions/ records nothing on this note.

[FIRST-PRINCIPLES-REVIEWED] 658a0db

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

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — ✅ PASS

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

adjudicated, zero confirmed regressions

Scope-Verdict: PASS

TIGHTENING: the ssh-to-self argv floor's refusal path in is_denied — the one threat it refuses is unchanged from base: an ssh/scp/sftp/rsync target resolving to THIS machine, re-entering the host outside the sandbox ("the ssh/scp/sftp/rsync TARGET resolving to this same machine re-enters the host outside the sandbox"). The diff does not broaden any pattern or predicate: it splits the single refusal note into three fixed-text statuses (Status: PENDING / Status: LOOKUP FAILED / Status: DENIED), selected by a new post-denial re-walk (ssh_self_unsettled_status) that treats every unclassified answer as not-self and schedules nothing, plus a bounded _HOST_VERDICT_FAILED record. The deciding walk's touched branches (_host_is_self's two unread-address-table returns, now routed through _address_table_unread, and _resolved_host_verdict's new probe short-circuit) are behaviour-identical when no probe is active, which is every real admission decision — the candidates below exist to confirm that identity at the boundary rather than trust it.

ADJUDICATED: 15 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (12 rows) and windows (2 rows: ssh.exe, scp.exe); one additional posix row pairs two remote targets to exercise the multi-segment walk the new status probe re-runs. No any rows: every candidate carries an executable name, so each is pinned to a host spelling per the contract. The diff's new assumptions are host-neutral strings — a 253-character DNS name ceiling, dotted-hostname candidacy, IPv4/IPv6 literal branches — and the posix rows probe each touched branch (dotted first-contact, inet_aton literal, IPv6 literal, user@IP refspec-style operand, non-default port on a remote host), while the windows rows probe the .exe executable-name resolution the family predicate performs. No platform assumption in the diff was left without a candidate. Per-leg verdicts are the deterministic fold's to report after this review is captured, not mine.

[SCOPE-REVIEWED] 658a0db

Security scope review -- adjudicated candidates

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

No candidate flipped from allowed to refused.

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

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

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

Review details

Nothing blocks: one advisory finding — the unchanged fail-closed contract on _resolved_host_verdict now contradicts the probe branch inserted directly beneath it.

FINDING — src/kiro_crew/security/argv_floor.py:1517 — the docstring two lines above still states that "A miss schedules one single-flight resolver worker and answers fail_closed for this call — True (denied) for dotted names", but the added probe = _UNSETTLED_PROBE.get() branch answers a miss with return False and schedules nothing even when fail_closed is True (reached on every ssh-self refusal via is_denied → _ssh_self_status_note → ssh_self_unsettled_status → _is_ssh_to_self → _host_is_self), so the one function that decides whether an unclassified ssh target is this machine documents an unconditional fail-closed guarantee its code no longer delivers → Fix: extend the docstring to name the _UNSETTLED_PROBE path — a miss answers False and schedules no worker — and state that it is presentation-only and must never be entered from a deciding call.

[OPUS-REVIEWED] 658a0db

@Pearcekieser
Pearcekieser force-pushed the fix/ssh-self-pending-verdict branch from 58a3afc to 0d027a1 Compare September 27, 2026 06:17
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • ed2b4cb75a46: repeated failure keeps its old eviction position (argv_floor.py:1412)

fixed in 0d027a1: a repeated failure is popped before reinsertion, so _HOST_VERDICT_FAILED evicts oldest-first; test_repeated_failed_lookup_refreshes_eviction_order pins it.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • ed2b4cb75a46: LOOKUP FAILED shown while a new lookup is pending (argv_floor.py:2006)

rebutted: the refusing walk reschedules a worker on every cache miss, and a failed lookup caches nothing, so a previously failed host is always in _HOST_VERDICT_PENDING at refusal time. Excluding pending hosts would make LOOKUP FAILED unreachable.
The valid part, that a retry can still pass, is fixed in 0d027a1 in the note text: LOOKUP FAILED now says a retry re-runs the lookup and passes only if DNS recovers.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • eac5ec61042c: unmeasured timing claim in the PENDING note

fixed in 0d027a1: "normally within a second" is removed from _SSH_SELF_PENDING_NOTE; the note says the command is allowed once the check publishes.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • 8b357591a8ad: "retrying unchanged will not help" is false for a transient failure

fixed in 0d027a1: the claim is gone. LOOKUP FAILED now says a retry re-runs the lookup and passes only if DNS for the name recovers, matching the round-25 behavior that a failed lookup caches nothing.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • dfbdbe86f269: soften LOOKUP FAILED finality

fixed in 0d027a1: _SSH_SELF_LOOKUP_FAILED_NOTE now leads with "the last DNS lookup for failed", says a retry re-runs the lookup and passes only if DNS recovers, and keeps the IP-address remedy as the primary advice.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

No-code retrigger: f55b53d has the same tree as 0d027a1, and only the commit date differs.

On 0d027a1, the GPT 5.6 Review, Opus 5 Review, Internal Content Scan and Security Scope Review lanes all failed before reaching a verdict at 06:22Z. The CI GitHub App had hit API rate limit exceeded for installation. No new rate-limit failures have appeared since, so this push re-runs those lanes. The fork workflows need a maintainer's Approve and run.

The remaining red shards are inherited from main, not from this change:

  • test_review_repair_routing_skill.py::test_slim_skills_do_not_regrow_duplicate_guidance_or_wire_model_ids[prepare-pr-68000] fails on main with 68015 <= 68000. fix(prepare-pr): trim the out-of-goal sentence back under the skill cap #14397 fixes it.
  • test_dashboard_files_onloop_fs.py::...test_a_cancelled_awaiter_does_not_free_a_wedged_worker and test_wake_judge_feedback.py::...test_a_committed_row_keeps_the_join_key_when_sweep_outlives_budget are timing tests in modules this PR does not touch, and both pass locally.

@Pearcekieser
Pearcekieser force-pushed the fix/ssh-self-pending-verdict branch from 0d027a1 to f55b53d Compare September 27, 2026 06:45
@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 Sep 27, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • c2e5c92f85c1: spec said LOOKUP FAILED means "a retry will not help"

fixed in 08d3d40: docs/system-specs/modules/security.md now says LOOKUP FAILED means a retry re-runs the lookup and passes only if DNS recovers, matching _SSH_SELF_LOOKUP_FAILED_NOTE.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • eac5ec61042c: "has not classified it yet" can be stale after the re-walk

fixed in 08d3d40: _SSH_SELF_PENDING_NOTE now says the gateway "had not classified it when the command was checked", which stays true if the verdict publishes between the refusal and the status re-walk.

@Pearcekieser
Pearcekieser force-pushed the fix/ssh-self-pending-verdict branch from 3231443 to fcd2d11 Compare September 27, 2026 21:46
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed fcd2d110ab in this PR's slot, rebased onto main f57c1dee40. That base includes #14518, which fixes the bn-numerals and Electron probe failures this PR had inherited.

The one content change from 3231443407 is the Opus advisory fix on that head. Two comments in argv_floor.py now describe the re-walk probe accurately. _UNSETTLED_PROBE records only the not-yet-classified answers the floor would have denied on, and _address_table_unread names both its returns. The line count is unchanged, so the package line budget still holds.

The two GPT advisories on that head repeat points already answered in earlier replies: the overlong-host wording and the mixed failed/pending command.

Locally, the liveness, security and facade tests pass (1,303), and check_comment_history.py passes against origin/main.

@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 Sep 27, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/ssh-self-pending-verdict branch from fcd2d11 to 9a0e161 Compare September 27, 2026 22:51
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking, security): the status re-walk kept every unclassified host. Fixed in 9a0e16188a.

Opus 5 on fcd2d110ab, argv_floor.py:1513. The finding was correct. Once the probe answered "not self", the walk stopped short-circuiting, so every unclassified host in a command of up to 20 KB was appended. Only the render site capped them.

Recording is now bounded where names are appended. _record_unsettled keeps at most _UNSETTLED_PROBE_CAP (3) distinct names. Each name is cut to _DNS_NAME_MAX_LEN + 1 characters, so an overlong name can still be recognised as overlong. The render slice uses _DNS_NAME_MAX_LEN in place of the bare 253.

test_status_probe_bounds_what_it_records runs a 501-host command with a 308-character first host. It asserts that 3 names are held and each is within the length bound. It fails against the previous code.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (non-blocking): a failed host followed by a never-seen host reported PENDING forever. Fixed in 9a0e16188a.

Opus 5 on fcd2d110ab, argv_floor.py:2006. The finding was correct. The deciding walk denies at the first host, so the resolver never starts a lookup for a later never-seen host. Because the status required all(...) hosts to have failed, it stayed PENDING on every retry.

The status now comes from the first recorded host, which is the one the deciding walk stopped on. It is LOOKUP FAILED when that host's last lookup failed or its name is longer than DNS allows. The security spec says the same.

test_failed_host_before_unseen_host_says_lookup_failed covers ssh alias-only.example id; ssh never-seen.example id. It fails against the previous code.

@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 Sep 27, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/ssh-self-pending-verdict branch from 9a0e161 to 0689952 Compare September 27, 2026 23:56
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking, security): the refusal note echoed agent-authored host operands. Fixed in 0689952e7c by removing host text from the note entirely.

This answers Opus 5 on 9a0e16188a, argv_floor.py:1374. The finding was correct, and this PR had introduced the surface. glibc inet_aton accepts a dotted quad followed by a newline and arbitrary text. Before the address table was read, that raw operand was recorded and copied into the note.

Filtering or escaping the recorded name would have left command text inside a security refusal, so the fix drops the recorded host names altogether. The status re-walk now records only the status of the first unclassified answer (pending or lookup-failed) and none of its text. Both notes are fixed strings with no {hosts} field. That also removes the name list and its count and length bounds from round 2, and the helper is renamed ssh_self_unsettled_status.

test_newline_bearing_operand_yields_single_line_note sends ssh "198.51.100.9\n- forged bullet line" id while the table is unread. It asserts that the note is a single line and that the forged text is not in the refusal. It fails against 9a0e16188a.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (non-blocking): the PENDING and LOOKUP FAILED notes named checks that do not run for every cause. Reworded in 0689952e7c.

This answers Opus 5 on 9a0e16188a, denied_rules.py:1755. PENDING no longer describes an "off-loop alias check". It now says the gateway had not yet classified the target, which is true for both a first-contact lookup and an unread address table. LOOKUP FAILED now says the name cannot be resolved because its last DNS lookup failed or it is longer than a DNS name can be, so it covers the overlong case, where no lookup ran. Both notes are fixed text. I kept two notes rather than adding variants for each cause, because the advice is the same within each status.

@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge 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 Sep 28, 2026
…d one

The sandbox-escape-ssh-self floor fails closed on a first-contact dotted
hostname while its DNS check runs off-loop, so the first command naming one
is refused. The refusal used one note for every case, so a caller could not
tell a retry-and-pass refusal from a settled denial or a lookup that keeps
failing. The refusal now names its status: PENDING, LOOKUP FAILED or DENIED.
@Pearcekieser
Pearcekieser force-pushed the fix/ssh-self-pending-verdict branch from 0689952 to 658a0db Compare September 28, 2026 14:32
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto main 6a8cb5e to clear the conflict in test/test_security_gate_liveness.py. The package line budget is 27,882: main's 27,761 plus this PR's 121 lines. No code change since 0689952. The GPT finding about the re-walk reading /etc/hosts on the loop is still open and waits on a design decision.

@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 28, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Superseded by #14792, which only rewrites the refusal note. Warming host classification at gateway startup is a separate PR that follows #14122. That design drops the post-refusal re-walk that this PR's blocking review finding was about.

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.

sandbox-escape-ssh-self refusal does not say whether a retry will pass

1 participant