fix(update): audit tracked candidates before publication (#647)

* fix(update): audit tracked candidates before publication

Prevent rejected tracked-update bytes from becoming readable through published target links by staging and auditing a private candidate before updating the active checkout. Publish the exact approved revision without a second upstream pull.

Preserve sparse state, audit metadata, followed checkouts, and compatible edits. Recover staged and unstaged changes after failed forced publication, including deletions, renames, and sparse exclusions. Cover the boundary deterministically and align error messages and localized documentation.

* fix(update): preserve local bytes across Git line-ending conversion

Overlay dirty worktree bytes after staging candidate patches so core.autocrlf does not silently rewrite local edits. Cover staged, unstaged, and cancelled worktree changes while retaining their index state.

Make permission-failure coverage explicitly POSIX-only and compare private checkout contents to their original bytes. Align red-team assertions with candidate rejection and register private temporary cleanup with the raw-write guard.

* test(install): normalize checkout after configuring line endings

Windows fixtures initially inherit core.autocrlf=true. Reset the isolated checkout after selecting the subtest setting so changing it to false does not turn untouched upstream files into local edits.
This commit is contained in:
Willie
2026-10-26 15:59:32 +08:00
committed by GitHub
parent cbcb7a21ab
commit efc492fd7a
55 changed files with 1176 additions and 328 deletions
+4 -4
View File
@@ -30,7 +30,7 @@ else
fail "TC-20: malicious content not found in work clone"
fi
# ── TC-21: update detects + blocks + rolls back ───────────────
# ── TC-21: update rejects candidate before publication ───────
info "TC-21: skillshare update detects and blocks malicious update"
ss_capture update _attack-repo
@@ -38,11 +38,11 @@ TC21_OUTPUT="$SS_OUTPUT"
TC21_EXIT="$SS_EXIT"
assert_exit "TC-21a: update exits non-zero" 1 "$TC21_EXIT"
assert_contains "TC-21b: output mentions rollback" "$TC21_OUTPUT" "rolled back"
assert_contains "TC-21b: output mentions candidate rejection" "$TC21_OUTPUT" "candidate rejected; checkout unchanged"
# ── TC-22: Content verified clean after rollback ──────────────
# ── TC-22: Content verified clean after rejection ─────────────
info "TC-22: content is clean after rollback"
info "TC-22: content is clean after candidate rejection"
AFTER_CONTENT=$(cat "$SOURCE_DIR/_attack-repo/my-skill/SKILL.md")
assert_contains "TC-22a: clean content preserved" "$AFTER_CONTENT" "Nothing dangerous"
assert_not_contains "TC-22b: malicious content absent" "$AFTER_CONTENT" "Ignore all previous instructions"
+2 -2
View File
@@ -27,9 +27,9 @@ TC29_EXIT="$SS_EXIT"
assert_exit "TC-29: update --all exits non-zero with malicious repo" 1 "$TC29_EXIT"
assert_contains "TC-29b: output mentions blocked" "$TC29_OUTPUT" "blocked by security audit"
# TC-30: clean repo still updated, malicious rolled back
# TC-30: clean repo still updated, malicious candidate rejected
CLEAN_AFTER=$(cat "$SOURCE_DIR/_clean-repo/my-skill/SKILL.md")
assert_contains "TC-30a: clean repo updated successfully" "$CLEAN_AFTER" "Version 2"
EVIL_AFTER=$(cat "$SOURCE_DIR/_evil-repo/my-skill/SKILL.md")
assert_not_contains "TC-30b: malicious repo rolled back" "$EVIL_AFTER" "Ignore all previous instructions"
assert_not_contains "TC-30b: malicious candidate rejected" "$EVIL_AFTER" "Ignore all previous instructions"