Skip to content

chore(security): remove confirmed dead code in the platform and security surface - #6934

Merged
bolichen97 merged 1 commit into
mainfrom
chore/dead-code-platform-security
Aug 30, 2026
Merged

chore(security): remove confirmed dead code in the platform and security surface#6934
bolichen97 merged 1 commit into
mainfrom
chore/dead-code-platform-security

Conversation

@iamwhatever

Copy link
Copy Markdown
Collaborator

Dead-code audit of the platform / security surface: src/kiro_crew/platform/, platform_compat.py, security.py, security_posture.py, sel.py, sandbox.py, src/kiro_crew/secrets/, src/kiro_crew/auth/ — 46,127 lines, 1,797 module/class-level definitions.

This group is audited at a deliberately higher bar than the others, so the result is small on purpose: 2 symbols, 30 lines, one file, zero behaviour change. Everything else that scanned as unreferenced is either exempt by construction or reported below rather than deleted.

Candidate generation — three independent scans

Scan Method Findings
vulture --min-confidence 60 374
AST defined names minus repo-wide Load / Attribute / ImportFrom / keyword names
tokenize real NAME tokens only (docstrings, comments and same-spelled strings excluded), repo-wide, minus self-definitions

Triple intersection: 12 candidates. A supplementary module-level-only pass (top-level funcs/classes with zero AST references, excluding structurally exempt files) returned 2, both already inside the 12 — so the strict intersection missed nothing at module level.

A separate unreachable-branch pass (statements after return / raise / break / continue, and constant-valued if / while tests) returned 12 hits that are all idiomatic while True:. There is no genuinely unreachable branch in this surface.

Why vulture's 374 findings do not become candidates

Three categories dominate and are exempt by construction:

  • platform/interfaces.py (1,271 lines) — Protocol definitions; every method is definitionally uncalled. The codebase already carries a formal registry for exactly this: platform/context.py:141 RESERVED_METHODS is a declared-inert contract surface documenting, per slot, why a Protocol method has no core call site (e.g. agent_runtime.managed_mcp_servers, identity.whoami). Their uncalledness is documented design, not decay.
  • platform/defaults.py (511 lines) — the OSS default implementations of those Protocols, reached through the adapter table rather than by name.
  • platform_compat.py (5,224 lines) — platform shims. Windows/macOS branches unreachable on a Linux host are live elsewhere.

sel.py audit emit sites were not considered for deletion at all: a missing emit is a missing audit record.

Deleted (2 symbols, 30 lines)

resolve_command_pathssecurity.py:11140-11159 (20 lines)

  • Exactly one occurrence repo-wide before this change (its own definition), across *.py *.ts *.tsx *.js *.md *.json *.yml *.yaml *.toml *.sh *.ps1, plus test/, docs/, docs/system-specs/, .github/, pyproject.toml. No string, getattr, dispatch-table, globals(), importlib or entry-point consumer.
  • security.py declares no __all__; the symbol is not re-exported from kiro_crew/__init__.py and appears in no spec or SKILL.md.
  • Its whole job — realpath-canonicalizing path-like tokens out of normalize_shell_command — is done inside is_sensitive_path() (security.py:6268) via _candidate_forms() (security.py:5967), which applies realpath, Path.resolve, lexical normalization, expansion and fallback forms and then matches. The live path _check_sensitive_via_normalizer routes every path-like operand through it at security.py:7532 and :7767; docs/system-specs/modules/security.md:155 names that path authoritative ("one implementation is authoritative on both surfaces").
  • Redundant, not an unwired guard: it only canonicalized and never blocked, so it was never a gate nor part of one. Introduced 2026-07-16 (45 days).

