Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

fix(oss): close scanner gaps (env assignments, non-UTF-8, more home-path shapes), exact email allow-list, readable non-checkout error

eyalgolanfb6f208f06c3
diff --git a/scripts/oss/check_repo.py b/scripts/oss/check_repo.py
index 938a96b9d..c3bffee9d 100755
--- a/scripts/oss/check_repo.py
+++ b/scripts/oss/check_repo.py
@@ -63,12 +63,14 @@ def _text(root: Path, rel: str) -> str | None:
if p.is_symlink() or not p.is_file():
return None
data = p.read_bytes()
+ if data[:2] in (b"\xff\xfe", b"\xfe\xff"):
+ return data.decode("utf-16", errors="replace") # UTF-16 text has NULs; the BOM says it is text
if b"\0" in data[:8192]:
return None
try:
return data.decode("utf-8")
except UnicodeDecodeError:
- return None
+ return data.decode("latin-1") # never skip a text file whole
def _line_check(name: str, fn: Callable[[str], list[str]]):
@@ -209,7 +211,11 @@ def main(argv: list[str] | None = None) -> int:
print(f"unknown check(s): {', '.join(unknown)}; known: {', '.join(CHECKS)}")
return 2
root = args.root.resolve()
- files = tracked_files(root)
+ try:
+ files = tracked_files(root)
+ except (subprocess.CalledProcessError, FileNotFoundError):
+ print("not a git checkout (or git refused it): run from a clone", file=sys.stderr)
+ return 2
findings = [f for n in names for f in CHECKS[n](root, files, args.release)]
findings = apply_allowlist(root, findings, names)
for f in findings:
diff --git a/scripts/oss/oss_policy.py b/scripts/oss/oss_policy.py
index d93059df5..e5f76d2e0 100755
--- a/scripts/oss/oss_policy.py
+++ b/scripts/oss/oss_policy.py
@@ -17,6 +17,9 @@ SECRET_PATTERNS: dict[str, re.Pattern[str]] = {
"jwt": re.compile(r"\beyJ[A-Za-z0-9_\-]{10,}\.[A-Za-z0-9_\-]{10,}\.[A-Za-z0-9_\-]{10,}"),
"secret-assignment": re.compile(
r"(?i)(?:api[_-]?key|secret|token|passw(?:or)?d)['\"]?\s*[:=]\s*['\"][A-Za-z0-9_\-/+=]{16,}['\"]"),
+ # The unquoted shell / .env shape: export OPENAI_API_KEY=<value> (review I4).
+ "env-assignment": re.compile(
+ r"(?:^|[^A-Za-z0-9_])[A-Z0-9_]*(?:API_?KEY|SECRET|TOKEN|PASSWORD)[A-Z0-9_]*[ \t]*[:=][ \t]*[A-Za-z0-9_/+=-]{16,}"),
# Unity writes these into ProjectSettings.asset when the project is linked to Unity Cloud. Empty is fine. The value
# shapes are narrow on purpose (a GUID; a slug that ends the line) so that this file and its tests, which mention
# the keys, do not match themselves.
@@ -28,10 +31,11 @@ SECRET_PATTERNS: dict[str, re.Pattern[str]] = {
# The local part must start with a letter or digit (so "@pytest.mark" is not an address), and the last domain label
# must be letters only (so a Unity package id such as "[email protected]" is not an address).
EMAIL = re.compile(r"(?<![\w.+-])[A-Za-z0-9][A-Za-z0-9._%+\-]*@((?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,})(?![\w.-])")
-ALLOWED_EMAIL_DOMAINS = frozenset({"users.noreply.github.com", "anthropic.com", "example.com", "example.org",
- "example.net"})
+ALLOWED_EMAIL_DOMAINS = frozenset({"users.noreply.github.com", "example.com", "example.org", "example.net"})
+ALLOWED_EMAILS = frozenset({"[email protected]", "[email protected]"}) # exact addresses, never a whole domain
-HOME_PATH = re.compile(r"(?:/Users/(?!Shared/)|/home/)[A-Za-z][\w.\-]*/")
+HOME_PATH = re.compile(
+ r"(?:/Users/(?!Shared\b)|/home/)[A-Za-z][\w.\-]*(?:/|\b)|[A-Za-z]:\\Users\\[A-Za-z]|-Users-[a-z][\w.]*-")
MAX_FILE_BYTES = 10 * 1024 * 1024
@@ -68,8 +72,7 @@ def secret_kinds(line: str) -> list[str]:
def email_kinds(line: str) -> list[str]:
for m in EMAIL.finditer(line):
domain = m.group(1).lower()
- local = m.group(0).split("@", 1)[0].lower()
- if domain in ALLOWED_EMAIL_DOMAINS or local == "noreply":
+ if domain in ALLOWED_EMAIL_DOMAINS or m.group(0).lower() in ALLOWED_EMAILS:
continue
return ["personal-email"]
return []
diff --git a/scripts/oss/tests/test_check_repo.py b/scripts/oss/tests/test_check_repo.py
index ae7741ba9..788e5ca0c 100644
--- a/scripts/oss/tests/test_check_repo.py
+++ b/scripts/oss/tests/test_check_repo.py
@@ -130,3 +130,46 @@ def test_release_mode_refuses_open_decisions(make_repo, capsys):
def test_unknown_check_name_is_an_error(make_repo, capsys):
root = make_repo({"a.txt": "x\n"})
assert run(root, "--only", "nonsense") == 2
+
+
+# Review I4: scanner gaps.
+def test_unquoted_env_assignment_is_a_secret(make_repo, capsys):
+ value = "q" * 40
+ root = make_repo({"setup.sh": "export OPENAI_" + f"API_KEY={value}\n", "ok.sh": "export OPENAI_API_KEY=$KEY\n"})
+ assert run(root, "--only", "secrets") == 1
+ out = capsys.readouterr().out
+ assert "secrets: setup.sh:1: env-assignment" in out and "ok.sh" not in out and value not in out
+
+
+def test_non_utf8_and_utf16_files_are_still_scanned(make_repo, capsys):
+ aws = "AKIA" + "ABCDEFGHIJ" + "123456"
+ mail = "someone" + "@" + "gmail.com"
+ latin = f"caf\xe9 {aws}\n{mail}\n".encode("latin-1")
+ utf16 = f"{aws}\n".encode("utf-16")
+ root = make_repo({"latin.txt": latin, "wide.txt": utf16})
+ assert run(root, "--only", "secrets,emails") == 1
+ out = capsys.readouterr().out
+ assert "secrets: latin.txt:1: aws-access-key-id" in out and "emails: latin.txt:2: personal-email" in out
+ assert "secrets: wide.txt:1: aws-access-key-id" in out
+
+
+def test_more_personal_path_shapes_are_home_paths(make_repo, capsys):
+ root = make_repo({"a.md": "cd /Users/" + "someone\n", "b.md": "C:\\Users\\" + "someone\\x\n",
+ "c.md": "see -Users-" + "someone-israel-game\n", "d.md": "/Users/Shared and ~/x\n"})
+ assert run(root, "--only", "home-paths") == 1
+ out = capsys.readouterr().out
+ for f in ("a.md", "b.md", "c.md"):
+ assert f"home-paths: {f}:1: home-path" in out
+ assert "d.md" not in out
+
+
+def test_email_allowlist_is_exact_addresses_not_whole_domains(make_repo, capsys):
+ root = make_repo({"a.md": "Claude <noreply" + "@" + "anthropic.com>\n", "b.md": "x" + "@" + "anthropic.com\n"})
+ assert run(root, "--only", "emails") == 1
+ out = capsys.readouterr().out
+ assert "b.md:1: personal-email" in out and "a.md" not in out
+
+
+def test_outside_a_checkout_is_a_readable_error_not_a_traceback(tmp_path, capsys):
+ assert run(tmp_path) == 2
+ assert "not a git checkout" in capsys.readouterr().err