diff --git a/internal/audit/audit.go b/internal/audit/audit.go index 5dc03e185..3bb331db8 100644 --- a/internal/audit/audit.go +++ b/internal/audit/audit.go @@ -520,7 +520,14 @@ func checkContentIntegrity(skillPath string) []Finding { // Check pinned files: missing or tampered for rel, expected := range raw.FileHashes { - absPath := filepath.Clean(filepath.Join(skillPath, filepath.FromSlash(rel))) + normalizedRel := filepath.FromSlash(rel) + // Reject absolute keys in metadata (e.g. "/etc/passwd"). + // file_hashes must always be skill-relative paths. + if filepath.IsAbs(normalizedRel) { + continue + } + + absPath := filepath.Clean(filepath.Join(skillPath, normalizedRel)) // Containment check: reject keys that escape the skill directory if !strings.HasPrefix(absPath, filepath.Clean(skillPath)+string(filepath.Separator)) { continue diff --git a/internal/audit/audit_scan_skill_test.go b/internal/audit/audit_scan_skill_test.go index 28f57f81d..d020495a6 100644 --- a/internal/audit/audit_scan_skill_test.go +++ b/internal/audit/audit_scan_skill_test.go @@ -567,6 +567,7 @@ func TestScanSkill_ContentIntegrity_PathTraversal(t *testing.T) { writeMetaWithHashes(t, skillDir, map[string]string{ "SKILL.md": "sha256:" + sha256hex(content), "../../../etc/passwd": "sha256:aaaa", + "/etc/passwd": "sha256:bbbb", }) result, err := ScanSkill(skillDir) @@ -575,7 +576,7 @@ func TestScanSkill_ContentIntegrity_PathTraversal(t *testing.T) { } for _, f := range result.Findings { - if f.File == "../../../etc/passwd" { + if f.File == "../../../etc/passwd" || f.File == "/etc/passwd" { t.Errorf("path traversal key should be silently skipped, got finding: %s %s", f.Pattern, f.File) } } diff --git a/scripts/red_team/phase5_advanced.sh b/scripts/red_team/phase5_advanced.sh new file mode 100644 index 000000000..4c138587b --- /dev/null +++ b/scripts/red_team/phase5_advanced.sh @@ -0,0 +1,94 @@ +# Phase 5 - ADVANCED ADVERSARIAL CASES +# Sourced by red_team_test.sh; requires _helpers.sh + +phase "PHASE 5 - ADVANCED ADVERSARIAL CASES" + +# -- TC-31: file_hashes path traversal keys are ignored ---------- + +info "TC-31: file_hashes traversal keys should be ignored" +TRAVERSAL_DIR="$SOURCE_DIR/traversal-skill" +create_skill "$TRAVERSAL_DIR" "# Traversal test +Safe content for traversal hardening checks." + +TRAVERSAL_HASH=$(shasum -a 256 "$TRAVERSAL_DIR/SKILL.md" | awk '{print $1}') +echo "TOP SECRET" > "$TMPDIR_ROOT/secret.txt" + +cat > "$TRAVERSAL_DIR/.skillshare-meta.json" </dev/null 2>&1; then + fail "TC-31: traversal/absolute keys should not produce findings" +else + pass "TC-31: traversal/absolute hash keys ignored" +fi + +# -- TC-32: symlink to external file is surfaced ----------------- + +info "TC-32: external symlink should be surfaced as unexpected content" +SYMLINK_DIR="$SOURCE_DIR/symlink-skill" +create_skill "$SYMLINK_DIR" "# Symlink test +Safe content only." + +SYMLINK_HASH=$(shasum -a 256 "$SYMLINK_DIR/SKILL.md" | awk '{print $1}') +cat > "$SYMLINK_DIR/.skillshare-meta.json" < "$TMPDIR_ROOT/outside.txt" +ln -s "$TMPDIR_ROOT/outside.txt" "$SYMLINK_DIR/external-link.txt" + +ss_capture audit symlink-skill --json +if echo "$SS_OUTPUT" | jq -e ' + .results[0].findings[] | + select(.pattern == "content-unexpected" and .file == "external-link.txt" and .severity == "LOW") +' >/dev/null 2>&1; then + pass "TC-32: external symlink flagged as content-unexpected" +else + fail "TC-32: expected LOW content-unexpected for external-link.txt" +fi + +# -- TC-33: weird filename should not break --diff parsing ------- + +info "TC-33: weird filename should not break update --diff summary" +setup_tracked_repo "diff-weird" "# Diff parser baseline +Safe initial content." + +WEIRD_WORK="$TMPDIR_ROOT/work/diff-weird" +WEIRD_FILE=$'weird\tname.sh' +cat > "$WEIRD_WORK/$WEIRD_FILE" </dev/null 2>&1) +(cd "$WEIRD_WORK" && git push origin HEAD >/dev/null 2>&1) + +ss_capture update _diff-weird --diff --skip-audit +assert_exit "TC-33a: update with weird filename exits zero" 0 "$SS_EXIT" +assert_contains "TC-33b: --diff box rendered" "$SS_OUTPUT" "Files Changed" +assert_contains "TC-33c: weird filename appears in summary" "$SS_OUTPUT" "weird" + +# Clean up phase 5 +rm -rf "$SOURCE_DIR"/traversal-skill "$SOURCE_DIR"/symlink-skill "$SOURCE_DIR"/_diff-weird +rm -rf "$TMPDIR_ROOT/remotes/diff-weird.git" "$TMPDIR_ROOT/work/diff-weird" diff --git a/scripts/red_team_test.sh b/scripts/red_team_test.sh index 8d4d6ffa1..2b7185ce6 100755 --- a/scripts/red_team_test.sh +++ b/scripts/red_team_test.sh @@ -108,6 +108,7 @@ source "$RED_TEAM_DIR/phase1_recon.sh" source "$RED_TEAM_DIR/phase2_attack.sh" source "$RED_TEAM_DIR/phase3_integrity.sh" source "$RED_TEAM_DIR/phase4_batch.sh" +source "$RED_TEAM_DIR/phase5_advanced.sh" # ══════════════════════════════════════════════════════════════════ # SUMMARY diff --git a/tests/integration/audit_test.go b/tests/integration/audit_test.go index 09cbc1a3e..6277d47a9 100644 --- a/tests/integration/audit_test.go +++ b/tests/integration/audit_test.go @@ -932,6 +932,7 @@ func TestAudit_ContentHash_PathTraversal_Ignored(t *testing.T) { "../../../secret.txt": "sha256:0000", "../../secret.txt": "sha256:0000", "sub/../../../escape/passwd.txt": "sha256:0000", + "/etc/passwd": "sha256:0000", }) sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n") @@ -942,4 +943,5 @@ func TestAudit_ContentHash_PathTraversal_Ignored(t *testing.T) { result.AssertAnyOutputContains(t, "No issues found") result.AssertOutputNotContains(t, "secret.txt") result.AssertOutputNotContains(t, "passwd.txt") + result.AssertOutputNotContains(t, "/etc/passwd") }