T09 · Insecure Skill Coding Practices
- Location
scripts/parallel-implement.workflow.js:1277- Finding
Unvalidated Worktree Result IDs Allow the Post-Apply Audit to Be Skipped
- Content
View full analysis
Vulnerability Details
File Location:
scripts/parallel-implement.workflow.js, lines 1277–1284 and 1377–1380
Vulnerability Type: Improper validation of structured subagent results
Risk Level: HighVulnerable Code
js worktreeGroups.push({ id: g.id, branch: r.branch || '', worktreePath: wtPathFor(g), disjoint: g.disjoint, files: g.files, units: r.units || [] }) for (const ur of (r.units || [])) { const unit = g.units.find((u) => u.id === ur.unitId) || g.units[0] const d = draftByUnit.get(ur.unitId) || { unit, patch: { summary: '' } } // Map the worktree unit result onto the shared {d, result} shape (carry the in-worktree commit). const slot = { d, result: { unitId: ur.unitId, applied: ur.applied, filesChanged: ur.filesChanged || [], reDerived: ur.reDerived, verify: ur.verify, notes: ur.notes, committed: ur.committed, sha: ur.sha, subject: ur.subject } } if (ur.applied) applied.push(slot); else failed.push(slot) }The subsequent worktree audit derives the units to audit from the untrusted result IDs:
js const ids = appliedIds() for (const g of worktreeGroups) { const groupApplied = (g.units || []).map((u) => u.unitId).filter((id) => ids.has(id)) if (!groupApplied.length) continueTechnical Analysis
The workflow treats structured output from a worktree apply subagent as untrusted in several places, but it does not validate that
r.unitscontains exactly the units assigned to the group.When an apply result contains an unknown
unitId, the first block performs inconsistent identity handling:worktreeGroupsstores the unknown, agent-supplied ID inr.units.g.units.find(...)fails to locate that ID.- The code silently falls back to
g.units[0], associating the result with the first legitimate unit. - The resulting
appliedentry therefore has the legitimate unit ID throughs.d.unit.id, whileworktreeGroups[].unitsretains the unknown ID.
The audit subsequently constructs
idsfrom the ...[truncated 2592 chars]- Remediation
View remediation
Remediation Suggestions
Treat each worktree apply result as untrusted and validate it against the orchestrator’s expected group definition before adding it to
appliedor retaining its branch.- Build a set of expected unit IDs from the original
g.units. - Require every expected unit to appear exactly once in
r.units. - Reject unknown, duplicate, and missing unit IDs.
- Verify that
r.groupIdexactly equalsg.id. - Do not use
g.units[0]as a fallback for an unknown ID. - On any identity mismatch:
- Mark the entire group failed.
- Clear
r.branchorg.branch. - Disable committing and merge-back.
- Record an explicit audit finding.
- Derive the set of worktrees requiring audit from orchestrator-owned group state, not agent-reported unit IDs. Any group whose agent performed work or returned a branch should be audited even when no unit is considered successfully applied.
- Require a successful worktree disk audit before a branch can be merged. Represent this with a code-owned flag such as
auditPassed, initialized tofalseand set only after the audit verifies the group. - Add regression tests covering:
- Unknown result IDs.
- Duplicate IDs.
- Missing expected IDs.
- Results belonging to another group.
- A valid generated branch containing undeclared files while the result uses an unknown ID.
A secure validation pattern should resemble:
js const expectedIds = new Set(g.units.map((u) => u.id)) const returnedIds = (r.units || []).map((u) => u.unitId) const uniqueReturnedIds = new Set(returnedIds) const invalidIdentity = returnedIds.length !== expectedIds.size || uniqueReturnedIds.size !== returnedIds.length || returnedIds.some((id) => !expectedIds.has(id)) || [...expectedIds].some((id) => !uniqueReturnedIds.has(id)) || r.groupId !== g.id if (invalidIdentity) { r.branch = '' DO_COMMIT = false // Mark every expected unit failed and record an audit finding. }The post-apply audit should then ...[truncated 131 chars]
- Build a set of expected unit IDs from the original
