Repository Public License
1#!/usr/bin/env bash2# ORIX OS Automation3# File: Scripts/release/secret-scan.sh4# Description: Fails when the repository or a built app contains credential-shaped strings, the development key variable names in a release binary, or internal host names.5#6# Author: Simon-Pierre Boucher7# Contact: contact@spboucher.ai8# Scripts/release/secret-scan.sh [path-to-app]9set -uo pipefail10cd "$(dirname "$0")/../.."11FAIL=012PATTERN='sk-ant-[A-Za-z0-9_-]{20,}|sk-or-v1-[A-Za-z0-9]{20,}|sk-(proj-)?[A-Za-z0-9_-]{32,}|xai-[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}|-----BEGIN [A-Z ]*PRIVATE KEY-----|gh[pousr]_[A-Za-z0-9]{30,}'13echo "== tracked files"14# Test sources hold synthetic, key-shaped fixtures for the redactor and the provider stubs; they are covered by the15# exact-value check below instead of the shape check.16if git ls-files -z | grep -zv "/Tests/" | xargs -0 grep -nIE "$PATTERN" 2>/dev/null | grep -v "Scripts/release/secret-scan.sh" | cut -c1-120; then echo "FAIL: credential-shaped string in the repository"; FAIL=1; else echo "ok"; fi17echo "== git history"18if git log -p --all -- . ':(exclude)*/Tests/*' 2>/dev/null | grep -nE "^\+.*($PATTERN)" | grep -v "PATTERN=" | cut -c1-120 | head -5 | grep -q .; then echo "FAIL: credential-shaped string in git history"; FAIL=1; else echo "ok"; fi19APP="${1:-}"20# Exact-value check: when run under Scripts/test/with-dev-keys.sh, the real development keys are searched for (as fixed21# strings, never printed) in every tracked file, the whole git history and the built app.22REAL=023for v in "${ORIX_DEV_ANTHROPIC_API_KEY:-}" "${ORIX_DEV_OPENAI_API_KEY:-}" "${ORIX_DEV_OPENROUTER_API_KEY:-}"; do24 [[ ${#v} -ge 20 ]] || continue25 REAL=126 if git ls-files -z | xargs -0 grep -lIF -- "$v" >/dev/null 2>&1; then echo "FAIL: a real development key is in a tracked file"; FAIL=1; fi27 if git log -p --all 2>/dev/null | grep -qF -- "$v"; then echo "FAIL: a real development key is in git history"; FAIL=1; fi28 if [[ -n "$APP" ]] && LC_ALL=C grep -rqF -- "$v" "$APP" 2>/dev/null; then echo "FAIL: a real development key is in the app bundle"; FAIL=1; fi29done30echo "== exact development key values"31if [[ $REAL -eq 1 ]]; then [[ $FAIL -eq 0 ]] && echo "ok: none of the real keys appears in tracked files, history or the bundle"; else echo "not checked (run under Scripts/test/with-dev-keys.sh to check)"; fi32if [[ -n "$APP" ]]; then33 echo "== $APP"34 BIN="$APP/Contents/MacOS/$(/usr/libexec/PlistBuddy -c 'Print CFBundleExecutable' "$APP/Contents/Info.plist")"35 if LC_ALL=C grep -rIlE "$PATTERN" "$APP" 2>/dev/null | head -3 | grep -q .; then echo "FAIL: credential-shaped string in the bundle"; FAIL=1; fi36 if strings -a "$BIN" | grep -E "$PATTERN" | head -1 | grep -q .; then echo "FAIL: credential-shaped string in the executable"; FAIL=1; fi37 if strings -a "$BIN" | grep -q "ORIX_DEV_ANTHROPIC_API_KEY"; then echo "FAIL: development credential adapter is present in this binary"; FAIL=1; else echo "ok: no development credential adapter"; fi38 if strings -a "$BIN" | grep -iE "maclustr|spboucher\.ai/|192\.168\.|\.internal\b" | head -3 | grep -q .; then echo "FAIL: internal host name in the executable"; FAIL=1; else echo "ok: no internal host names"; fi39 if find "$APP" -name "*.env" -o -name "*.p8" -o -name "*.p12" | grep -q .; then echo "FAIL: key material file in the bundle"; FAIL=1; fi40fi41[[ $FAIL -eq 0 ]] && echo "RESULT: clean" || echo "RESULT: FAILED"42exit $FAIL43