Skip to content

fix(code-review): reject resolve-base.sh against repo top-level, not CWD#12

Open
davidalee wants to merge 1 commit intomainfrom
fix/code-review-skill-dir-repo-toplevel
Open

fix(code-review): reject resolve-base.sh against repo top-level, not CWD#12
davidalee wants to merge 1 commit intomainfrom
fix/code-review-skill-dir-repo-toplevel

Conversation

@davidalee
Copy link
Copy Markdown
Owner

Summary

Follow-up to #11 / EveryInc#783. Codex review on EveryInc#783 flagged that the CWD-rejection guard for ${CLAUDE_SKILL_DIR}/scripts/resolve-base.sh compares real_base against pwd -P — the caller's current directory — not the reviewed-repo top-level. The bypass:

  • Reviewer is launched from a monorepo subdirectory: pwd -P = <repo-root>/services/foo.
  • Harness sets ${CLAUDE_SKILL_DIR} to <repo-root>/.evil (a sibling of the subdir).
  • real_base is outside the CWD subdir, so the case clause does not match and the path is accepted.
  • bash \"$RESOLVE_SCRIPT\" then executes a repo-controlled script.

The valid (and intended) boundary is the reviewed repo's top-level, not the caller's CWD.

What changed

  • Both probe blocks (branch and standalone modes) now derive real_repo from git rev-parse --show-toplevel, with a pwd -P fallback when the CWD is not inside a git repo. The case match rejects real_base equal to or nested under real_repo.
  • Contract test pins the new shape (git rev-parse --show-toplevel must appear in SKILL.md) and adds an end-to-end monorepo-subdirectory attack scenario: git init a fake repo, set CWD to a subdir, point CLAUDE_SKILL_DIR at <root>/.evil, assert the probe fails closed and the decoy never runs.

Verification

  • bun test tests/review-skill-contract.test.ts — 26 pass.
  • bun test — full suite (1240 tests) passes.
  • bun run release:validate — clean.

Test plan

  • Existing scenarios (unset, empty, happy-path, hostile-CWD-nested-skill-dir) still pass.
  • New monorepo-subdir scenario: rejected, fail-closed, decoy not executed.

The CWD-rejection guard for `${CLAUDE_SKILL_DIR}/scripts/resolve-base.sh`
compared `real_base` against `pwd -P`. In a monorepo where the reviewer is
launched from a subdirectory, a harness value like `<repo-root>/.evil`
sits outside the CWD subdir but is still repo-controlled and would be
accepted, allowing arbitrary code execution from the reviewed repo.

Compare against the repo top-level (`git rev-parse --show-toplevel`)
instead, falling back to `pwd -P` only when not inside a git repo. Add a
contract test that exercises the monorepo-subdirectory attack and pins
the new probe shape.
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.

1 participant