_HTTP_TOOLS_REsecurity.py:11390-11395 (6 lines, net 8 with spacing)

  • Exactly one occurrence repo-wide before this change (its own definition).
  • Its unambiguous intended consumer _check_imds_access (live — called at security.py:6647, tested in test/test_security.py:4601-4624, spec'd at docs/system-specs/modules/security.md:617) deliberately declines to narrow by tool. Inline comment at the block point: "Found IMDS IP -- block regardless of tool since even echo piped into nc could exfil credentials from the metadata service." The narrowing was abandoned by design, not left pending, so removing the pattern cannot weaken the gate.
  • No other URL, credential or exfiltration guard in the module wants a tool-name pattern; each carries its own purpose-built one. Introduced 2026-07-16 (45 days).

Neither symbol had a test, so no test was deleted and no source-presence assertion was relaxed. _is_path_like remains live (security.py:7532, :7767); os and re remain in heavy use.

Deferred — 30-day new-code gate

Confirmed unreferenced but too new to delete:

Symbol File:line Introduced Age
bind_allowed_port auth/login/portal.py:64-76 2026-08-27 3d
BUILDER_ID_REGION auth/login/endpoints.py:37 2026-08-27 3d
AMZN_START_URL auth/login/endpoints.py:39 2026-08-27 3d
ProfileStore.for_bind platform/governance_profiles.py:770-776 2026-08-26 4d
MANAGED_BY_NONE platform/update_capability.py:40 2026-08-20 10d
MODE_AUTO platform/update_capability.py:43 2026-08-20 10d
CHECK_CHECKING platform/update_capability.py:51 2026-08-20 10d
SecretValue.__hash__ secrets/vault.py:73-74 2026-08-19 11d
_SENSITIVE_SEGMENT_ALT security.py:6525 2026-08-12 18d

Needs a decision — deadness here is a defect, not dead code

Reported rather than deleted. Each wants wiring or an explicit call, which is a design decision outside a cleanup PR.

  1. auth/login/portal.py is an unwired login flow. wait_for_callback (docstring: "Serve the pre-bound loopback socket") requires a bound socket, and bind_allowed_port is the only function that produces one — yet nothing in production calls either. bind_allowed_port is also the enforcement point for the Cognito port allowlist (CALLBACK_PORTS): binding anywhere else is what it exists to prevent. Every sibling helper in the module (generate_code_verifier, generate_code_challenge, generate_state, build_auth_url, rebuild_redirect_uri, exchange_code) is exercised only by test/test_kas_auth_helpers.py and test/test_kas_auth_flows.py. The production login path is the device flow (auth/service.py:57 KasLoginServicedashboard/handlers/kas_login.py); the portal/loopback flow looks built but never connected.

  2. BUILDER_ID_REGION = "us-east-1" sits unused while auth/refresh.py:167 hardcodes the same literal (region = token.region or "us-east-1"). That constant should almost certainly be imported there rather than deleted.

  3. PlatformContext.is_enterprise (platform/context.py:356-357) has zero real references — the only other hit, test/test_cpp_wiring_enterprise.py:192 test_identity_is_enterprise, is a test function name, a substring rather than a call. It is nonetheless a public property on PlatformContext, which platform/__init__.py exports in __all__ and whose module docstring defines the CPP seam: "an enterprise companion imports build_default_context + the interfaces and supplies its own adapters." An out-of-tree companion reading ctx.is_enterprise is invisible from here, so it is kept. If the seam is meant to be closed it is deletable; otherwise it likely belongs in the RESERVED_METHODS-style declared-inert documentation so the next audit does not re-raise it.

Verification

  • test/test_security.py — 995 passed, 1 skipped.
  • test/test_denied_commands_security.py, test/test_governance_self_protection.py, test/test_platform_context.py, test/test_kas_auth_helpers.py — 674 passed.
  • flake8 clean, isort --check clean, mypy src/kiro_crew/security.py clean.
  • black --check fails on security.py identically on unmodified origin/main (Python 3.12 parsing a py314 target; the reported hunks are at lines 210 / 2443 / 2808, nowhere near this diff) — pre-existing and environmental, deliberately not touched.
  • Post-deletion grep confirms zero residual references to either symbol.
  • Two local AI reviewer lanes run before pushing (reachability / unwired-guard, and public-surface / hygiene): both returned no findings. One wording nit — "strictly stronger" in the original commit message — was corrected, since the deleted helper only canonicalized while is_sensitive_path() canonicalizes and matches, making them non-equivalent rather than one being a stronger form of the other.

…ity surface

Two symbols in security.py with zero references anywhere in the repository.
Neither has a caller, a test, or a documentation mention, so there is no
behaviour change; each is redundant against a mechanism that is live.

- resolve_command_paths: realpath-canonicalized path-like tokens out of
  normalize_shell_command, and nothing else. is_sensitive_path() performs
  that canonicalization itself via _candidate_forms() (realpath, resolve,
  lexical normalization, expansion) and then matches, and
  _check_sensitive_via_normalizer routes every path-like operand through it.
  The deleted helper only canonicalized, so it was never a substitute for
  that gate, and with no caller it was never part of one either.
- _HTTP_TOOLS_RE: a tool-narrowing pattern for the IMDS gate. Its intended
  consumer _check_imds_access blocks on the canonical IMDS endpoint
  regardless of executable, by explicit design ("even echo piped into nc
  could exfil credentials"), so the narrowing was abandoned rather than
  pending. No other URL, credential, or exfiltration guard in the module
  wants a tool-name pattern; each carries its own purpose-built one.
@iamwhatever
iamwhatever requested a review from a team as a code owner August 30, 2026 05:44
@iamwhatever
iamwhatever requested a review from CrysisDeu August 30, 2026 05:44
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Aug 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 3727ebbe599c036da4f6382e9f2aac94b24332ee and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3727ebb

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 3727ebbe599c036da4f6382e9f2aac94b24332ee: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 3727ebbe599c036da4f6382e9f2aac94b24332ee — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 3727ebb

Verdict parsed from the review's SHA-scoped output markers for commit 3727ebbe599c036da4f6382e9f2aac94b24332ee.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 3727ebbe599c036da4f6382e9f2aac94b24332ee: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 3727ebbe599c036da4f6382e9f2aac94b24332ee — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Two verifiably dead symbols removed from a security module with the live guard paths confirmed intact — minimal, evidence-backed, trivially reversible.

Verified against HEAD: zero residual references to either symbol, _is_path_like remains live, and _check_imds_access blocks tool-agnostically by design (the inline comment at security.py:11385 confirms _HTTP_TOOLS_RE's intended narrowing was deliberately abandoned), so no gate is weakened.

Suggestions

  • The "Needs a decision" findings (unwired portal.py login flow, BUILDER_ID_REGION duplicated as a literal in refresh.py) live only in this PR's description — file them as issues so the audit's most valuable output survives the merge.

[DESIGN-REVIEWED] 3727ebb

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 3727ebbe599c036da4f6382e9f2aac94b24332ee — 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.

Everything checks out. Both deletions verified independently: zero references to either symbol repo-wide at HEAD, _is_path_like retains its two live callers, the IMDS gate's inline comment confirms tool-narrowing was rejected by design, and _candidate_forms (security.py:5967) applies os.path.realpath inside the live sensitive-path matcher, covering the deleted function's only job.

First-Principles-Verdict: PASS

Pure subtraction: two zero-consumer symbols deleted, every zero-consumer claim in the description reproduces under independent grep, and nothing rides along.

What this change ships

Intent: remove dead code from the security surface so it stops reading as live guard machinery — a FIX (of decay), shipped entirely as deletion.

  1. resolve_command_paths no longer exists — justified; grep count 0 references at HEAD, its realpath job lives in _candidate_forms (security.py:5994) on the authoritative is_sensitive_path route.
  2. _HTTP_TOOLS_RE no longer exists — justified; grep count 0, and its intended consumer _check_imds_access blocks "regardless of tool" by documented design (security.py:11385).

Verification notes a reviewer should have: _is_path_like keeps 2 real callers (security.py:7532, :7767), so the deletion strands no helper; no spec or doc names either symbol (grepped HTTP_TOOLS|resolve_command across py/md/ts/json/yml — all hits are unrelated _resolve_command* symbols); neither deletion removes a gate, since one only canonicalized without matching and the other was never applied.

The description's deferred list and "needs a decision" items ship nothing, so they generate no inventory. The BUILDER_ID_REGION-should-be-imported-at-auth/refresh.py:167 observation is a correctly deferred wiring decision, not a rider.

[FIRST-PRINCIPLES-REVIEWED] 3727ebb

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Aug 30, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independently verified every removed symbol (grep across full repo + PR head, string/dynamic/registry lookup checks) has zero remaining references anywhere -- no dangling handler/registry entry (the #6876 defect class). CI all green. Approving.

@bolichen97
bolichen97 merged commit d79dbf5 into main Aug 30, 2026
67 checks passed
@bolichen97
bolichen97 deleted the chore/dead-code-platform-security branch August 30, 2026 08:32
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants