Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(security): distinguish capture source from private artifacts

Alfredo Lopezb57daff1497b
diff --git a/scripts/tests/test-minikube-t2-public-boundary.sh b/scripts/tests/test-minikube-t2-public-boundary.sh
index 771ac142f..c4d15eb37 100755
--- a/scripts/tests/test-minikube-t2-public-boundary.sh
+++ b/scripts/tests/test-minikube-t2-public-boundary.sh
@@ -38,14 +38,38 @@ while IFS= read -r -d '' path; do
sed 's/^/+/' "$ROOT/$path"
done >>"$tmp"
-python3 - "$tmp" <<'PY'
+python3 - "$tmp" "$ROOT" <<'PY'
from pathlib import Path
import re
+import shlex
import sys
diff = Path(sys.argv[1]).read_text(errors="replace")
bad = []
current = ""
+root = Path(sys.argv[2]).resolve()
+
+
+def public_capture_source(relative):
+ # Test/config source may describe screenshots. This never exempts its added
+ # contents from the credential/private-URL checks below.
+ candidate = Path(relative)
+ if not re.search(r"\.(?:spec|test|config)\.(?:ts|tsx|js|mjs|cjs)$", candidate.name, re.I):
+ return False
+ if not any(part in {"src", "test", "tests"} for part in candidate.parts):
+ return False
+ filename = root / candidate
+ try:
+ if filename.is_symlink() or not filename.resolve().is_relative_to(root):
+ return False
+ raw = filename.read_bytes()
+ if len(raw) > 1024 * 1024 or any(byte < 32 and byte not in {9, 10, 13} for byte in raw):
+ return False
+ text = raw.decode("utf-8")
+ except (OSError, UnicodeError):
+ return False
+ return bool(re.search(r"(?m)^\s*(?:import\s|export\s|(?:const|let|var|type|interface|class|function)\s|(?:test|describe)\s*[.(])", text))
+
safe_source_paths = {
"control-api/src/routes/admin/communicationchannelcredentials.ts",
"control-api/test/routes.admincommunicationchannelcredentials.test.ts",
@@ -60,8 +84,21 @@ safe_source_paths = {
"deploy/scripts/reconcile-gfs-deploy-credentials.sh",
}
for line in diff.splitlines():
- if line.startswith("+++ b/"):
- current = line[6:]
+ changed_path = None
+ if line.startswith("diff --git "):
+ try:
+ headers = shlex.split(line[len("diff --git "):])
+ except ValueError:
+ bad.append(("<diff>", "malformed path header"))
+ continue
+ if len(headers) != 2 or not headers[1].startswith("b/"):
+ bad.append(("<diff>", "malformed path header"))
+ continue
+ changed_path = headers[1][2:]
+ elif line.startswith("+++ b/"):
+ changed_path = line[6:]
+ if changed_path is not None:
+ current = changed_path
path = current.lower()
path_parts = path.split("/")
if (
@@ -76,11 +113,13 @@ for line in diff.splitlines():
)
and path not in safe_source_paths
)
- or "screenshot" in path
+ or ("screenshot" in path and not public_capture_source(current))
or "e2e-artifacts" in path
):
if not (path.endswith(".env.example") or path.endswith(".env.test")):
- bad.append((current, "sensitive file name"))
+ finding = (current, "sensitive file name")
+ if finding not in bad:
+ bad.append(finding)
continue
if not line.startswith("+") or line.startswith("+++"):
continue
diff --git a/scripts/tests/test-minikube-t2-public-source-contract.sh b/scripts/tests/test-minikube-t2-public-source-contract.sh
new file mode 100644
index 000000000..93a5f70dc
--- /dev/null
+++ b/scripts/tests/test-minikube-t2-public-source-contract.sh
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+# Hermetic public-source/capture classification; fixtures never touch the host checkout.
+set -euo pipefail
+ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd -P)"
+source "$ROOT/scripts/tests/lib/minikube-fixture-repo.sh"
+fixture_tmp="$(mktemp -d "${TMPDIR:-/tmp}/evenfire-public-source.XXXXXX")"
+cleanup() {
+ local status=$?
+ minikube_test_assert_host_unchanged || status=1
+ rm -rf -- "$fixture_tmp"
+ exit "$status"
+}
+trap cleanup EXIT
+minikube_test_fixture_repo_init "$ROOT" "$fixture_tmp"
+repo="$MINIKUBE_TEST_PROJECT_DIR"
+failures=0
+cases=0
+check_case() {
+ local label="$1" expected="$2" code=0
+ T2_PUBLIC_ROOT="$repo" T2_PUBLIC_BASE_REF=origin/dev \
+ bash "$ROOT/scripts/tests/test-minikube-t2-public-boundary.sh" \
+ >"$fixture_tmp/output" 2>&1 || code=$?
+ cases=$((cases + 1))
+ if [[ "$expected" == pass && "$code" != 0 ]] ||
+ [[ "$expected" == reject && "$code" == 0 ]]; then
+ printf 'FAIL: %s (exit %s)\n' "$label" "$code" >&2
+ failures=$((failures + 1))
+ fi
+ rm -rf -- "$repo/tests"
+}
+mkdir -p "$repo/tests/e2e"
+printf "import { test } from 'node:test'\ntest('public screenshots', () => {})\n" \
+ >"$repo/tests/e2e/public-screenshot.spec.ts"
+check_case 'public screenshot spec' pass
+mkdir -p "$repo/tests/e2e"
+printf "export default { name: 'public screenshot configuration' }\n" \
+ >"$repo/tests/e2e/playwright-screenshot.config.ts"
+check_case 'public screenshot config' pass
+if [[ "${1:-}" != --source-only ]]; then
+ mkdir -p "$repo/tests/e2e/screenshots"
+ printf '\211PNG\r\n\032\n\000unit' >"$repo/tests/e2e/screenshots/private-capture.png"
+ check_case 'private capture artifact' reject
+ mkdir -p "$repo/tests/e2e"
+ printf '\211PNG\r\n\032\n\000unit' >"$repo/tests/e2e/capture-screenshot.spec.ts"
+ check_case 'binary disguised as source' reject
+fi
+if (( failures )); then
+ printf 'PUBLIC_SOURCE_CONTRACT_FAIL: %s/%s\n' "$failures" "$cases" >&2
+ exit 1
+fi
+printf 'PUBLIC_SOURCE_CONTRACT_PASS: %s cases\n' "$cases"