Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

ci: add privacy checks before commits and in Actions

RoversX6e78ef3fbfe5
diff --git a/.github/workflows/privacy.yml b/.github/workflows/privacy.yml
new file mode 100644
index 00000000..f229831b
--- /dev/null
+++ b/.github/workflows/privacy.yml
@@ -0,0 +1,26 @@
+name: privacy
+
+on:
+ push:
+ pull_request:
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: privacy-${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ check:
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+ - name: Test the guard
+ run: python3 -m unittest discover -s ci -p 'test_privacy_guard.py'
+ - name: Check tracked content
+ run: python3 ci/check-privacy.py --tree HEAD
diff --git a/.gitignore b/.gitignore
index 15146e88..1e9bedcc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -107,3 +107,21 @@ __pycache__/
/thinkterm-web/www/schemes.json
/thinkterm-web/www/*.gz
/thinkterm-web/ui/node_modules/
+
+# Local credentials and native release output. The privacy hook also rejects
+# these if they are force-added; ignore rules do not protect tracked files.
+.env
+.env.*
+!.env.example
+!.env.sample
+!.env.template
+*.p12
+*.pfx
+*.keystore
+*.jks
+*.apk
+*.aab
+*.ipa
+*.dmg
+
+!/ci/PRIVACY.md
diff --git a/ci/PRIVACY.md b/ci/PRIVACY.md
new file mode 100644
index 00000000..bffe97b5
--- /dev/null
+++ b/ci/PRIVACY.md
@@ -0,0 +1,42 @@
+# Privacy checks
+
+Install the local guard once per clone (Python 3 and Git are required):
+
+```sh
+python3 ci/install-privacy-hook.py
+```
+
+The installer preserves and chains any existing pre-commit hook, including
+GitButler's hook. Linked worktrees share the installation. The scanner is copied
+into Git's hooks directory so older branches still work; run the installer again
+after updating the scanner. Fresh clones do not inherit hooks automatically.
+
+Before committing, the guard reads the **complete Git index**, not the working
+files. A secret still staged will be rejected even if the working file has been
+cleaned. Fix the file, then stage the correction. Ignored, untracked local keys
+are not read. Matched secret values are never printed.
+
+```sh
+python3 ci/check-privacy.py --staged
+python3 ci/check-privacy.py --tree HEAD
+```
+
+Checks cover multiline private keys, selected credential token formats,
+embedded CI credentials, literal home directories, literal SSH IPv4 endpoints,
+local credential filenames, generated mobile build output, and release archives
+or app bundles. Use `alice`/`example` and documentation IPs such as `192.0.2.10`
+for fixtures. Existing public upstream examples and specific packaging template
+files have narrow exceptions in the scanner; do not add blanket exclusions for
+tests or source folders.
+
+The `privacy` Actions workflow checks the committed snapshot on pushes and pull
+requests without running a Rust/mobile build. Once installed on GitHub, its
+`check` job can be required in repository branch rules. CI is **after upload**;
+it cannot prevent a leaked commit from reaching GitHub. Local hooks can also be
+bypassed. This guard does not scan every historical commit, recurse into
+submodules, OCR images, inspect archives, or recognize every possible secret.
+Keep reviewing `git diff --cached` and any newly added files before committing.
+
+To uninstall locally, remove the managed `pre-commit` wrapper and restore
+`pre-commit.before-privacy-guard` to `pre-commit` if that backup exists. Keep the
+original hook; do not delete it as part of cleanup.
diff --git a/ci/check-privacy.py b/ci/check-privacy.py
new file mode 100644
index 00000000..d9c1b483
--- /dev/null
+++ b/ci/check-privacy.py
@@ -0,0 +1,155 @@
+#!/usr/bin/env python3
+"""Check Git blobs, never unstaged files. Requires only Python 3 and Git."""
+
+import argparse
+import ipaddress
+import json
+import re
+import subprocess
+import sys
+from pathlib import PurePosixPath
+
+
+SAMPLE_USERS = set(b"a ada alice b bob dev developer example me myname pi public root shared someone test testuser u user username x yourusername".split())
+# Existing public upstream examples; these are not blanket file exclusions.
+UPSTREAM_USERS = {
+ b"wez": ("docs/", "assets/", "wezterm-escape-parser/src/tmux_cc/mod.rs"),
+ b"alec": ("docs/config/plugins.md",),
+ b"joe": ("wezterm-escape-parser/src/tmux_cc/mod.rs",),
+ b"fred": ("wezterm-ssh/src/config.rs",),
+ b"garrus": ("assets/windows/mesa/opengl32.dll",),
+}
+APP_TEMPLATE = {
+ "assets/macos/ThinkTerm.app/Contents/Info.plist",
+ "assets/macos/ThinkTerm.app/Contents/Resources/ThinkTerm.icns",
+ "assets/macos/ThinkTerm.app/Contents/Resources/ThinkTerm_simple.icns",
+ "assets/macos/ThinkTerm.app/Contents/Resources/terminal.icns",
+ "assets/macos/ThinkTerm.app/libEGL.dylib",
+ "assets/macos/ThinkTerm.app/libGLESv1_CM.dylib",
+ "assets/macos/ThinkTerm.app/libGLESv2.dylib",
+ "assets/windows/conhost/OpenConsole.exe",
+}
+ARCHIVES = (".zip", ".tar.gz", ".tar.xz", ".tgz", ".dmg", ".apk", ".aab", ".ipa", ".deb", ".rpm", ".appimage", ".msi", ".exe")
+HOME = re.compile(rb"(?:/(?:Users|home)/|[A-Za-z]:[\\/]+Users[\\/]+)([A-Za-z_\x80-\xff][A-Za-z0-9_.\x80-\xff-]*)")
+# Match actual multiline key material, not the header strings used by SSH code.
+PRIVATE_KEY = re.compile(rb"-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY-----(?:\r?\n|\\n)(?:(?:Proc-Type:|DEK-Info:)[^\r\n]+\r?\n)*[\r\n]*(?:[A-Za-z0-9+/=]{32,})(?:\r?\n|\\n)")
+TOKENS = re.compile(rb"(?:gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{60,}|xox[baprs]-[A-Za-z0-9-]{20,}|sk-(?:proj-|ant-)[A-Za-z0-9_-]{32,}|AKIA[0-9A-Z]{16})")
+SSH_IP = re.compile(rb"ssh://[^\s/@\"'<>]+@((?:[0-9]{1,3}\.){3}[0-9]{1,3})(?=[:/\s\"'<>]|$)")
+DOCUMENTATION_NETS = tuple(ipaddress.ip_network(n) for n in ("192.0.2.0/24", "198.51.100.0/24", "203.0.113.0/24"))
+
+
+def git(*args):
+ return subprocess.check_output(["git", *args], stderr=subprocess.PIPE)
+
+
+def path_issues(path):
+ parts = PurePosixPath(path).parts
+ name = parts[-1].lower()
+ issues = set()
+ if path not in APP_TEMPLATE and (name.endswith(ARCHIVES) or any(p.lower().endswith(".app") for p in parts)):
+ issues.add("release-artifact: distribute packages outside Git")
+ if any(p in ("target", "XCBuildData", "DerivedData") for p in parts) or path.startswith(("ios/build/", "android/build/", "android/app/build/")):
+ issues.add("build-output: ignore generated files")
+ if (name.startswith(".env") and name not in (".env.example", ".env.sample", ".env.template")) or name in ("probe_key", "probe_user", "id_rsa", "id_dsa", "id_ecdsa", "id_ed25519", "local.xcconfig", "local.properties") or name.endswith((".p12", ".pfx", ".keystore", ".jks")):
+ issues.add("local-credentials: keep this file untracked")
+ return issues
+
+
+def content_issues(path, data):
+ issues = set()
+ if b"PRIVATE KEY-----" in data and PRIVATE_KEY.search(data):
+ issues.add("private-key: remove key material")
+ if any(marker in data for marker in (b"/Users/", b"/home/", b"Users\\", b"Users/")):
+ for match in HOME.finditer(data):
+ user = match[1].lower()
+ if user in SAMPLE_USERS:
+ continue
+ if any(path == prefix or (prefix.endswith("/") and path.startswith(prefix)) for prefix in UPSTREAM_USERS.get(user, ())):
+ continue
+ issues.add("personal-home: use an environment variable or an alice/example fixture")
+ # Binary assets are not interpreted as text tokens or endpoint examples.
+ if b"\0" not in data[:8000]:
+ if any(marker in data for marker in (b"gh", b"github_pat_", b"xox", b"sk-", b"AKIA")) and TOKENS.search(data):
+ issues.add("provider-token: remove the credential")
+ if b"ENCRYPTED" + b"[" in data:
+ issues.add("embedded-ci-credential: use repository secrets")
+ for match in SSH_IP.finditer(data):
+ try:
+ address = ipaddress.ip_address(match[1].decode("ascii"))
+ except ValueError:
+ continue
+ if not address.is_loopback and not any(address in net for net in DOCUMENTATION_NETS):
+ issues.add("ssh-endpoint: use a documentation IP in examples")
+ return issues
+
+
+def entries(tree=None):
+ if tree is None:
+ for row in git("ls-files", "--full-name", "--stage", "-z", "--", ":/").split(b"\0"):
+ if not row:
+ continue
+ meta, path = row.split(b"\t", 1)
+ mode, oid, stage = meta.split()
+ if stage != b"0":
+ raise ValueError("Resolve unmerged index entries before running the privacy check")
+ if mode != b"160000": # Submodules are separate repositories.
+ yield path.decode("utf-8", "surrogateescape"), oid
+ else:
+ tree_id = git("rev-parse", "--verify", "--end-of-options", tree + "^{tree}").strip().decode("ascii")
+ for row in git("ls-tree", "--full-tree", "-r", "-z", tree_id).split(b"\0"):
+ if not row:
+ continue
+ meta, path = row.split(b"\t", 1)
+ mode, kind, oid = meta.split()
+ if kind == b"blob":
+ yield path.decode("utf-8", "surrogateescape"), oid
+
+
+def check(tree=None):
+ failures = 0
+ count = 0
+ with subprocess.Popen(["git", "cat-file", "--batch"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) as batch:
+ try:
+ for path, oid in entries(tree):
+ batch.stdin.write(oid + b"\n")
+ batch.stdin.flush()
+ header = batch.stdout.readline().split()
+ if len(header) != 3 or header[1] != b"blob":
+ raise ValueError("Unable to read a Git blob")
+ size = int(header[2])
+ data = batch.stdout.read(size)
+ if len(data) != size or batch.stdout.read(1) != b"\n":
+ raise ValueError("Incomplete Git blob")
+ issues = path_issues(path) | content_issues(path, data)
+ count += 1
+ for issue in sorted(issues):
+ # No matched values, snippets or key material in terminal/CI logs.
+ print("privacy:", json.dumps(path), "-", issue, file=sys.stderr)
+ failures += 1
+ finally:
+ batch.stdin.close()
+ batch.stdout.close()
+ if batch.wait() != 0:
+ raise ValueError("Git blob reader failed")
+ if failures:
+ print(f"Privacy check blocked: {failures} finding(s). Fix and re-stage the files.", file=sys.stderr)
+ return 1
+ print(f"Privacy check passed: {count} Git blobs checked.")
+ return 0
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ mode = parser.add_mutually_exclusive_group()
+ mode.add_argument("--staged", action="store_true", help="check the complete index (default)")
+ mode.add_argument("--tree", help="check a committed tree, e.g. HEAD")
+ args = parser.parse_args()
+ try:
+ return check(args.tree)
+ except (OSError, ValueError, subprocess.CalledProcessError):
+ print("Privacy check could not complete; commit blocked. Check Python 3, Git and the index.", file=sys.stderr)
+ return 2
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/ci/install-privacy-hook.py b/ci/install-privacy-hook.py
new file mode 100644
index 00000000..3ecddca0
--- /dev/null
+++ b/ci/install-privacy-hook.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+"""Install a local hook while preserving an existing pre-commit hook."""
+
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import sys
+
+MARKER = "# THINKTERM_PRIVACY_GUARD_V1"
+WRAPPER = '''#!/bin/sh
+# THINKTERM_PRIVACY_GUARD_V1
+set -eu
+hooks_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
+python3 "$hooks_dir/thinkterm-privacy-guard.py" --staged
+if [ -x "$hooks_dir/pre-commit.before-privacy-guard" ]; then
+ exec "$hooks_dir/pre-commit.before-privacy-guard" "$@"
+fi
+'''
+
+
+def main():
+ raw = subprocess.check_output(["git", "rev-parse", "--git-path", "hooks/pre-commit"], text=True).strip()
+ hook = Path(os.path.abspath(raw))
+ backup = hook.with_name("pre-commit.before-privacy-guard")
+ scanner = hook.with_name("thinkterm-privacy-guard.py")
+ managed = hook.is_file() and MARKER in hook.read_text(errors="replace")
+ if os.path.lexists(hook) and not managed and os.path.lexists(backup):
+ sys.exit("Existing hook and backup both present; refusing to overwrite either.")
+ hook.parent.mkdir(parents=True, exist_ok=True)
+ # Keep a local copy: linked worktrees on older branches may lack ci/ scripts.
+ scanner_temp = scanner.with_name("thinkterm-privacy-guard.py.new")
+ shutil.copyfile(Path(__file__).with_name("check-privacy.py"), scanner_temp)
+ scanner_temp.replace(scanner)
+ if os.path.lexists(hook) and not managed:
+ hook.rename(backup)
+ temp = hook.with_name("pre-commit.privacy-new")
+ temp.write_text(WRAPPER)
+ temp.chmod(0o755)
+ temp.replace(hook)
+ print("Privacy hook installed. Existing hook preserved and chained.")
+ print("Linked worktrees share this hook. Re-run this installer after scanner updates.")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/ci/test_privacy_guard.py b/ci/test_privacy_guard.py
new file mode 100644
index 00000000..ef2e712d
--- /dev/null
+++ b/ci/test_privacy_guard.py
@@ -0,0 +1,159 @@
+"""Exercise real Git indexes and hook chaining without touching the caller's repo."""
+
+import importlib.util
+import os
+from pathlib import Path
+import subprocess
+import sys
+import tempfile
+import unittest
+
+CI = Path(__file__).resolve().parent
+SPEC = importlib.util.spec_from_file_location("privacy_guard", CI / "check-privacy.py")
+GUARD = importlib.util.module_from_spec(SPEC)
+SPEC.loader.exec_module(GUARD)
+
+
+def personal_path():
+ # Build synthetic rejected data at runtime; do not commit a real identity.
+ return b"/Users/" + b"synthetic-private-person" + b"/project"
+
+
+class Rules(unittest.TestCase):
+ def test_native_and_escaped_windows_paths(self):
+ for data in (personal_path(), b"C:\\Users\\" + b"synthetic-person\\work", b"C:\\\\Users\\\\" + b"synthetic-person\\\\work"):
+ self.assertTrue(GUARD.content_issues("example.rs", data))
+ self.assertFalse(GUARD.content_issues("example.rs", b"/Users/alice/project /home/example/app"))
+
+ def test_keys_and_runtime_header_strings(self):
+ header = b"-----BEGIN " + b"OPENSSH PRIVATE KEY-----"
+ self.assertTrue(GUARD.content_issues("key.txt", header + b"\n" + b"A" * 64 + b"\n"))
+ self.assertTrue(GUARD.content_issues("key.json", header + b"\\n" + b"A" * 64 + b"\\n"))
+ self.assertTrue(GUARD.content_issues("key.pem", header + b"\nProc-Type: 4,ENCRYPTED\nDEK-Info: AES-256-CBC,example\n\n" + b"A" * 64 + b"\n"))
+ self.assertFalse(GUARD.content_issues("key.rs", b'let header = "' + header + b'\\n";'))
+
+ def test_token_and_ci_credentials(self):
+ for data in (b"ghp" + b"_" + b"A" * 36, b"ENCRYPTED" + b"[fake-ciphertext]"):
+ self.assertTrue(GUARD.content_issues("settings.txt", data))
+
+ def test_endpoint_examples(self):
+ prefix = b"ssh://alice@"
+ self.assertTrue(GUARD.content_issues("test.rs", prefix + b"10.8.9.10"))
+ for ip in (b"192.0.2.10", b"198.51.100.8", b"203.0.113.1", b"127.0.0.1"):
+ self.assertFalse(GUARD.content_issues("test.rs", prefix + ip))
+
+ def test_packaging_template_is_not_a_blanket_exemption(self):
+ self.assertFalse(GUARD.path_issues("assets/macos/ThinkTerm.app/Contents/Info.plist"))
+ self.assertTrue(GUARD.path_issues("assets/macos/ThinkTerm.app/Contents/MacOS/thinkterm"))
+ self.assertTrue(GUARD.path_issues("release/My App.app/Contents/MacOS/app"))
+ self.assertTrue(GUARD.path_issues("release/output.zip"))
+ self.assertTrue(GUARD.path_issues("ios/build/XCBuildData/manifest.json"))
+
+ def test_upstream_exception_is_scoped(self):
+ data = b"/home/" + b"wez/code"
+ self.assertFalse(GUARD.content_issues("docs/config/fonts.md", data))
+ self.assertTrue(GUARD.content_issues("new-test.rs", data))
+
+ def test_credential_filenames_and_templates(self):
+ for path in (".env", ".env.local", "keys/id_ed25519", "signing.p12", "android/local.properties"):
+ self.assertTrue(GUARD.path_issues(path))
+ self.assertFalse(GUARD.path_issues(".env.example"))
+ self.assertFalse(GUARD.path_issues("keys/id_ed25519.pub"))
+
+
+class GitIntegration(unittest.TestCase):
+ def setUp(self):
+ self.temp = tempfile.TemporaryDirectory()
+ self.repo = Path(self.temp.name)
+ self.env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
+ self.env.update(GIT_CONFIG_NOSYSTEM="1", GIT_CONFIG_GLOBAL=os.devnull)
+ self.git("init", "-q")
+ self.git("config", "user.name", "Privacy tests")
+ self.git("config", "user.email", "[email protected]")
+
+ def tearDown(self):
+ self.temp.cleanup()
+
+ def run_command(self, args):
+ return subprocess.run(args, cwd=self.repo, env=self.env, capture_output=True)
+
+ def git(self, *args):
+ result = self.run_command(["git", *args])
+ self.assertEqual(result.returncode, 0, result.stderr.decode(errors="replace"))
+ return result.stdout
+
+ def scan(self, *args):
+ return self.run_command([sys.executable, str(CI / "check-privacy.py"), *args])
+
+ def test_scans_staged_bytes_and_redacts_values(self):
+ path = self.repo / "settings.txt"
+ secret = b"ghp" + b"_" + b"A" * 36
+ path.write_bytes(secret + b"\n" + personal_path())
+ self.git("add", "settings.txt")
+ path.write_text("clean working file\n")
+ result = self.scan("--staged")
+ self.assertEqual(result.returncode, 1)
+ self.assertNotIn(secret, result.stdout + result.stderr)
+ self.assertNotIn(personal_path(), result.stdout + result.stderr)
+ self.assertIn(b"settings.txt", result.stderr)
+ self.git("add", "settings.txt")
+ self.assertEqual(self.scan().returncode, 0)
+
+ def test_unstaged_and_untracked_data_are_not_uploaded(self):
+ path = self.repo / "settings.txt"
+ path.write_text("safe\n")
+ self.git("add", "settings.txt")
+ path.write_bytes(personal_path())
+ (self.repo / "probe_key").write_bytes(personal_path())
+ self.assertEqual(self.scan().returncode, 0)
+
+ def test_force_added_artifact_is_blocked_then_deletion_passes(self):
+ (self.repo / ".gitignore").write_text("*.zip\n")
+ (self.repo / "release file.zip").write_bytes(b"PK\0dummy")
+ self.git("add", ".gitignore")
+ self.git("add", "-f", "release file.zip")
+ self.assertEqual(self.scan().returncode, 1)
+ self.git("rm", "--cached", "release file.zip")
+ self.assertEqual(self.scan().returncode, 0)
+
+ def test_tree_mode_ignores_working_changes(self):
+ (self.repo / "test.txt").write_text("safe\n")
+ self.git("add", "test.txt")
+ self.git("commit", "-qm", "Add safe fixture")
+ (self.repo / "test.txt").write_bytes(personal_path())
+ self.git("add", "test.txt")
+ self.assertEqual(self.scan("--tree", "HEAD").returncode, 0)
+ self.assertEqual(self.scan("--staged").returncode, 1)
+
+ def test_running_from_subdirectory_still_checks_root(self):
+ (self.repo / "settings.txt").write_bytes(personal_path())
+ self.git("add", "settings.txt")
+ nested = self.repo / "nested"
+ nested.mkdir()
+ result = subprocess.run([sys.executable, str(CI / "check-privacy.py"), "--staged"], cwd=nested, env=self.env, capture_output=True)
+ self.assertEqual(result.returncode, 1)
+ self.assertIn(b"settings.txt", result.stderr)
+
+ def test_installer_preserves_hook_and_works_on_old_branches(self):
+ hooks = self.repo / ".git" / "hooks"
+ hook = hooks / "pre-commit"
+ original = '#!/bin/sh\nprintf chained > hook-ran\nexit 9\n'
+ hook.write_text(original)
+ hook.chmod(0o755)
+ install = [sys.executable, str(CI / "install-privacy-hook.py")]
+ self.assertEqual(self.run_command(install).returncode, 0)
+ self.assertEqual(self.run_command(install).returncode, 0)
+ self.assertEqual((hooks / "pre-commit.before-privacy-guard").read_text(), original)
+ # There is no ci/ directory in this throwaway repo: use the installed copy.
+ result = self.run_command([str(hook)])
+ self.assertEqual(result.returncode, 9)
+ self.assertEqual((self.repo / "hook-ran").read_text(), "chained")
+ (self.repo / "hook-ran").unlink()
+ (self.repo / "settings.txt").write_bytes(personal_path())
+ self.git("add", "settings.txt")
+ self.assertEqual(self.run_command([str(hook)]).returncode, 1)
+ self.assertFalse((self.repo / "hook-ran").exists())
+
+
+if __name__ == "__main__":
+ unittest.main()