Skip to content

Avoid common App Store and Google Play rejections. Open playbook and pre-submission guard with 117 documented rejection patterns and fixes, privacy manifest and Data safety checks, 95 tracked deadlines (EU AI Act, DSA, COPPA, age laws), and a skill for AI coding agents.

fix(guard): parse the hook payload as JSON and route a block to stderr (#610) (#611)

Mirza Iqbal8734397a9e00
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4aa036..38f1b93 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ All notable changes to this playbook are recorded here. The format follows Keep
### Fixed
+- The guard's hook-mode payload parser was not JSON-aware (#610, reported and measured by mj-deving). The regex extraction stopped at the first escaped quote, so `cd "$CLAUDE_PROJECT_DIR/apps/app" && npx eas submit --platform ios` reduced to two characters and the guard exited 0 unscanned, and a backslash-newline continuation left the JSON newline escape literal, so `eas submit` split across two lines never matched. The command is now read from `.tool_input.command` (or a top-level `command`) with jq, then python3, then a backslash-aware fallback when neither is installed. Backslash-newline continuations fold into one space, and bare newlines stay as separators, so a trigger split across two separate commands is never invented. In hook mode a block now writes the report to stderr, the only stream Claude Code shows on exit 2, so the reason no longer arrives empty. A pass stays on stdout and standalone mode is unchanged. An adversarial review of the fix added four more guards. the trigger is matched against the raw command with quote characters stripped, so `eas "submit"`, `bash -c 'eas submit'`, and a submit inside a `python3 -c` string are all scanned, and only a single simple line led by an inert text command (`echo`, `printf`, `grep`, `cat`, `head`, `tail`, `wc`, `sort`, `uniq`, `tee`) with no substitution, pipe, or separator has its quoted spans and trailing comment blanked, so a plain echo or grep that mentions a submit never blocks while `echo "$(eas submit)"` and a `git` alias still scan. jq and python3 are each probed with a trivial run and their real exit status is checked, so a present but broken interpreter (the macOS python3 stub without Command Line Tools, a stale pyenv shim, a jq that dies on real input) falls through instead of silencing the guard, while a payload python3 genuinely rejects as invalid JSON stays silent. A leading `cd <dir> &&`, when it is the only directory change in the command and resolves inside the project, scopes the scan to that app, which is how an EAS monorepo submits. A payload whose `tool_name` is not Bash, or that carries more than one JSON document, is never scanned. A hook timeout signal flushes the buffered report to stderr, and when no temp file can be created the report stays on stdout as before with only the block reason line added on stderr. 66 new test cases, including runs with jq and python3 removed from PATH, a present but broken interpreter on PATH, and every counterexample from four adversarial review rounds.
- The guard scanned Python virtualenvs, bundled web output under dist/, and lowercase test folders (test/, tests/, integration_test/) as app source. A virtualenv's vendored API JSON alone raised five false criticals on one Flutter project. Directories are now pruned by name below the project root only, which also fixes a project sitting under a folder named build being scanned as empty (#542).
- Every `find | grep -q .` pipeline exited 141 under `set -o pipefail` once grep stopped reading and find died of SIGPIPE, so a project with more than one PrivacyInfo.xcprivacy (any CocoaPods or SPM project) was reported as missing its privacy manifest, and platform detection could miss a platform. The pipelines now drain their input, as release_string_has already did.
- ANDROID-USER-DATA-DISCLOSURE matched lowercase English words case-sensitively, so it fired on "files" in any documented repo and stayed silent on READ_CONTACTS. It now matches the permission constants and API symbols (#542).
diff --git a/README.md b/README.md
index 622db1b..760e1c5 100644
--- a/README.md
+++ b/README.md
@@ -47,7 +47,7 @@ Set up the App Store Compliance Playbook from https://github.com/mjmirza/app-sto
Steps:
1. Clone https://github.com/mjmirza/app-store-compliance into ~/repositories/app-store-compliance. If you cannot clone, read the files over the GitHub raw URLs instead.
2. Install the audit skill: copy agent-os/skill/SKILL.md plus the docs/, data/, references/, templates/, and scripts/ folders into your agent's skills directory. For Claude Code that is ~/.claude/skills/app-store-compliance/. The references/ folder is the structured tree the agent loads slices from, and scripts/ holds the guard and the metadata-audit engine.
-3. Install the pre-submission guard: copy agent-os/hooks/app-store-compliance-guard.sh into your hooks directory (for Claude Code, ~/.claude/hooks/), make it executable, and register it as a PreToolUse hook on the Bash tool in settings.json so it runs before app submission commands (fastlane, eas submit, gradle bundleRelease, xcrun altool, bundletool, xcodebuild archive) and blocks on a critical rejection risk.
+3. Install the pre-submission guard: copy agent-os/hooks/app-store-compliance-guard.sh into your hooks directory (for Claude Code, ~/.claude/hooks/), make it executable, and register it as a PreToolUse hook on the Bash tool in settings.json so it runs before app submission commands (fastlane, eas submit, gradle bundleRelease, xcrun altool, bundletool, xcodebuild archive) and blocks on a critical rejection risk. Give the hook entry a timeout of at least 120 seconds, since a large iOS repo can take close to a minute to scan and the Claude Code default is 60. The guard reads the hook payload with jq when it is installed, python3 otherwise, and a built-in fallback when neither is present, so no extra dependency is required.
4. Add a standing instruction to your agent config: for any iOS or Android work, always adhere to the Apple App Store Review Guidelines and Google Play policies, run the audit before submission, and never say an app is clear to submit while a critical risk stands.
5. Run the guard against my current project and show me the ranked findings:
bash ~/.claude/hooks/app-store-compliance-guard.sh /path/to/my/app
diff --git a/agent-os/hooks/app-store-compliance-guard-test.sh b/agent-os/hooks/app-store-compliance-guard-test.sh
index a362561..cecb398 100755
--- a/agent-os/hooks/app-store-compliance-guard-test.sh
+++ b/agent-os/hooks/app-store-compliance-guard-test.sh
@@ -683,6 +683,470 @@ OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
echo "$OUT" | grep -q 'APPLE-MANIFEST-UNREADABLE' && [ "$RC" -eq 2 ] && ok "Array-root manifest blocks" || bad "Array-root manifest blocks (rc=$RC)"
rm -rf "$D"
+# ===== Issue #610. The hook payload parser must be JSON-aware. Real Claude Code payloads below =====
+# (.tool_input.command inside JSON). The old regex truncated at an escaped quote and left \n literal.
+BS='\'
+P_QUOTED='{"tool_name":"Bash","tool_input":{"command":"cd '"$BS"'"$CLAUDE_PROJECT_DIR/apps/app'"$BS"'" && npx eas submit --platform ios"}}'
+P_CONT='{"tool_input":{"command":"npx eas '"$BS$BS$BS"'n submit --platform ios"}}'
+P_TWOCMD='{"tool_input":{"command":"echo eas'"$BS"'nsubmit --platform ios"}}'
+P_TABCRLF='{"tool_input":{"command":"npx'"$BS"'teas'"$BS"'tsubmit --platform ios'"$BS"'r'"$BS"'n"}}'
+P_QUOTED_CONT='{"tool_input":{"command":"cd '"$BS"'"$CLAUDE_PROJECT_DIR/apps/app'"$BS"'" && npx eas '"$BS$BS$BS"'n submit --platform ios"}}'
+P_QUOTED_TEST='{"tool_input":{"command":"cd '"$BS"'"$HOME/my app'"$BS"'" && npm test"}}'
+P_COMMITMSG='{"tool_input":{"command":"git commit -m '"$BS"'"docs: note that eas submit needs a profile'"$BS"'""}}'
+
+# 63 a quoted path before the submit command must still be scanned
+D="$(mk_ios_bad)"
+OUT="$(printf '%s' "$P_QUOTED" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-1 quoted path before eas submit is scanned" || bad "610-1 quoted path before eas submit is scanned (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 64 a backslash-newline continuation must not hide the trigger
+D="$(mk_ios_bad)"
+OUT="$(printf '%s' "$P_CONT" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-2 line continuation before submit is scanned" || bad "610-2 line continuation before submit is scanned (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 65 a bare newline separates commands. "eas" on one line and "submit" on the next is NOT a submit
+D="$(mk_ios_bad)"
+OUT="$(printf '%s' "$P_TWOCMD" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-3 trigger split across two commands is never invented" || bad "610-3 trigger split across two commands is never invented (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 66 on a block in hook mode the report reaches stderr (the only stream Claude Code shows on exit 2)
+D="$(mk_ios_bad)"
+ERR="$(printf '{"tool_input":{"command":"fastlane deliver --submit"}}' | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1 >/dev/null)"; RC=$?
+echo "$ERR" | grep -q 'BLOCKED' && echo "$ERR" | grep -q 'CRITICAL' && [ "$RC" -eq 2 ] && ok "610-4 hook-mode block report is on stderr" || bad "610-4 hook-mode block report is on stderr (rc=$RC bytes=${#ERR})"
+rm -rf "$D"
+
+# 67 a passing hook-mode scan keeps its report on stdout, and stderr stays quiet
+D="$(mk_ios_clean)"
+STDOUT="$(printf '{"tool_input":{"command":"fastlane deliver --submit"}}' | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>/dev/null)"; RC=$?
+ERR="$(printf '{"tool_input":{"command":"fastlane deliver --submit"}}' | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1 >/dev/null)"
+echo "$STDOUT" | grep -q 'Summary\.' && [ "$RC" -eq 0 ] && ! echo "$ERR" | grep -q 'Summary\.' && ok "610-5 hook-mode pass report stays on stdout" || bad "610-5 hook-mode pass report stays on stdout (rc=$RC)"
+rm -rf "$D"
+
+# 68 standalone mode is unchanged. the report is on stdout even when it blocks
+D="$(mk_ios_bad)"
+STDOUT="$(bash "$GUARD" "$D" 2>/dev/null)"; RC=$?
+echo "$STDOUT" | grep -q 'BLOCKED' && [ "$RC" -eq 2 ] && ok "610-6 standalone block report stays on stdout" || bad "610-6 standalone block report stays on stdout (rc=$RC)"
+rm -rf "$D"
+
+# 69 CRLF inside the command and a tab between the words are folded, the trigger still matches
+D="$(mk_ios_bad)"
+OUT="$(printf '%s' "$P_TABCRLF" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-7 tabs and CRLF inside the command still match" || bad "610-7 tabs and CRLF inside the command still match (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 70 without jq the fallback decoder still handles the quoted path (a vendored copy on a runner without jq)
+D="$(mk_ios_bad)"
+NOJQ="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil python3 xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOJQ/$b"; done
+OUT="$(printf '%s' "$P_QUOTED" | PATH="$NOJQ" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-8 quoted path is scanned without jq on PATH" || bad "610-8 quoted path is scanned without jq on PATH (rc=$RC bytes=${#OUT})"
+rm -rf "$D" "$NOJQ"
+
+# 71 without jq AND python3 the last-resort decoder still unescapes the quoted path and the continuation
+D="$(mk_ios_bad)"
+NOJQ="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOJQ/$b"; done
+OUT="$(printf '%s' "$P_QUOTED_CONT" | PATH="$NOJQ" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-9 quoted path plus continuation is scanned with neither jq nor python3" || bad "610-9 quoted path plus continuation is scanned with neither jq nor python3 (rc=$RC bytes=${#OUT})"
+rm -rf "$D" "$NOJQ"
+
+# 72 a payload with the command at the top level (older hook shape) is still read
+D="$(mk_ios_bad)"
+OUT="$(printf '{"command":"fastlane pilot upload"}' | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-10 top-level command key is read" || bad "610-10 top-level command key is read (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 73 malformed JSON payload fails open, silently
+OUT="$(printf '{"tool_input":{"command":"fastlane deliver' | bash "$GUARD" 2>&1)"; RC=$?
+[ "$RC" -eq 0 ] && [ -z "$OUT" ] && ok "610-11 malformed payload fails open silently" || bad "610-11 malformed payload fails open silently (rc=$RC out=$OUT)"
+
+# 74 a non-string command (object) fails open, silently
+OUT="$(printf '{"tool_input":{"command":{"nested":true}}}' | bash "$GUARD" 2>&1)"; RC=$?
+[ "$RC" -eq 0 ] && [ -z "$OUT" ] && ok "610-12 non-string command fails open silently" || bad "610-12 non-string command fails open silently (rc=$RC out=$OUT)"
+
+# 75 a quoted non-submit command stays silent (decoding must not widen the trigger)
+OUT="$(printf '%s' "$P_QUOTED_TEST" | bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-13 quoted non-submit command stays silent" || bad "610-13 quoted non-submit command stays silent (rc=$RC out=$OUT)"
+
+# 76 the trigger phrase inside a commit message is scanned on the conservative side, never a silent skip.
+# The scan on a clean project must exit 0, so a commit message never blocks anyone.
+D="$(mk_ios_clean)"
+OUT="$(printf '%s' "$P_COMMITMSG" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+[ "$RC" -eq 0 ] && ok "610-14 trigger phrase inside a commit message never blocks a clean project" || bad "610-14 trigger phrase inside a commit message never blocks a clean project (rc=$RC)"
+rm -rf "$D"
+
+# 77 a 200KB payload with the command at the end is decoded and scanned
+D="$(mk_ios_bad)"
+PAD="$(head -c 200000 /dev/zero | tr '\0' 'x')"
+OUT="$(printf '{"tool_input":{"description":"%s","command":"npx eas submit --platform ios"}}' "$PAD" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-15 large payload is decoded and scanned" || bad "610-15 large payload is decoded and scanned (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# ===== Issue #610, second round. Counterexamples from the adversarial review, pinned =====
+NOTOOLS="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOTOOLS/$b"; done
+NOJQ="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil python3 xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOJQ/$b"; done
+P_ESCBS='{"tool_input":{"command":"gradlew '"$BS$BS$BS$BS$BS"'nbundleRelease"}}'
+P_BSSPACE='{"tool_input":{"command":"npx eas '"$BS$BS"' '"$BS"'nsubmit --platform ios"}}'
+P_META_OK='{"meta":{"command":"eas submit"},"tool_input":{"command":"ls"}}'
+P_META_BROKEN='{"meta":{"command":"eas submit"},"tool_input":{"command":"ls"},BROKEN'
+P_FALSE='{"tool_input":{"command":false},"command":"fastlane pilot upload"}'
+P_UESC='{"tool_input":{"command":"'"$BS"'u0065as submit --platform ios"}}'
+
+# 78 two backslashes before a newline are an escaped backslash plus a separator, not a continuation
+D="$(mk_ios_bad)"
+OUT="$(printf '%s' "$P_ESCBS" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-16 escaped backslash before a newline is not folded" || bad "610-16 escaped backslash before a newline is not folded (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 79 a backslash followed by a space and then a newline is not a continuation either
+D="$(mk_ios_bad)"
+OUT="$(printf '%s' "$P_BSSPACE" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-17 backslash space newline is not folded" || bad "610-17 backslash space newline is not folded (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 80 a trigger under a sibling key never wins over tool_input.command, on every tier
+D="$(mk_ios_bad)"
+for tier in "$PATH" "$NOJQ" "$NOTOOLS"; do
+ OUT="$(printf '%s' "$P_META_OK" | PATH="$tier" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ [ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-18 sibling command key is ignored (tier=${tier##*/})" || bad "610-18 sibling command key is ignored (tier=${tier##*/} rc=$RC bytes=${#OUT})"
+done
+rm -rf "$D"
+
+# 81 a malformed payload with a trigger under a sibling key stays silent when a real parser is installed
+D="$(mk_ios_bad)"
+for tier in "$PATH" "$NOJQ"; do
+ OUT="$(printf '%s' "$P_META_BROKEN" | PATH="$tier" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ [ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-19 malformed payload never scans a sibling key (tier=${tier##*/})" || bad "610-19 malformed payload never scans a sibling key (tier=${tier##*/} rc=$RC bytes=${#OUT})"
+done
+rm -rf "$D"
+
+# 82 a non-string tool_input.command falls through to the top-level command identically on jq and python3
+D="$(mk_ios_bad)"
+for tier in "$PATH" "$NOJQ"; do
+ OUT="$(printf '%s' "$P_FALSE" | PATH="$tier" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-20 false tool_input.command falls through to top-level (tier=${tier##*/})" || bad "610-20 false tool_input.command falls through to top-level (tier=${tier##*/} rc=$RC bytes=${#OUT})"
+done
+rm -rf "$D"
+
+# 83 an ASCII unicode escape in the command is read on every tier, including the no-tools fallback
+D="$(mk_ios_bad)"
+for tier in "$PATH" "$NOJQ" "$NOTOOLS"; do
+ OUT="$(printf '%s' "$P_UESC" | PATH="$tier" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-21 unicode-escaped trigger is read (tier=${tier##*/})" || bad "610-21 unicode-escaped trigger is read (tier=${tier##*/} rc=$RC bytes=${#OUT})"
+done
+rm -rf "$D"
+
+# 84 the three tiers agree byte for byte on the two payloads from the issue
+D="$(mk_ios_bad)"
+for p in "$P_QUOTED" "$P_CONT"; do
+ A="$(printf '%s' "$p" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1 | grep -E '^ \[|^Summary\.|^BLOCKED')"
+ B="$(printf '%s' "$p" | PATH="$NOJQ" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1 | grep -E '^ \[|^Summary\.|^BLOCKED')"
+ C="$(printf '%s' "$p" | PATH="$NOTOOLS" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1 | grep -E '^ \[|^Summary\.|^BLOCKED')"
+ [ -n "$A" ] && [ "$A" = "$B" ] && [ "$B" = "$C" ] && ok "610-22 tiers agree on an issue payload" || bad "610-22 tiers agree on an issue payload (jq=${#A} py=${#B} none=${#C})"
+done
+rm -rf "$D"
+
+# 85 there is no stdin cap. a 34MB valid payload with the command up front is read and scanned
+D="$(mk_ios_bad)"
+BIG="$(mktemp)"; { printf '{"tool_input":{"command":"npx eas submit --platform ios","description":"'; head -c 34000000 /dev/zero | tr '\0' 'x'; printf '"}}'; } > "$BIG"
+OUT="$(CLAUDE_PROJECT_DIR="$D" bash "$GUARD" < "$BIG" 2>&1)"; RC=$?; rm -f "$BIG"
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-23 34MB valid payload is read and scanned" || bad "610-23 34MB valid payload is read and scanned (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+rm -rf "$NOTOOLS" "$NOJQ"
+
+# ===== Issue #610, third round. Reporter persona findings, pinned =====
+P_ECHO='{"tool_input":{"command":"echo '"$BS"'"eas submit --platform ios'"$BS"'""}}'
+P_GREP='{"tool_input":{"command":"grep -rn '"'"'eas submit'"'"' docs/"}}'
+P_COMMENT='{"tool_input":{"command":"ls -la # then npx eas submit --platform ios"}}'
+P_COMMENT_ECHO='{"tool_input":{"command":"echo hi # then npx eas submit --platform ios"}}'
+P_SHC='{"tool_input":{"command":"bash -c '"$BS"'"npx eas submit --platform ios'"$BS"'""}}'
+P_CD_APP='{"tool_input":{"command":"cd '"$BS"'"$CLAUDE_PROJECT_DIR/apps/app'"$BS"'" && npx eas submit --platform ios"}}'
+P_CD_REL='{"tool_input":{"command":"cd apps/app; eas submit -p ios --latest"}}'
+P_CD_OUT='{"tool_input":{"command":"cd /tmp && npx eas submit --platform ios"}}'
+P_BOM="$(printf '\357\273\277')"'{"tool_input":{"command":"fastlane pilot upload"}}'
+
+mk_expo_mono() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/apps/app/ios/App" "$d/apps/kiosk/ios/Kiosk" "$d/node_modules/x"
+ printf '{"name":"root","workspaces":["apps/*"]}' > "$d/package.json"
+ printf '{"expo":{"name":"app"}}' > "$d/apps/app/app.json"
+ printf '<plist><dict></dict></plist>' > "$d/apps/app/ios/App/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\nlet u="https://staging.example.com"\n' > "$d/apps/app/ios/App/A.swift"
+ printf '<plist><dict><key>NSLocationWhenInUseUsageDescription</key><string>Show stores</string><key>ITSAppUsesNonExemptEncryption</key><false/></dict></plist>' > "$d/apps/kiosk/ios/Kiosk/Info.plist"
+ printf '%s' "$PLIST_EMPTY" > "$d/apps/kiosk/ios/Kiosk/PrivacyInfo.xcprivacy"
+ printf 'import StoreKit\nlet policy="https://kiosk.example.io/privacy-policy"\n' > "$d/apps/kiosk/ios/Kiosk/K.swift"
+ echo "$d"
+}
+
+# 86 echo of the trigger text is not a submit
+OUT="$(printf '%s' "$P_ECHO" | bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-24 echo of the trigger text stays silent" || bad "610-24 echo of the trigger text stays silent (rc=$RC bytes=${#OUT})"
+
+# 87 grep for the trigger text is not a submit
+OUT="$(printf '%s' "$P_GREP" | bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-25 grep for the trigger text stays silent" || bad "610-25 grep for the trigger text stays silent (rc=$RC bytes=${#OUT})"
+
+# 88 a trailing comment is blanked only behind a text-only command. behind anything else it scans on the
+# conservative side (a comment can start inside a quoted wrapper argument) and a clean project still passes.
+D="$(mk_ios_clean)"
+OUT="$(printf '%s' "$P_COMMENT_ECHO" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-26 comment behind echo stays silent" || bad "610-26 comment behind echo stays silent (rc=$RC bytes=${#OUT})"
+OUT="$(printf '%s' "$P_COMMENT" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+[ "$RC" -eq 0 ] && ok "610-26 comment behind ls scans and a clean project passes" || bad "610-26 comment behind ls scans and a clean project passes (rc=$RC)"
+rm -rf "$D"
+
+# 89 a submit wrapped in bash -c "..." is still a submit and is scanned
+D="$(mk_ios_bad)"
+OUT="$(printf '%s' "$P_SHC" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-27 submit inside bash -c is scanned" || bad "610-27 submit inside bash -c is scanned (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 90 a leading cd into an app inside the project scopes the scan to that app, quoted and relative forms
+D="$(mk_expo_mono)"
+for p in "$P_CD_APP" "$P_CD_REL"; do
+ OUT="$(printf '%s' "$p" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q "^Project\. .*/apps/app$" && echo "$OUT" | grep -q 'MISSING-USAGE-DESCRIPTION' && [ "$RC" -eq 2 ] && ok "610-28 leading cd scopes the scan to the app" || bad "610-28 leading cd scopes the scan to the app (rc=$RC)"
+done
+rm -rf "$D"
+
+# 91 a leading cd outside the project root is ignored and the root is scanned
+D="$(mk_expo_mono)"
+OUT="$(printf '%s' "$P_CD_OUT" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ok "610-29 cd outside the project root is ignored" || bad "610-29 cd outside the project root is ignored (rc=$RC)"
+rm -rf "$D"
+
+# 92 a UTF-8 BOM before the payload is read on every tier
+D="$(mk_ios_bad)"
+NOTOOLS="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOTOOLS/$b"; done
+NOJQ="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil python3 xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOJQ/$b"; done
+for tier in "$PATH" "$NOJQ" "$NOTOOLS"; do
+ OUT="$(printf '%s' "$P_BOM" | PATH="$tier" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-30 BOM payload is read (tier=${tier##*/})" || bad "610-30 BOM payload is read (tier=${tier##*/} rc=$RC bytes=${#OUT})"
+done
+rm -rf "$D" "$NOTOOLS" "$NOJQ"
+
+# ===== Issue #610, fourth round. Hook-contract persona findings, pinned =====
+P_MCP='{"hook_event_name":"PreToolUse","tool_name":"mcp__some__runner","tool_input":{"command":"eas submit --platform ios"}}'
+P_EDIT='{"hook_event_name":"PreToolUse","tool_name":"Edit","tool_input":{"file_path":"x.md","new_string":"run eas submit"},"command":"eas submit --platform ios"}'
+P_NUL='{"tool_name":"Bash","tool_input":{"command":"./gradlew '"$BS"'u0000 bundleRelease"}}'
+
+# 93 a payload from any tool other than Bash is never scanned, even when it carries a command key
+D="$(mk_ios_bad)"
+for p in "$P_MCP" "$P_EDIT"; do
+ OUT="$(printf '%s' "$p" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ [ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-31 non-Bash tool payload stays silent" || bad "610-31 non-Bash tool payload stays silent (rc=$RC bytes=${#OUT})"
+done
+rm -rf "$D"
+
+# 94 a 5MB payload that is valid JSON with the command up front is scanned, well under the cap
+D="$(mk_ios_bad)"
+BIG="$(mktemp)"; { printf '{"tool_name":"Bash","tool_input":{"command":"npx eas submit --platform ios","description":"'; head -c 5000000 /dev/zero | tr '\0' 'x'; printf '"}}'; } > "$BIG"
+OUT="$(bash "$GUARD" < "$BIG" 2>&1)"; RC=$?; rm -f "$BIG"
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-32 5MB valid payload is scanned" || bad "610-32 5MB valid payload is scanned (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
+# 95 a NUL byte inside the command never leaks a bash warning to stderr on a pass
+D="$(mk_ios_clean)"
+ERR="$(printf '%s' "$P_NUL" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1 >/dev/null)"; RC=$?
+[ "$RC" -eq 0 ] && [ -z "$ERR" ] && ok "610-33 NUL byte in the command keeps stderr empty on a pass" || bad "610-33 NUL byte in the command keeps stderr empty on a pass (rc=$RC err=${ERR:0:80})"
+rm -rf "$D"
+
+# ===== Issue #610, fifth round. Second adversarial review, pinned. A submit can never hide in quotes =====
+P_QSUB='{"tool_input":{"command":"eas '"$BS"'"submit'"$BS"'" --platform ios"}}'
+P_SEMI_SHC='{"tool_input":{"command":"true;bash -c '"'"'eas submit --platform ios'"'"'"}}'
+P_PY_OS='{"tool_input":{"command":"python3 -c '"'"'import os; os.system('"$BS"'"eas submit --platform ios'"$BS"'")'"'"'"}}'
+P_SUBST='{"tool_input":{"command":"x='"$BS"'"$(bash -c '"'"'npx eas submit --platform ios'"'"')'"$BS"'""}}'
+P_ABS_SH='{"tool_input":{"command":"/bin/sh -c '"'"'eas submit --platform ios'"'"'"}}'
+P_TWO_CD='{"tool_input":{"command":"cd apps/app && cd ../kiosk && npx eas submit --platform ios"}}'
+P_TWO_DOCS='{"tool_input":{"command":"eas submit --platform ios"}} {"tool_input":{"command":"echo"}}'
+P_NESTED_TN='{"metadata":{"tool_name":"Edit"},"tool_name":"Bash","tool_input":{"command":"fastlane pilot upload"}}'
+NOJQ="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil python3 xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOJQ/$b"; done
+
+# 96 a submit is scanned however it is quoted or wrapped
+D="$(mk_ios_bad)"
+for p in "$P_QSUB" "$P_SEMI_SHC" "$P_PY_OS" "$P_SUBST" "$P_ABS_SH"; do
+ OUT="$(printf '%s' "$p" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-34 quoted or wrapped submit is scanned" || bad "610-34 quoted or wrapped submit is scanned (rc=$RC bytes=${#OUT} payload=${p:0:60})"
+done
+rm -rf "$D"
+
+# 97 two cd's in one command never scope the scan. the root is scanned as before
+D="$(mk_expo_mono)"
+OUT="$(printf '%s' "$P_TWO_CD" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ok "610-35 two cd's fall back to the project root" || bad "610-35 two cd's fall back to the project root (rc=$RC)"
+rm -rf "$D"
+
+# 98 two concatenated JSON documents are not one payload. silent on jq and on python3
+D="$(mk_ios_bad)"
+for tier in "$PATH" "$NOJQ"; do
+ OUT="$(printf '%s' "$P_TWO_DOCS" | PATH="$tier" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ [ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-36 concatenated documents stay silent (tier=${tier##*/})" || bad "610-36 concatenated documents stay silent (tier=${tier##*/} rc=$RC bytes=${#OUT})"
+done
+rm -rf "$D"
+
+# 99 a nested metadata tool_name never masks the real top-level Bash tool_name on the JSON tiers
+D="$(mk_ios_bad)"
+for tier in "$PATH" "$NOJQ"; do
+ OUT="$(printf '%s' "$P_NESTED_TN" | PATH="$tier" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-37 nested tool_name does not mask Bash (tier=${tier##*/})" || bad "610-37 nested tool_name does not mask Bash (tier=${tier##*/} rc=$RC bytes=${#OUT})"
+done
+rm -rf "$D" "$NOJQ"
+
+# ===== Issue #610, sixth round. Portability persona. the no-tools unescape must stay linear =====
+# 100 a 300KB command reaches the no-tools tier and is unescaped and scanned in seconds, not minutes
+D="$(mk_ios_bad)"
+NOTOOLS="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOTOOLS/$b"; done
+BIG="$(mktemp)"; { printf '{"tool_input":{"command":"npx eas submit --platform ios && echo '; head -c 300000 /dev/zero | tr '\0' 'x'; printf '"}}'; } > "$BIG"
+T0=$(date +%s); OUT="$(PATH="$NOTOOLS" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" < "$BIG" 2>&1)"; RC=$?; T1=$(date +%s); rm -f "$BIG"
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && [ $((T1-T0)) -lt 20 ] && ok "610-38 300KB command is scanned on the no-tools tier in $((T1-T0))s" || bad "610-38 300KB command is scanned on the no-tools tier (rc=$RC secs=$((T1-T0)) bytes=${#OUT})"
+rm -rf "$D" "$NOTOOLS"
+
+# ===== Issue #610, seventh round. Fuzz persona. a present but broken parser never disables the guard =====
+mk_broken_tool_path() { # $1 = name of the tool to break, everything else real, jq and python3 otherwise absent
+ local d; d="$(mktemp -d)"
+ for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$d/$b"; done
+ printf '#!/bin/sh\necho "xcrun: error: invalid active developer path" >&2\nexit 1\n' > "$d/$1"; chmod +x "$d/$1"
+ echo "$d"
+}
+P_FF='{"tool_input":{"command":"eas'"$BS"'fsubmit --platform ios"}}'
+P_NESTED_TI='{"command":"ls","tool_input":{"env":{"x":"y"},"command":"eas submit --platform ios"}}'
+
+# 101 the macOS python3 stub (no Command Line Tools) or a stale pyenv shim must fall through, never silence the guard
+D="$(mk_ios_bad)"
+for tool in python3 jq; do
+ BROKEN="$(mk_broken_tool_path "$tool")"
+ OUT="$(printf '%s' "$P_QUOTED" | PATH="$BROKEN" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-39 broken $tool on PATH falls through and the submit is scanned" || bad "610-39 broken $tool on PATH falls through and the submit is scanned (rc=$RC bytes=${#OUT})"
+ rm -rf "$BROKEN"
+done
+rm -rf "$D"
+
+# 102 a form feed between the tool and the verb is whitespace on every tier
+D="$(mk_ios_bad)"
+NOTOOLS="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOTOOLS/$b"; done
+for tier in "$PATH" "$NOTOOLS"; do
+ OUT="$(printf '%s' "$P_FF" | PATH="$tier" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-40 form feed separator is read (tier=${tier##*/})" || bad "610-40 form feed separator is read (tier=${tier##*/} rc=$RC bytes=${#OUT})"
+done
+
+# 103 a nested object ahead of the command key inside tool_input does not fool the no-tools tier
+OUT="$(printf '%s' "$P_NESTED_TI" | PATH="$NOTOOLS" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-41 nested object inside tool_input is skipped over" || bad "610-41 nested object inside tool_input is skipped over (rc=$RC bytes=${#OUT})"
+rm -rf "$D" "$NOTOOLS"
+
+# ===== Issue #610, eighth round. Third adversarial review. an inert text command cannot smuggle a submit =====
+P_ECHO_SUBST='{"tool_input":{"command":"echo '"$BS"'"$(eas submit --platform ios)'"$BS"'""}}'
+P_ECHO_PIPE='{"tool_input":{"command":"echo '"$BS"'"eas submit --platform ios'"$BS"'" | sh"}}'
+P_GIT_ALIAS='{"tool_input":{"command":"git -c alias.ship='"'"'!npx eas submit --platform ios'"'"' ship"}}'
+P_GIT_MSG='{"tool_input":{"command":"git commit -m '"$BS"'"docs: note that eas submit needs a profile'"$BS"'""}}'
+
+# 104 a submit inside a command substitution, a pipe, or a git alias behind an inert-looking command is scanned
+D="$(mk_ios_bad)"
+for p in "$P_ECHO_SUBST" "$P_ECHO_PIPE" "$P_GIT_ALIAS"; do
+ OUT="$(printf '%s' "$p" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-42 smuggled submit behind a text command is scanned" || bad "610-42 smuggled submit behind a text command is scanned (rc=$RC bytes=${#OUT} payload=${p:0:60})"
+done
+rm -rf "$D"
+
+# 105 a plain echo of the trigger with no substitution, pipe, or separator is still silent
+OUT="$(printf '%s' "$P_ECHO" | bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-43 plain echo of the trigger stays silent" || bad "610-43 plain echo of the trigger stays silent (rc=$RC bytes=${#OUT})"
+
+# 106 git is no longer inert (aliases and exec flags run commands). a commit message scans and a clean project passes
+D="$(mk_ios_clean)"
+OUT="$(printf '%s' "$P_GIT_MSG" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+[ "$RC" -eq 0 ] && ok "610-44 git commit message scans and a clean project passes" || bad "610-44 git commit message scans and a clean project passes (rc=$RC)"
+rm -rf "$D"
+
+# ===== Issue #610, ninth round. Fourth adversarial review. a parser that passes its probe but fails for real falls through =====
+mk_shim_path() { # $1 tool name to shim, $2 shim body, $3 = jq|python3|none to keep real on PATH besides the shim
+ local d; d="$(mktemp -d)"
+ for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$d/$b"; done
+ [ "$3" = jq ] && ln -s "$(command -v jq)" "$d/jq"; [ "$3" = python3 ] && ln -s "$(command -v python3)" "$d/python3"
+ printf '%s\n' "$2" > "$d/$1"; chmod +x "$d/$1"
+ echo "$d"
+}
+P_UNI='{"tool_input":{"command":"cd apps/caf\xc3\xa9 && npx eas submit --platform ios"}}'
+
+# 107 a jq that answers the probe but dies on real input falls through to python3 and the submit is scanned
+D="$(mk_ios_bad)"
+SHIM="$(mk_shim_path jq '#!/bin/sh
+[ "$1" = "-n" ] && exit 0
+echo "jq: error: segfault" >&2; exit 2' python3)"
+OUT="$(printf '%s' "$P_QUOTED" | PATH="$SHIM" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-45 jq that fails on real input falls through" || bad "610-45 jq that fails on real input falls through (rc=$RC bytes=${#OUT})"
+rm -rf "$SHIM"
+
+# 108 a python3 that answers the probe but dies on real input falls through to the regex tier and the submit is scanned
+SHIM="$(mk_shim_path python3 '#!/bin/sh
+[ "$2" = "pass" ] && exit 0
+echo "Fatal Python error" >&2; exit 1' none)"
+OUT="$(printf '%s' "$P_QUOTED" | PATH="$SHIM" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-46 python3 that fails on real input falls through" || bad "610-46 python3 that fails on real input falls through (rc=$RC bytes=${#OUT})"
+rm -rf "$SHIM"
+
+# 109 a genuinely invalid payload rejected by python3 stays silent (rejection is authoritative, not a crash)
+SHIM="$(mk_shim_path jq '#!/bin/sh
+exit 2' python3)"
+OUT="$(printf '{"tool_input":{"command":"fastlane deliver' | PATH="$SHIM" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+[ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-47 python3 rejecting invalid JSON stays silent" || bad "610-47 python3 rejecting invalid JSON stays silent (rc=$RC bytes=${#OUT})"
+rm -rf "$SHIM"
+
+# 110 PYTHONIOENCODING=ascii never drops a command with a non-ASCII path on the python3 tier
+NOJQ="$(mktemp -d)"; for b in bash grep sed awk find xargs tr head mktemp cat rm printf wc sort uniq cut plutil python3 xmllint dirname basename date; do p="$(command -v "$b" 2>/dev/null)"; [ -n "$p" ] && ln -s "$p" "$NOJQ/$b"; done
+OUT="$(printf "$P_UNI" | PYTHONIOENCODING=ascii PATH="$NOJQ" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-48 non-ASCII path survives PYTHONIOENCODING=ascii" || bad "610-48 non-ASCII path survives PYTHONIOENCODING=ascii (rc=$RC bytes=${#OUT})"
+rm -rf "$NOJQ"
+
+# 111 with no temp file available the pass report stays on stdout and a block still puts its reason on stderr
+SHIM="$(mk_shim_path mktemp '#!/bin/sh
+exit 1' jq)"; ln -s "$(command -v python3)" "$SHIM/python3"
+ERR="$(printf '{"tool_input":{"command":"fastlane deliver --submit"}}' | PATH="$SHIM" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1 >/dev/null)"; RC=$?
+echo "$ERR" | grep -q '^BLOCKED\.' && [ "$RC" -eq 2 ] && ok "610-49 degraded routing still puts the block reason on stderr" || bad "610-49 degraded routing still puts the block reason on stderr (rc=$RC err=${ERR:0:80})"
+rm -rf "$D"
+D="$(mk_ios_clean)"
+STDOUT="$(printf '{"tool_input":{"command":"fastlane deliver --submit"}}' | PATH="$SHIM" CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>/dev/null)"; RC=$?
+echo "$STDOUT" | grep -q 'Summary\.' && [ "$RC" -eq 0 ] && ok "610-50 degraded routing keeps the pass report on stdout" || bad "610-50 degraded routing keeps the pass report on stdout (rc=$RC bytes=${#STDOUT})"
+rm -rf "$D" "$SHIM"
+
+# ===== Issue #610, tenth round. Fifth adversarial review. a backslash before a letter is the letter =====
+P_LETTER_ESC='{"tool_input":{"command":"eas s'"$BS$BS"'ubmit --platform ios"}}'
+P_CONT_ESC='{"tool_input":{"command":"eas '"$BS$BS$BS"'n'"$BS$BS"'submit --platform ios"}}'
+
+# 112 eas s\ubmit and a continuation followed by \submit are both plain eas submit to the shell, and are scanned
+D="$(mk_ios_bad)"
+for p in "$P_LETTER_ESC" "$P_CONT_ESC"; do
+ OUT="$(printf '%s' "$p" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-51 letter escape inside the verb is scanned" || bad "610-51 letter escape inside the verb is scanned (rc=$RC bytes=${#OUT} payload=${p:0:60})"
+done
+rm -rf "$D"
+
+# ===== Issue #610, eleventh round. A heredoc body is data unless an interpreter consumes it =====
+P_HD_GH='{"tool_input":{"command":"gh pr create --title x --body-file - <<'"$BS"'"EOF'"$BS"'"'"$BS"'nFixes the guard so npx eas submit --platform ios is scanned.'"$BS"'nEOF"}}'
+P_HD_CAT='{"tool_input":{"command":"cat > notes.md <<EOF'"$BS"'nrun npx eas submit --platform ios later'"$BS"'nEOF"}}'
+P_HD_BASH='{"tool_input":{"command":"bash <<EOF'"$BS"'nnpx eas submit --platform ios'"$BS"'nEOF"}}'
+P_HD_PIPE='{"tool_input":{"command":"cat <<EOF | sh'"$BS"'nnpx eas submit --platform ios'"$BS"'nEOF"}}'
+P_HD_DOCKER='{"tool_input":{"command":"docker exec build sh <<'"'"'EOF'"'"''"$BS"'nfastlane pilot upload'"$BS"'nEOF"}}'
+P_HD_THEN='{"tool_input":{"command":"cat > x.txt <<EOF'"$BS"'nhello'"$BS"'nEOF'"$BS"'nnpx eas submit --platform ios"}}'
+
+# 113 a heredoc handed to gh or cat is prose, not a submit
+D="$(mk_ios_bad)"
+for p in "$P_HD_GH" "$P_HD_CAT"; do
+ OUT="$(printf '%s' "$p" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ [ -z "$OUT" ] && [ "$RC" -eq 0 ] && ok "610-52 heredoc prose behind gh or cat stays silent" || bad "610-52 heredoc prose behind gh or cat stays silent (rc=$RC bytes=${#OUT} payload=${p:0:50})"
+done
+
+# 114 a heredoc handed to an interpreter, directly, through a pipe, or inside docker exec, is scanned
+for p in "$P_HD_BASH" "$P_HD_PIPE" "$P_HD_DOCKER"; do
+ OUT="$(printf '%s' "$p" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+ echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-53 heredoc fed to an interpreter is scanned" || bad "610-53 heredoc fed to an interpreter is scanned (rc=$RC bytes=${#OUT} payload=${p:0:50})"
+done
+
+# 115 a real submit on the line after a heredoc terminator is still scanned
+OUT="$(printf '%s' "$P_HD_THEN" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-54 submit after a heredoc terminator is scanned" || bad "610-54 submit after a heredoc terminator is scanned (rc=$RC bytes=${#OUT})"
+rm -rf "$D"
+
echo ""
echo "app-store-compliance-guard-test: $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]
diff --git a/agent-os/hooks/app-store-compliance-guard.sh b/agent-os/hooks/app-store-compliance-guard.sh
index 576cb6c..c48e089 100755
--- a/agent-os/hooks/app-store-compliance-guard.sh
+++ b/agent-os/hooks/app-store-compliance-guard.sh
@@ -12,7 +12,8 @@ log_err() { if type hlog_error >/dev/null 2>&1; then hlog_error "app-store-compl
CRIT=0; HIGH=0; MED=0
FILELIST=""
-cleanup() { [ -n "$FILELIST" ] && rm -f "$FILELIST" 2>/dev/null || true; }
+REPORT=""; REPORT_DEGRADED=0
+cleanup() { [ -n "$FILELIST" ] && rm -f "$FILELIST" 2>/dev/null; [ -n "$REPORT" ] && rm -f "$REPORT" 2>/dev/null; true; }
trap cleanup EXIT
# ----- resolve mode and project dir -----
@@ -30,13 +31,100 @@ elif [ ! -t 0 ]; then
[ -z "$STDIN_JSON" ] && exit 0
fi
+# Read .tool_input.command as JSON (issue #610). The best installed parser decides. jq, else python3,
+# else a backslash-aware regex. A payload the chosen parser rejects yields no command, so the guard stays silent.
+tool_ok() { command -v "$1" >/dev/null 2>&1 && "$@" >/dev/null 2>&1; } # present AND able to run
+payload_command() {
+ local out
+ if tool_ok jq -n true; then
+ out="$(printf '%s' "$STDIN_JSON" | jq -rs 'if length != 1 then empty else .[0] | if ((.tool_name? // "Bash") != "Bash") then empty else ((.tool_input.command? | strings) // (.command? | strings) // empty) end end' 2>/dev/null)" && { printf '%s' "$out"; return 0; }
+ fi
+ if tool_ok python3 -c pass; then
+ out="$(printf '%s' "$STDIN_JSON" | python3 -c '
+import json, sys
+try:
+ d = json.loads(sys.stdin.buffer.read().decode("utf-8-sig"))
+except Exception:
+ sys.exit(4)
+c = None
+if isinstance(d, dict) and d.get("tool_name", "Bash") == "Bash":
+ ti = d.get("tool_input")
+ if isinstance(ti, dict) and isinstance(ti.get("command"), str):
+ c = ti["command"]
+ elif isinstance(d.get("command"), str):
+ c = d["command"]
+sys.stdout.buffer.write((c or "").encode("utf-8"))' 2>/dev/null)"; rc=$?
+ [ "$rc" -eq 0 ] && { printf '%s' "$out"; return 0; }
+ [ "$rc" -eq 4 ] && return 0
+ fi
+ # No working tool. Prefer the command inside tool_input, else the first command key, then unescape it.
+ local body
+ body="$(printf '%s' "$STDIN_JSON" | tr -d '\n\r' | grep -oE '"tool_input"[[:space:]]*:[[:space:]]*\{([^{}]|\{[^{}]*\})*"command"[[:space:]]*:[[:space:]]*"([^"\\]|\\.)*"' | head -1)"
+ [ -z "$body" ] && body="$(printf '%s' "$STDIN_JSON" | tr -d '\n\r' | grep -oE '"command"[[:space:]]*:[[:space:]]*"([^"\\]|\\.)*"' | head -1)"
+ [ -z "$body" ] && return 0
+ printf '%s' "$body" | sed -E 's/.*"command"[[:space:]]*:[[:space:]]*"//; s/"$//' \
+ | awk 'BEGIN { hx="0123456789abcdef" }
+ { n=split($0, part, /\\/); o=part[1]; lit=0
+ for (i=2; i<=n; i++) { p=part[i]
+ if (lit) { o=o p; lit=0; continue }
+ if (p=="") { o=o "\\"; lit=1; continue }
+ d=substr(p,1,1); rest=substr(p,2)
+ if (d=="n") o=o "\n" rest; else if (d=="t") o=o "\t" rest; else if (d=="r") o=o "\r" rest
+ else if (d=="\"") o=o "\"" rest; else if (d=="/") o=o "/" rest
+ else if (d=="f") o=o sprintf("%c", 12) rest; else if (d=="b") o=o sprintf("%c", 8) rest
+ else if (d=="u" && length(p)>=5) { h=tolower(substr(p,2,4)); v=0; ok=1
+ for (j=1;j<=4;j++) { q=index(hx,substr(h,j,1)); if (q==0) {ok=0; break}; v=v*16+q-1 }
+ if (ok && v>0 && v<128) o=o sprintf("%c", v) substr(p,6); else o=o "\\" p }
+ else o=o "\\" p }
+ printf "%s", o }'
+}
+
if [ -n "$STDIN_JSON" ]; then
- CMD="$(printf '%s' "$STDIN_JSON" | grep -oE '"command"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed -E 's/.*:[[:space:]]*"//; s/"$//')"
+ # Only a Bash tool call carries a shell command. The jq and python3 tiers check the top-level tool_name.
+ # The no-tools tier cannot tell a top-level key from a nested one, so it scans rather than skips.
+ CMD="$(payload_command 2>/dev/null | tr -d '\000')"
+ # Fold a backslash-newline continuation (odd trailing backslashes) into one space. Bare newlines stay,
+ # and grep matches per line, so a trigger split across two commands is never invented.
+ CMD="$(printf '%s' "$CMD" | tr -d '\r' | awk '
+ { l=$0; if (cont) { sub(/^[ \t]*/, "", l); cont=0 }
+ n=length(l); k=0; while (k<n && substr(l,n-k,1)=="\\") k++
+ if (k%2==1) { acc=acc substr(l,1,n-1) " "; cont=1 } else { printf "%s%s\n", acc, l; acc="" } }
+ END { if (cont) printf "%s\n", acc }' 2>/dev/null)"
+ [ -z "$CMD" ] && exit 0
+ # Match raw with quotes and letter escapes stripped. Only a single simple line led by an inert text command
+ # (echo, grep, cat) has quoted spans blanked, and a heredoc body is blanked unless an interpreter consumes it.
+ CMD_MATCH="$(printf '%s' "$CMD" | awk 'BEGIN { sq=sprintf("%c", 39); dq="\""; bt=sprintf("%c", 96); hd=0 }
+ { l=$0
+ if (hd) { t=l; sub(/^\t+/, "", t); if (t == hd_end) { hd=0 } else if (!hd_keep) { l="" } ; print l; next }
+ if (match(l, /<<-?[ \t]*[\047"]?[A-Za-z_][A-Za-z0-9_]*[\047"]?/) && substr(l, RSTART+2, 1) != "<") {
+ tag=substr(l, RSTART, RLENGTH); sub(/^<<-?[ \t]*/, "", tag); gsub(/[\047"]/, "", tag); hd=1; hd_end=tag
+ hd_keep = (l ~ /(^|[^A-Za-z0-9_\/-])((ba|z|da|k)?sh|eval|ssh|sudo|su|xargs|python[0-9.]*|node|ruby|perl|docker|kubectl|source)([^A-Za-z0-9_-]|$)/) }
+ f=l; sub(/^[ \t]*/, "", f)
+ while (f ~ /^[A-Za-z_][A-Za-z0-9_]*=[^ \t]*[ \t]+/) sub(/^[A-Za-z_][A-Za-z0-9_]*=[^ \t]*[ \t]+/, "", f)
+ split(f, w, /[ \t]+/); c=w[1]
+ simple = (index(l, "$(") == 0 && index(l, bt) == 0 && l !~ /[|;&<>]/)
+ if (simple && c ~ /^(echo|printf|grep|egrep|fgrep|cat|head|tail|wc|sort|uniq|tee)$/) {
+ gsub(sq "[^" sq "]*" sq, sq sq, l); gsub(dq "[^" dq "]*" dq, dq dq, l); sub(/(^|[ \t])#.*$/, "", l) }
+ else { gsub(sq, "", l); gsub(dq, "", l) }
+ print l }' 2>/dev/null | sed -E 's/\\([A-Za-z0-9])/\1/g')"
# Only act on submission style commands. Otherwise stay silent.
- if ! printf '%s' "$CMD" | grep -qiE 'fastlane[[:space:]]+(deliver|pilot|supply|submit)|eas[[:space:]]+(submit|build)|xcrun[[:space:]]+(altool|notarytool)|transporter|gradlew?[^&|;]*(bundleRelease|assembleRelease)|bundletool|xcodebuild[^&|;]*archive|flutter[[:space:]]+build[[:space:]]+(ipa|appbundle|apk|ios)|(npx[[:space:]]+)?(expo[[:space:]]+(prebuild|run:ios|run:android)|cap[[:space:]]+(sync|build|run|copy|open)|react-native[[:space:]]+run-(ios|android))|ionic[[:space:]]+capacitor[[:space:]]+(build|run)|cordova[[:space:]]+build([[:space:]]+--release)?'; then
+ if ! printf '%s' "$CMD_MATCH" | grep -qiE 'fastlane[[:space:]]+(deliver|pilot|supply|submit)|eas[[:space:]]+(submit|build)|xcrun[[:space:]]+(altool|notarytool)|transporter|gradlew?[^&|;]*(bundleRelease|assembleRelease)|bundletool|xcodebuild[^&|;]*archive|flutter[[:space:]]+build[[:space:]]+(ipa|appbundle|apk|ios)|(npx[[:space:]]+)?(expo[[:space:]]+(prebuild|run:ios|run:android)|cap[[:space:]]+(sync|build|run|copy|open)|react-native[[:space:]]+run-(ios|android))|ionic[[:space:]]+capacitor[[:space:]]+(build|run)|cordova[[:space:]]+build([[:space:]]+--release)?'; then
exit 0
fi
DIR="${CLAUDE_PROJECT_DIR:-$PWD}"
+ # A leading "cd <dir> &&" scopes the scan to that app (an EAS monorepo submits from apps/<app>).
+ # The target must resolve inside the project root, otherwise the root is scanned as before.
+ FIRST="$(printf '%s' "$CMD" | head -1)"
+ CD_COUNT="$(printf '%s' "$CMD" | grep -oE '(^|[;&|(][[:space:]]*)(cd|pushd|popd|source|\.)[[:space:]]' | wc -l | tr -d ' ')"
+ if [ "$CD_COUNT" -eq 1 ] && printf '%s' "$FIRST" | grep -qE '^[[:space:]]*cd[[:space:]]+[^&|;]+(&&|;)'; then
+ TARGET="$(printf '%s' "$FIRST" | sed -E 's/^[[:space:]]*cd[[:space:]]+//; s/[[:space:]]*(&&|;).*$//; s/^"(.*)"$/\1/; s/^'"'"'(.*)'"'"'$/\1/')"
+ TARGET="${TARGET//\$\{CLAUDE_PROJECT_DIR\}/$DIR}"; TARGET="${TARGET//\$CLAUDE_PROJECT_DIR/$DIR}"
+ case "$TARGET" in /*) ;; '~'*) TARGET="$HOME${TARGET#\~}" ;; *) TARGET="$DIR/$TARGET" ;; esac
+ if [ -d "$TARGET" ]; then
+ REAL_T="$(cd "$TARGET" 2>/dev/null && pwd -P)"; REAL_R="$(cd "$DIR" 2>/dev/null && pwd -P)"
+ case "$REAL_T/" in "$REAL_R"/*) DIR="$REAL_T" ;; esac
+ fi
+ fi
fi
# See docs/CROSS-PLATFORM-FRAMEWORKS.md: an Android-only command beats a committed ios/
@@ -169,6 +257,21 @@ done < <(find "$DIR" -maxdepth 4 -name 'config.xml' 2>/dev/null)
IOS_TARGET_ACTIVE=0
[ "$IS_IOS" -eq 1 ] && [ "$CMD_TARGET_ANDROID_ONLY" -eq 0 ] && IOS_TARGET_ACTIVE=1
+# ----- report routing (issue #610). Hook mode buffers the report. A block goes to stderr, the only
+# stream Claude Code shows on exit 2. A pass stays on stdout. Standalone mode prints straight to stdout.
+emit_report() { # $1 is the exit code about to be returned
+ [ -n "$REPORT" ] || return 0
+ exec 1>&3 3>&-
+ if [ "$1" -eq 2 ]; then cat "$REPORT" >&2; else cat "$REPORT"; fi
+ rm -f "$REPORT" 2>/dev/null; REPORT=""
+}
+# A hook timeout sends TERM. Flush what was buffered to stderr so the partial report is not lost.
+trap 'emit_report 2; exit 143' INT TERM HUP
+if [ -n "$STDIN_JSON" ]; then
+ REPORT="$(mktemp 2>/dev/null)" || REPORT=""
+ if [ -n "$REPORT" ] && : >"$REPORT" 2>/dev/null; then exec 3>&1; exec >"$REPORT"; else REPORT=""; REPORT_DEGRADED=1; fi
+fi
+
echo "== App Store Compliance Guard =="
echo "Project. $DIR"
echo "Platforms. iOS=$IS_IOS Android=$IS_AND Web=$IS_WEB"
@@ -615,10 +718,11 @@ if [ "$CRIT" -gt 0 ]; then
if [ "${APP_STORE_GUARD_OK:-0}" = "1" ]; then
echo "APP_STORE_GUARD_OK set. Critical findings present but the submission is allowed."
log_err "override used with $CRIT critical findings"
- exit 0
+ emit_report 0; exit 0
fi
echo ""
echo "BLOCKED. $CRIT critical rejection risk(s) above. Fix them, or set APP_STORE_GUARD_OK=1 to override."
- exit 2
+ [ "${REPORT_DEGRADED:-0}" = "1" ] && echo "BLOCKED. $CRIT critical rejection risk(s). Full report on stdout (no temp file available for buffering)." >&2
+ emit_report 2; exit 2
fi
-exit 0
+emit_report 0; exit 0