chore: update schema and red team scripts for centralized metadata

- registry.schema.json: describe .metadata.json store format (version,
  entries map with full field set) instead of old registry.yaml format
- Red team scripts: add write_store_meta helper, replace sidecar writes
  with centralized store writes in phase3 (integrity) and phase5 (advanced)
This commit is contained in:
Willie
2026-04-08 17:43:39 +08:00
parent 7552c76973
commit 19d88ce905
4 changed files with 90 additions and 77 deletions
+22
View File
@@ -49,6 +49,28 @@ $content
SKILL_EOF
}
# Write or merge a skill entry into the centralized .metadata.json store.
# Usage: write_store_meta <source_dir> <skill_name> <json_entry>
# Example: write_store_meta "$SOURCE_DIR" "my-skill" '{"source":"test","file_hashes":{"SKILL.md":"sha256:abc"}}'
write_store_meta() {
local source_dir="$1"
local skill_name="$2"
local entry_json="$3"
local store_path="$source_dir/.metadata.json"
if [ -f "$store_path" ]; then
# Merge into existing store
local tmp
tmp=$(jq --arg name "$skill_name" --argjson entry "$entry_json" \
'.entries[$name] = $entry' "$store_path")
echo "$tmp" > "$store_path"
else
# Create new store
jq -n --arg name "$skill_name" --argjson entry "$entry_json" \
'{version:1, entries:{($name): $entry}}' > "$store_path"
fi
}
# Run skillshare with isolated config.
# -g is placed after the subcommand to force global mode,
# preventing auto-detection of .skillshare/ in the working directory.
+6 -31
View File
@@ -13,16 +13,8 @@ Safe content for hash verification."
SKILL_HASH=$(shasum -a 256 "$INTEGRITY_DIR/SKILL.md" | awk '{print $1}')
cat > "$INTEGRITY_DIR/.skillshare-meta.json" <<META_EOF
{
"source": "test/integrity",
"type": "local",
"installed_at": "2026-01-01T00:00:00Z",
"file_hashes": {
"SKILL.md": "sha256:$SKILL_HASH"
}
}
META_EOF
write_store_meta "$SOURCE_DIR" "integrity-skill" \
"{\"source\":\"test/integrity\",\"type\":\"local\",\"installed_at\":\"2026-01-01T00:00:00Z\",\"file_hashes\":{\"SKILL.md\":\"sha256:$SKILL_HASH\"}}"
ss_capture audit integrity-skill --format json
HAS_INTEGRITY=false
@@ -54,17 +46,8 @@ create_skill "$INTEGRITY_DIR" "# Integrity test
Safe content for hash verification."
SKILL_HASH=$(shasum -a 256 "$INTEGRITY_DIR/SKILL.md" | awk '{print $1}')
cat > "$INTEGRITY_DIR/.skillshare-meta.json" <<META_EOF
{
"source": "test/integrity",
"type": "local",
"installed_at": "2026-01-01T00:00:00Z",
"file_hashes": {
"SKILL.md": "sha256:$SKILL_HASH",
"extras.md": "sha256:0000000000000000000000000000000000000000000000000000000000000000"
}
}
META_EOF
write_store_meta "$SOURCE_DIR" "integrity-skill" \
"{\"source\":\"test/integrity\",\"type\":\"local\",\"installed_at\":\"2026-01-01T00:00:00Z\",\"file_hashes\":{\"SKILL.md\":\"sha256:$SKILL_HASH\",\"extras.md\":\"sha256:0000000000000000000000000000000000000000000000000000000000000000\"}}"
ss_capture audit integrity-skill --format json
assert_finding "TC-27: content-missing detected as LOW" "$SS_OUTPUT" "content-missing" "LOW"
@@ -72,16 +55,8 @@ assert_finding "TC-27: content-missing detected as LOW" "$SS_OUTPUT" "content-mi
# ── TC-28: Unexpected file → content-unexpected (LOW) ─────────
info "TC-28: unexpected file detected"
cat > "$INTEGRITY_DIR/.skillshare-meta.json" <<META_EOF
{
"source": "test/integrity",
"type": "local",
"installed_at": "2026-01-01T00:00:00Z",
"file_hashes": {
"SKILL.md": "sha256:$SKILL_HASH"
}
}
META_EOF
write_store_meta "$SOURCE_DIR" "integrity-skill" \
"{\"source\":\"test/integrity\",\"type\":\"local\",\"installed_at\":\"2026-01-01T00:00:00Z\",\"file_hashes\":{\"SKILL.md\":\"sha256:$SKILL_HASH\"}}"
echo "unexpected content" > "$INTEGRITY_DIR/sneaky.sh"
+4 -23
View File
@@ -13,19 +13,8 @@ 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" <<META_EOF
{
"source": "test/traversal",
"type": "local",
"installed_at": "2026-01-01T00:00:00Z",
"file_hashes": {
"SKILL.md": "sha256:$TRAVERSAL_HASH",
"../../../secret.txt": "sha256:0000",
"../../secret.txt": "sha256:0000",
"/etc/passwd": "sha256:0000"
}
}
META_EOF
write_store_meta "$SOURCE_DIR" "traversal-skill" \
"{\"source\":\"test/traversal\",\"type\":\"local\",\"installed_at\":\"2026-01-01T00:00:00Z\",\"file_hashes\":{\"SKILL.md\":\"sha256:$TRAVERSAL_HASH\",\"../../../secret.txt\":\"sha256:0000\",\"../../secret.txt\":\"sha256:0000\",\"/etc/passwd\":\"sha256:0000\"}}"
ss_capture audit traversal-skill --format json
if echo "$SS_OUTPUT" | jq -e '
@@ -45,16 +34,8 @@ 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" <<META_EOF
{
"source": "test/symlink",
"type": "local",
"installed_at": "2026-01-01T00:00:00Z",
"file_hashes": {
"SKILL.md": "sha256:$SYMLINK_HASH"
}
}
META_EOF
write_store_meta "$SOURCE_DIR" "symlink-skill" \
"{\"source\":\"test/symlink\",\"type\":\"local\",\"installed_at\":\"2026-01-01T00:00:00Z\",\"file_hashes\":{\"SKILL.md\":\"sha256:$SYMLINK_HASH\"}}"
echo "outside file content" > "$TMPDIR_ROOT/outside.txt"
ln -s "$TMPDIR_ROOT/outside.txt" "$SYMLINK_DIR/external-link.txt"