chore(security): remove confirmed dead code in the platform and security surface - #6934
Conversation
…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.
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 4.8 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Design Review (Fable 5) — ✅ PASSDesign-level review of 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, Suggestions
[DESIGN-REVIEWED] 3727ebb |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of Everything checks out. Both deletions verified independently: zero references to either symbol repo-wide at HEAD, 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 shipsIntent: remove dead code from the security surface so it stops reading as live guard machinery — a FIX (of decay), shipped entirely as deletion.
Verification notes a reviewer should have: The description's deferred list and "needs a decision" items ship nothing, so they generate no inventory. The [FIRST-PRINCIPLES-REVIEWED] 3727ebb |
bolichen97
left a comment
There was a problem hiding this comment.
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.
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
--min-confidence 60Load/Attribute/ImportFrom/keywordnamesNAMEtokens only (docstrings, comments and same-spelled strings excluded), repo-wide, minus self-definitionsTriple 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-valuedif/whiletests) returned 12 hits that are all idiomaticwhile 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_METHODSis 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.pyaudit emit sites were not considered for deletion at all: a missing emit is a missing audit record.Deleted (2 symbols, 30 lines)
resolve_command_paths—security.py:11140-11159(20 lines)*.py *.ts *.tsx *.js *.md *.json *.yml *.yaml *.toml *.sh *.ps1, plustest/,docs/,docs/system-specs/,.github/,pyproject.toml. No string,getattr, dispatch-table,globals(),importlibor entry-point consumer.security.pydeclares no__all__; the symbol is not re-exported fromkiro_crew/__init__.pyand appears in no spec or SKILL.md.normalize_shell_command— is done insideis_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_normalizerroutes every path-like operand through it atsecurity.py:7532and:7767;docs/system-specs/modules/security.md:155names that path authoritative ("one implementation is authoritative on both surfaces")._HTTP_TOOLS_RE—security.py:11390-11395(6 lines, net 8 with spacing)_check_imds_access(live — called atsecurity.py:6647, tested intest/test_security.py:4601-4624, spec'd atdocs/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.Neither symbol had a test, so no test was deleted and no source-presence assertion was relaxed.
_is_path_likeremains live (security.py:7532,:7767);osandreremain in heavy use.Deferred — 30-day new-code gate
Confirmed unreferenced but too new to delete:
bind_allowed_portauth/login/portal.py:64-76BUILDER_ID_REGIONauth/login/endpoints.py:37AMZN_START_URLauth/login/endpoints.py:39ProfileStore.for_bindplatform/governance_profiles.py:770-776MANAGED_BY_NONEplatform/update_capability.py:40MODE_AUTOplatform/update_capability.py:43CHECK_CHECKINGplatform/update_capability.py:51SecretValue.__hash__secrets/vault.py:73-74_SENSITIVE_SEGMENT_ALTsecurity.py:6525Needs 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.
auth/login/portal.pyis an unwired login flow.wait_for_callback(docstring: "Serve the pre-bound loopback socket") requires a bound socket, andbind_allowed_portis the only function that produces one — yet nothing in production calls either.bind_allowed_portis 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 bytest/test_kas_auth_helpers.pyandtest/test_kas_auth_flows.py. The production login path is the device flow (auth/service.py:57 KasLoginService→dashboard/handlers/kas_login.py); the portal/loopback flow looks built but never connected.BUILDER_ID_REGION = "us-east-1"sits unused whileauth/refresh.py:167hardcodes the same literal (region = token.region or "us-east-1"). That constant should almost certainly be imported there rather than deleted.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 onPlatformContext, whichplatform/__init__.pyexports in__all__and whose module docstring defines the CPP seam: "an enterprise companion importsbuild_default_context+ the interfaces and supplies its own adapters." An out-of-tree companion readingctx.is_enterpriseis invisible from here, so it is kept. If the seam is meant to be closed it is deletable; otherwise it likely belongs in theRESERVED_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.flake8clean,isort --checkclean,mypy src/kiro_crew/security.pyclean.black --checkfails onsecurity.pyidentically on unmodifiedorigin/main(Python 3.12 parsing apy314target; the reported hunks are at lines 210 / 2443 / 2808, nowhere near this diff) — pre-existing and environmental, deliberately not touched.is_sensitive_path()canonicalizes and matches, making them non-equivalent rather than one being a stronger form of the other.