counterlure-cli 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -211,6 +211,19 @@ counterlure fingerprint photo.jpg --token # send that one fingerprint, print
211
211
 
212
212
  This is for the Counterlure Agent Exchange (`check_contact` on `https://mcp.counterlure.com/mcp`, or the `counterlure-mcp` package). Without `--token` nothing goes over the network: the face is found and measured on this machine, and the 128 numbers are printed for an assistant to send. With `--token`, the fingerprint goes over the usual route (the onion service by default), never the photo. You get back a code that an assistant can pass instead of the numbers. No account is needed.
213
213
 
214
+ ## Inspecting a repo before you run it (anyone, offline)
215
+
216
+ ```bash
217
+ counterlure inspect ./take-home # readable report
218
+ counterlure inspect ./take-home --json # { verdict, findings: [{ severity, indicator, file, detail }] }
219
+ ```
220
+
221
+ For the "Contagious Interview" pattern: a recruiter or a new contact sends a take-home or a "quick bug fix" repo that runs code the moment you open it in your editor or run `npm install`. `inspect` reads the files and flags what would run, without running anything, following symlinks or sending a byte. It works on a fresh clone or an unzipped archive, including private repos that can't go to an online scanner.
222
+
223
+ It looks for VS Code and Cursor folder-open tasks and `task.allowAutomaticTasks`, `preLaunchTask`, npm lifecycle hooks (in every workspace's `package.json`) and the files they run, git and tarball dependencies, names one letter away from popular packages, `.npmrc` registry and shell overrides, `yarnPath`, dev container commands (`initializeCommand` runs on your machine, not in the container), Makefiles that download or eval, `setup.py` and in-repo Python build backends, `build.rs`, `.envrc`, submodules, hook managers, already-installed `.git/hooks` and `core.hooksPath`/`fsmonitor`, code that writes into `.git/hooks`, decode-then-`eval`, fetch-then-`new Function`, base64 strings that hide URLs, symlinks pointing outside the repo, bundled binaries, and instructions to turn off antivirus, Defender or Gatekeeper.
224
+
225
+ Exit code `0` means no known traps, `1` review first, `2` do not run. No known traps is not proof of safety: still open unfamiliar code in a container or VM.
226
+
214
227
  ## Messages to the team (members)
215
228
 
216
229
  ```bash
@@ -24,6 +24,7 @@ import { SERVER_FINGERPRINT } from '../lib/server-key.js';
24
24
  import { ONION, SITE, resolveRoute } from '../lib/route.js';
25
25
  import { request } from '../lib/net.js';
26
26
  import { out, say } from '../lib/term.js';
27
+ import { inspectDir, renderInspect } from '../lib/inspect.js';
27
28
 
28
29
  const VERSION = JSON.parse(fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8')).version;
29
30
  const CONTEXTS = ['dating-app', 'social-media', 'event-or-conference', 'work-or-business', 'introduced', 'other'];
@@ -41,6 +42,12 @@ Query and contribute to the Counterlure watchlist of faces tied to suspected app
41
42
  against people in tech. Traffic goes to Counterlure's onion service over Tor, and every request is
42
43
  OpenPGP-encrypted to a pinned key and padded to a fixed size.
43
44
 
45
+ Repositories (offline, nothing is sent or executed)
46
+ inspect [DIR] Read a repo you were sent (a take-home, a "fix this bug" invite) before you
47
+ open, install or build it. Flags folder-open tasks, install hooks, dev
48
+ container commands, git hooks, typosquats, hidden URLs, remote eval and
49
+ "turn off your antivirus" instructions. Exit 0 clean, 1 review, 2 do not run.
50
+
44
51
  Account
45
52
  signup [--user NAME] Open an account: pick a username, link an authenticator app, pay in
46
53
  [--plan P] crypto. No email, phone or name is asked for. Resumes where it stopped.
@@ -1041,6 +1048,15 @@ async function main() {
1041
1048
  if (o.version) return out(VERSION);
1042
1049
  if (o.help || !cmd) return process.stdout.write(HELP);
1043
1050
 
1051
+ if (cmd === 'inspect') {
1052
+ const dir = rest[0] || '.';
1053
+ const r = inspectDir(dir);
1054
+ if (o.json) process.stdout.write(JSON.stringify(r, null, 2) + '\n');
1055
+ else out(renderInspect(r));
1056
+ process.exitCode = r.verdict === 'do_not_run' ? 2 : r.verdict === 'review_first' ? 1 : 0;
1057
+ return;
1058
+ }
1059
+
1044
1060
  if (cmd === 'key') {
1045
1061
  out([
1046
1062
  'Pinned Counterlure CLI key fingerprint:',
package/lib/inspect.js ADDED
@@ -0,0 +1,226 @@
1
+ // Static, offline inspection of a local repository before you open, install, build or run it.
2
+ // Reads files only: nothing is executed, nothing is sent anywhere, symlinks are never followed.
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+
6
+ const MAX_FILES = 5000;
7
+ const MAX_BYTES = 512 * 1024;
8
+ const SKIP_DIRS = new Set(['node_modules', '.venv', 'venv', '__pycache__', 'target', '.next', '.tox']);
9
+ const TEXT_EXT = /\.(?:[cm]?[jt]sx?|json|ya?ml|toml|py|sh|bash|zsh|ps1|psm1|bat|cmd|rb|md|txt|cfg|ini|rs|go|mk)$/i;
10
+ const CODE_EXT = /\.(?:[cm]?[jt]sx?|py|sh|bash|zsh|ps1|psm1|bat|cmd|rb)$/i;
11
+ const BINARY_EXT = /\.(?:exe|dll|dylib|so|node|wasm|msi|dmg|pkg|scr|bat|vbs|jar|lnk|appimage)$/i;
12
+
13
+ const EXEC = /(?:curl\s+|wget\s+|powershell|pwsh|cmd\.exe|\/bin\/sh|bash\s+-c|node\s+-e|python3?\s+-c|\beval\s*\(|new\s+Function\s*\(|child_process|Buffer\.from\s*\([^)]*base64|atob\s*\(|os\.system\s*\(|subprocess\.|Invoke-Expression|\biex\b)/i;
14
+ const PIPE_TO_SHELL = /(?:curl|wget|iwr|Invoke-WebRequest)\b[^\n|]*\|\s*(?:sudo\s+)?(?:sh|bash|zsh|iex|python3?|node)\b/i;
15
+ const LIFECYCLE = ['preinstall', 'install', 'postinstall', 'preprepare', 'prepare', 'postprepare', 'prepublish', 'prepack', 'postpack'];
16
+ const NON_REGISTRY = /^(?:git\+|git:|github:|gitlab:|bitbucket:|gist:|https?:\/\/|file:|link:)|\.t(?:ar\.)?gz(?:[#?].*)?$/i;
17
+ const POPULAR = ['express', 'lodash', 'react', 'react-dom', 'axios', 'chalk', 'commander', 'debug', 'dotenv', 'request', 'moment',
18
+ 'webpack', 'typescript', 'eslint', 'jest', 'mocha', 'vue', 'next', 'mongoose', 'cors', 'body-parser', 'jsonwebtoken', 'bcrypt',
19
+ 'uuid', 'yargs', 'colors', 'async', 'underscore', 'socket.io', 'nodemon', 'prettier', 'ethers', 'web3', 'puppeteer', 'electron',
20
+ 'sharp', 'dayjs', 'zod', 'vite', 'redux', 'nodemailer', 'mysql', 'pg', 'redis', 'ws', 'cheerio', 'inquirer', 'semver', 'glob'];
21
+ const DISABLE_SECURITY = /(?:(?:disable|turn off|switch off|deactivate|pause)\s+(?:your\s+|the\s+|windows\s+)?(?:anti-?virus|defender|edr|endpoint protection|firewall|gatekeeper|smartscreen|real-?time protection|sip\b)|Set-MpPreference|Add-MpPreference\s+-ExclusionPath|xattr\s+-[a-z]*d[a-z]*\s+com\.apple\.quarantine|spctl\s+--master-disable|csrutil\s+disable)/i;
22
+
23
+ // Damerau-Levenshtein distance, capped (we only care about 0, 1 and "more").
24
+ function distance(a, b) {
25
+ if (Math.abs(a.length - b.length) > 1) return 2;
26
+ const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
27
+ for (let j = 1; j <= b.length; j++) d[0][j] = j;
28
+ for (let i = 1; i <= a.length; i++) {
29
+ for (let j = 1; j <= b.length; j++) {
30
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
31
+ d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
32
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
33
+ }
34
+ }
35
+ return d[a.length][b.length];
36
+ }
37
+
38
+ export function typosquatOf(name) {
39
+ if (typeof name !== 'string' || name.startsWith('@') || POPULAR.includes(name) || name.length < 4) return null;
40
+ return POPULAR.find((p) => p.length >= 4 && distance(name, p) === 1) || null;
41
+ }
42
+
43
+ // Decode quoted base64 literals of 16+ chars; return the ones that decode to readable text.
44
+ function hiddenStrings(text) {
45
+ const out = [];
46
+ for (const m of text.matchAll(/(['"`])([A-Za-z0-9+/]{16,}={0,2})\1/g)) {
47
+ const s = Buffer.from(m[2], 'base64').toString('utf8');
48
+ if (/^[\x20-\x7e\s]{8,}$/.test(s)) out.push(s);
49
+ if (out.length >= 20) break;
50
+ }
51
+ return out;
52
+ }
53
+
54
+ const clip = (s, n = 160) => String(s).replace(/\s+/g, ' ').trim().slice(0, n);
55
+
56
+ // Walk the tree without following symlinks. .git is skipped except for hooks and config.
57
+ function walk(root) {
58
+ const files = [];
59
+ const links = [];
60
+ let truncated = false;
61
+ const stack = [''];
62
+ while (stack.length) {
63
+ const rel = stack.pop();
64
+ let entries;
65
+ try { entries = fs.readdirSync(path.join(root, rel), { withFileTypes: true }); } catch { continue; }
66
+ for (const e of entries) {
67
+ const p = rel ? `${rel}/${e.name}` : e.name;
68
+ if (e.isSymbolicLink()) { links.push(p); continue; }
69
+ if (e.isDirectory()) {
70
+ if (SKIP_DIRS.has(e.name)) continue;
71
+ if (p === '.git') {
72
+ for (const sub of ['hooks']) {
73
+ try { for (const h of fs.readdirSync(path.join(root, '.git', sub), { withFileTypes: true })) if (h.isFile()) files.push(`.git/${sub}/${h.name}`); } catch { /* none */ }
74
+ }
75
+ if (fs.existsSync(path.join(root, '.git', 'config'))) files.push('.git/config');
76
+ continue;
77
+ }
78
+ stack.push(p);
79
+ } else if (e.isFile()) {
80
+ if (files.length >= MAX_FILES) { truncated = true; continue; }
81
+ files.push(p);
82
+ }
83
+ }
84
+ }
85
+ return { files: files.sort(), links, truncated };
86
+ }
87
+
88
+ function readText(root, rel) {
89
+ try {
90
+ const full = path.join(root, rel);
91
+ const st = fs.lstatSync(full);
92
+ if (!st.isFile() || st.size > MAX_BYTES) return null;
93
+ const buf = fs.readFileSync(full);
94
+ if (buf.includes(0)) return null;
95
+ return buf.toString('utf8');
96
+ } catch { return null; }
97
+ }
98
+
99
+ export function inspectDir(dir) {
100
+ const root = path.resolve(dir);
101
+ if (!fs.statSync(root).isDirectory()) throw new Error(`Not a directory: ${dir}`);
102
+ const { files, links, truncated } = walk(root);
103
+ const findings = [];
104
+ const add = (severity, indicator, file, detail) => findings.push({ severity, indicator, file, detail });
105
+ const hookTargets = new Set();
106
+
107
+ for (const l of links) {
108
+ let target = '';
109
+ try { target = fs.readlinkSync(path.join(root, l)); } catch { /* unreadable */ }
110
+ const resolved = path.resolve(path.dirname(path.join(root, l)), target);
111
+ const rel = path.relative(root, resolved);
112
+ if (rel.startsWith('..') || path.isAbsolute(rel)) add('high', 'symlink_outside_repo', l, `Symlink points outside the repository (${clip(target, 80)}). Tools that follow it can read or overwrite your files.`);
113
+ }
114
+
115
+ const binaries = files.filter((f) => BINARY_EXT.test(f) && !f.startsWith('.git/'));
116
+ if (binaries.length) add('medium', 'binaries_present', binaries[0], `Executable or binary files: ${binaries.slice(0, 5).join(', ')}${binaries.length > 5 ? '…' : ''}`);
117
+
118
+ for (const f of files) {
119
+ const base = f.split('/').pop();
120
+ const lower = f.toLowerCase();
121
+
122
+ if (f.startsWith('.git/hooks/')) {
123
+ if (!base.endsWith('.sample')) add('high', 'installed_git_hook', f, `A git hook is already installed (${base}). It runs on your next git ${base.replace(/^(pre|post)-/, '')}.`);
124
+ continue;
125
+ }
126
+ if (!TEXT_EXT.test(base) && !['Makefile', 'makefile', 'GNUmakefile', '.npmrc', '.yarnrc', '.envrc', '.gitmodules', 'config'].includes(base)
127
+ && !lower.startsWith('.husky/') && !lower.startsWith('.githooks/')) continue;
128
+ const text = readText(root, f);
129
+ if (text == null) continue;
130
+
131
+ if (f === '.git/config') {
132
+ if (/^\s*hookspath\s*=/im.test(text)) add('high', 'git_hooks_path', f, 'core.hooksPath points git at hooks shipped inside the repository.');
133
+ if (/^\s*fsmonitor\s*=\s*(?!true|false)\S/im.test(text)) add('high', 'git_fsmonitor_command', f, 'core.fsmonitor is set to a command; git runs it on status and diff.');
134
+ continue;
135
+ }
136
+ if (lower.endsWith('.vscode/tasks.json')) {
137
+ if (/"runOn"\s*:\s*"folderOpen"/i.test(text)) add('high', 'vscode_folder_open_autorun', f, 'A task runs automatically when the folder is opened in VS Code or Cursor (runOn: "folderOpen").');
138
+ if (EXEC.test(text)) add('high', 'vscode_task_shell_execution', f, 'tasks.json contains shell, download or eval primitives.');
139
+ } else if (lower.endsWith('.vscode/settings.json')) {
140
+ if (/"task\.allowAutomaticTasks"\s*:\s*("on"|true)/i.test(text)) add('high', 'vscode_auto_tasks_enabled', f, 'Turns on automatic tasks, so folder-open tasks run without asking.');
141
+ } else if (lower.endsWith('.vscode/launch.json')) {
142
+ if (/"preLaunchTask"\s*:/i.test(text)) add('medium', 'vscode_pre_launch_task', f, 'Starting the debugger first runs a task from tasks.json.');
143
+ } else if (/(^|\/)\.devcontainer(\/devcontainer)?\.json$/i.test(f) || /(^|\/)\.devcontainer\/[^/]+\/devcontainer\.json$/i.test(f)) {
144
+ for (const m of text.matchAll(/"(initializeCommand|onCreateCommand|updateContentCommand|postCreateCommand|postStartCommand|postAttachCommand)"\s*:\s*("(?:[^"\\]|\\.)*"|\[[^\]]*\]|\{[^}]*\})/g)) {
145
+ const onHost = m[1] === 'initializeCommand';
146
+ add(onHost || EXEC.test(m[2]) || PIPE_TO_SHELL.test(m[2]) ? 'high' : 'medium', 'devcontainer_command', f,
147
+ `${m[1]} runs ${onHost ? 'on your machine (not in the container)' : 'when the dev container is created or started'}: ${clip(m[2], 120)}`);
148
+ }
149
+ } else if (base === 'package.json') {
150
+ let pkg = null;
151
+ try { pkg = JSON.parse(text); } catch { add('low', 'package_json_unparseable', f, 'package.json is not valid JSON; npm may still read parts of it.'); }
152
+ if (pkg) {
153
+ const scripts = pkg.scripts && typeof pkg.scripts === 'object' ? pkg.scripts : {};
154
+ const pkgDir = path.posix.dirname(f);
155
+ for (const [k, v] of Object.entries(scripts)) {
156
+ if (typeof v !== 'string') continue;
157
+ if (LIFECYCLE.includes(k)) {
158
+ const risky = EXEC.test(v) || /https?:\/\//i.test(v);
159
+ add(risky ? 'high' : 'medium', `npm_${k}_hook`, f, `"${k}": "${clip(v)}" runs automatically on npm/pnpm/yarn install${k.includes('prepare') ? ' (and on git dependency installs)' : ''}.`);
160
+ for (const m of v.matchAll(/(?:node|python3?|sh|bash)\s+([\w./-]+\.(?:[cm]?js|ts|py|sh))/g)) hookTargets.add(path.posix.normalize(path.posix.join(pkgDir === '.' ? '' : pkgDir, m[1])));
161
+ } else if (EXEC.test(v)) {
162
+ add('high', 'suspicious_npm_script', f, `Script "${clip(k, 32)}" contains shell, download or eval primitives: ${clip(v, 100)}`);
163
+ }
164
+ }
165
+ for (const field of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
166
+ for (const [name, spec] of Object.entries(pkg[field] || {})) {
167
+ if (typeof spec === 'string' && NON_REGISTRY.test(spec.trim())) add('high', 'non_registry_dependency', f, `${field}.${name} installs from "${clip(spec, 80)}", not the registry; its own install hooks run too.`);
168
+ const near = typosquatOf(name);
169
+ if (near) add('high', 'possible_typosquat', f, `${field}.${name} is one letter away from the popular package "${near}".`);
170
+ }
171
+ }
172
+ }
173
+ } else if (base === '.npmrc') {
174
+ if (/^\s*(?:@[\w-]+:)?registry\s*=\s*https?:\/\/(?!registry\.npmjs\.org)/im.test(text)) add('high', 'npmrc_registry_override', f, 'Points npm at a non-default registry.');
175
+ if (/^\s*(script-shell|node-options|ignore-scripts\s*=\s*false)/im.test(text)) add('high', 'npmrc_exec_setting', f, 'Sets script-shell, node-options or re-enables scripts.');
176
+ } else if (base === '.yarnrc.yml' || base === '.yarnrc') {
177
+ if (/^\s*(yarnPath|yarn-path)\s*[:=\s]/im.test(text)) add('medium', 'yarn_path', f, 'yarnPath makes every yarn command run a JavaScript file from this repository.');
178
+ } else if (base === 'setup.py') {
179
+ if (EXEC.test(text)) add('high', 'setup_py_exec', f, 'setup.py runs shell, subprocess or eval code; pip install runs it.');
180
+ } else if (base === 'pyproject.toml') {
181
+ if (/^\s*backend-path\s*=/im.test(text)) add('medium', 'python_local_build_backend', f, 'Uses an in-repo build backend (backend-path); pip install runs it.');
182
+ } else if (/^(?:GNU)?[Mm]akefile$/.test(base) || base.endsWith('.mk')) {
183
+ if (EXEC.test(text) || PIPE_TO_SHELL.test(text)) add('high', 'makefile_exec', f, 'The Makefile runs download, eval or inline-interpreter commands.');
184
+ } else if (base === 'build.rs') {
185
+ add('medium', 'cargo_build_script', f, 'cargo build runs build.rs on your machine.');
186
+ } else if (base === '.envrc') {
187
+ add('medium', 'direnv_envrc', f, 'direnv runs .envrc when you cd into the folder (once allowed).');
188
+ } else if (base === '.gitmodules') {
189
+ add('low', 'git_submodules', f, `Submodules: ${clip([...text.matchAll(/url\s*=\s*(\S+)/g)].map((m) => m[1]).join(', '), 140)}`);
190
+ } else if (lower.startsWith('.husky/') || lower.startsWith('.githooks/') || /(^|\/)(lefthook\.ya?ml|\.pre-commit-config\.ya?ml)$/i.test(f)) {
191
+ if (!lower.startsWith('.husky/_/')) add('medium', 'repo_git_hooks', f, 'Git hooks shipped with the repo; a prepare script or hook manager installs them.');
192
+ }
193
+
194
+ if (/\.(md|txt)$/i.test(base)) {
195
+ if (DISABLE_SECURITY.test(text)) add('high', 'disable_security_instructions', f, `Instructions ask you to turn off security tooling: "${clip(text.match(DISABLE_SECURITY)[0], 80)}"`);
196
+ if (PIPE_TO_SHELL.test(text)) add('medium', 'pipe_to_shell_instructions', f, 'Instructions pipe a download straight into a shell.');
197
+ }
198
+
199
+ if (CODE_EXT.test(base)) {
200
+ const hidden = hiddenStrings(text);
201
+ const hiddenUrl = hidden.find((s) => /https?:\/\//i.test(s));
202
+ if (/\beval\s*\(\s*(?:Buffer\.from|atob|unescape|decodeURIComponent)/.test(text)) add('high', 'obfuscated_eval', f, 'Decodes a string and passes it to eval().');
203
+ if (/new\s+Function\s*\(/.test(text) && /\b(fetch|https?\.get|axios|request)\s*\(/.test(text)) add('high', 'remote_code_eval', f, 'Fetches text over the network and runs it with new Function().');
204
+ if (hiddenUrl) add('high', 'hidden_url', f, `A base64 string decodes to a URL: ${clip(hiddenUrl, 100)}`);
205
+ if (/(?:writeFileSync|writeFile|copyFileSync|copyFile|open|cp|Copy-Item|Set-Content)\s*\(?\s*['"`][^'"`\n]*\.git[\\/]+hooks|>\s*['"]?\.git[\\/]+hooks/.test(text)) add('high', 'writes_git_hooks', f, 'Code writes into .git/hooks, installing a hook that runs on later git commands.');
206
+ if (hookTargets.has(f) && /child_process|subprocess|os\.system|execSync|spawnSync|exec\(/.test(text)) add('high', 'install_hook_runs_commands', f, 'This file runs from an install hook and starts other processes.');
207
+ }
208
+ }
209
+
210
+ const order = { high: 0, medium: 1, low: 2 };
211
+ findings.sort((a, b) => order[a.severity] - order[b.severity] || a.file.localeCompare(b.file));
212
+ const verdict = findings.some((x) => x.severity === 'high') ? 'do_not_run'
213
+ : findings.some((x) => x.severity === 'medium') ? 'review_first' : 'no_known_traps';
214
+ return { root, filesScanned: files.length, truncated, verdict, findings };
215
+ }
216
+
217
+ export function renderInspect(r) {
218
+ const head = {
219
+ do_not_run: 'DO NOT RUN: found code that runs on open, install or build, or asks you to lower your defences.',
220
+ review_first: 'REVIEW FIRST: found things that run code in some workflows.',
221
+ no_known_traps: 'No known traps found. That is not proof it is safe; still run it in a container or VM.',
222
+ }[r.verdict];
223
+ const lines = [head, `${r.filesScanned} files read in ${r.root}${r.truncated ? ' (stopped at the file limit)' : ''}. Nothing was executed or sent.`];
224
+ for (const f of r.findings) lines.push(` [${f.severity}] ${f.file}: ${f.detail}`);
225
+ return lines.join('\n');
226
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "counterlure-cli",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Screen photos against the Counterlure face watchlist and file reports from a terminal. Faces are detected locally; traffic is OpenPGP-encrypted to a pinned key.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",