@arifbiswas/git-pre-push 1.0.13 → 1.0.15

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
@@ -50,6 +50,13 @@ Run without arguments to open the interactive selection dashboard:
50
50
  npx @arifbiswas/git-pre-push
51
51
  ```
52
52
 
53
+ > **`gitsafty` "not recognized" / "command not found"?** `npx` only runs GitSafty from a temporary cache; it does not install the `gitsafty` command. Install it permanently (GitSafty also offers this after `npx ... init`):
54
+ > ```bash
55
+ > npm install -g @arifbiswas/git-pre-push
56
+ > gitsafty init --global
57
+ > ```
58
+ > Then open a **new** terminal. On Windows, if it is still not found, add the folder printed by `npm config get prefix` to your `Path` environment variable.
59
+
53
60
  Or if installed globally (`npm i -g @arifbiswas/git-pre-push`):
54
61
  ```bash
55
62
  gitsafty
@@ -65,10 +72,12 @@ Select an action to perform:
65
72
  ── Protection ──
66
73
  [1] 🛡️ Install Local Hook - Protect current repo (push + checkout + pull)
67
74
  [2] 🌐 Install Global Hook - Protect EVERY repo on this PC: scan on clone, pull & push
68
- [8] ❌ Uninstall Hook - Remove GitSafty hooks
75
+ [17] 🔁 Scan Every Pull - Also scan when git pull says "Already up to date"
76
+ [8] ❌ Uninstall Hook - Remove GitSafty hooks (this repo or whole PC)
69
77
 
70
78
  ── Malware scan & removal ──
71
79
  [3] 🔍 Scan Local Workspace - Deep scan this repo, auto-remove confirmed malware
80
+ [16] 🔬 Advanced Scanner - Audit ALL projects in a folder: malware, backdoors, secrets
72
81
  [10] 🧹 Sweep All Repos - Scan every git repo in a folder (whole device)
73
82
  [5] 🗑️ Clean & Quarantine - Remove confirmed malware + trojan scripts here
74
83
  [4] 🚀 Scan Remote GitHub Repo - Zero-clone audit (no download/clone)
@@ -83,13 +92,16 @@ Select an action to perform:
83
92
  [6] ⚡ Run Push Intercept Demo - Simulate a blocked malware push
84
93
  [7] 🤖 Setup GitHub Action CI - Guard repository on GitHub server-side
85
94
  [9] 🔄 Check for Updates - Check if a new version is available on npm
95
+ [15] 🩺 Doctor - Something broken? Find it and show/apply the fix
86
96
  [0] 🚪 Exit
87
97
 
88
- Enter your choice (1-14, 0 to exit):
98
+ Enter your choice (1-16, 0 to exit):
89
99
  ```
90
100
 
91
101
  ---
92
102
 
103
+ **Updates:** every time you open `gitsafty` it checks npm. When a new version is out it asks `Install GitSafty x.y.z now? (Y/n)`; answer `y` and it installs and reopens the new version (global installs only; never inside git hooks or CI). Turn the question off with `GITSAFTY_NO_UPDATE_PROMPT=1`.
104
+
93
105
  ### Option 3: Lock Down an Entire Machine (Global Protection)
94
106
 
95
107
  If you suspect your workstation has been compromised, lock down **all Git repositories on your computer** with a single command:
@@ -102,6 +114,15 @@ This configures `git config --global core.hooksPath`, ensuring every repository
102
114
 
103
115
  > Already installed globally? Run `init --global` again after updating so the new clone/pull hooks are added.
104
116
 
117
+ **Every `git pull` is scanned.** Pulls that bring changes (merge, fast-forward or `--rebase`) are scanned by the hooks, and the whole repository is checked, like after a clone. When git says *"Already up to date"* it runs **no hook at all**, so `init --global` offers to add a small `git` function to your shell profile (`~/.zshrc`, `~/.bashrc`, fish, or the PowerShell profile on Windows) that scans after every `git pull`, keeps git's exit code and never scans twice for the same pull:
118
+
119
+ ```bash
120
+ gitsafty pull-scan on # turn on (also menu [17])
121
+ gitsafty pull-scan off # remove the function again
122
+ ```
123
+
124
+ IDE "Sync"/"Pull" buttons that bring changes are covered by the hooks; only no-change pulls from a terminal need the shell function.
125
+
105
126
  ---
106
127
 
107
128
  ## ⚡ How It Works
@@ -209,6 +230,69 @@ Limits, honestly: the chip stops token theft (copying files, Keychain or browser
209
230
 
210
231
  ---
211
232
 
233
+ ## 🔬 Advanced Scanner (many projects at once)
234
+
235
+ Got a folder with 20 projects? Audit all of them in one go:
236
+
237
+ ```bash
238
+ gitsafty scan-projects ~/projects # report only
239
+ gitsafty scan-projects ~/projects --clean # also remove CONFIRMED malware
240
+ gitsafty scan-projects ~/projects --deep # include node_modules, build output, ignored files
241
+ gitsafty scan-projects ~/projects --json # machine-readable output
242
+ ```
243
+
244
+ Every direct sub-folder is a project (git repository or not; nested repos are found too). For each one it checks:
245
+
246
+ - **Malware**: the confirmed-malware engine on every file (always on, even for ignored paths)
247
+ - **Git backdoors**: unknown hooks in `.git/hooks`, and `core.fsmonitor`, `core.hooksPath`, `core.sshCommand`, filter drivers, `diff.external`, `!` aliases, repo-local credential helpers, which run code during normal git commands
248
+ - **IDE auto-run**: `.vscode` / `.idea` tasks and settings
249
+ - **Exposed secrets**: keys and tokens in code, and `.env` files that git tracks (masked in the output)
250
+ - **Dangerous files**: executables, disguised double extensions
251
+
252
+ When it finishes you get, for every project, what was found, what was **removed** (and how: whole file quarantined, or malware cut out and the rest kept), and what still needs your attention with the exact command to fix it, followed by a table:
253
+
254
+ ```text
255
+ Results per project
256
+ Project Status Found Removed To review
257
+ shop-backend CLEANED 8 8 0
258
+ admin-panel DANGER 2 0 2
259
+ mobile-app SECRETS 3 0 3
260
+ landing CLEAN 0 0 0
261
+ ```
262
+
263
+ A JSON report is saved to `~/.gitsafty/reports/`. Only confirmed malware is ever removed (with backups); backdoors and secrets are reported with a fix command. Use `.gitsafetyrc.json` `ignoreFiles` for known test fixtures.
264
+
265
+ ---
266
+
267
+ ## 🩺 Troubleshooting (`doctor`)
268
+
269
+ Something not working? One command finds out what and prints the exact fix:
270
+
271
+ ```bash
272
+ gitsafty doctor # report
273
+ gitsafty doctor --fix # apply the safe fixes (rewrite hooks, re-register the vault helper)
274
+ ```
275
+
276
+ It checks Node.js, git, the global hooks (missing, outdated, or pointing to a GitSafty that was uninstalled or moved), and the GitHub login helper (e.g. it points to a Node.js version that nvm removed). Every GitSafty error also ends with a "💡 What to do" hint, and if GitSafty itself is gone, every `git clone` / `git pull` / `git push` prints how to reinstall or turn it off.
277
+
278
+ **Can't install or update?**
279
+
280
+ | npm error | Fix |
281
+ |---|---|
282
+ | `EACCES` / permission denied | Use a user-owned npm folder: `mkdir -p ~/.npm-global && npm config set prefix ~/.npm-global`, add `~/.npm-global/bin` to `PATH`, install again (Windows: run as Administrator or use nvm-windows) |
283
+ | `ENOTFOUND` / `ETIMEDOUT` | Network/proxy: `npm config get registry`, `npm cache verify`, try again |
284
+ | `Unexpected token` / engine warning | Node.js too old: install Node 18+ (`nvm install --lts`) |
285
+
286
+ **Turn GitSafty off without the CLI** (works even when it can't be installed):
287
+
288
+ ```bash
289
+ git config --global --unset core.hooksPath
290
+ rm -rf ~/.git-hooks-safty # Windows PowerShell: Remove-Item -Recurse -Force "$HOME\.git-hooks-safty"
291
+ git config --global --remove-section credential.https://github.com # only if you used the vault
292
+ ```
293
+
294
+ ---
295
+
212
296
  ## 🛠️ CLI Command Reference
213
297
 
214
298
  | Command | Description |
@@ -222,6 +306,9 @@ Limits, honestly: the chip stops token theft (copying files, Keychain or browser
222
306
  | `npx @arifbiswas/git-pre-push clean` | Unstages and quarantines injected malware files to `.git/git-safty-quarantine/` |
223
307
  | `npx @arifbiswas/git-pre-push demo` | Simulates a blocked push in terminal |
224
308
  | `npx @arifbiswas/git-pre-push action` | Generates a `.github/workflows/git-safty.yml` CI workflow |
309
+ | `npx @arifbiswas/git-pre-push scan-projects <folder>` | **Advanced Scanner**: audit every project in a folder (malware, git backdoors, IDE, secrets) |
310
+ | `npx @arifbiswas/git-pre-push pull-scan on\|off` | Scan after every `git pull`, also when "Already up to date" (adds a shell `git` function) |
311
+ | `npx @arifbiswas/git-pre-push doctor [--fix]` | Finds broken/outdated installs and shows (or applies) the exact fix |
225
312
  | `npx @arifbiswas/git-pre-push uninstall` | Cleanly removes the hook from `.git/hooks` |
226
313
 
227
314
  ---
package/bin/cli.js CHANGED
@@ -6,6 +6,8 @@ const {
6
6
  runManualScan,
7
7
  runPostCheckout,
8
8
  runPostMerge,
9
+ runPostRewrite,
10
+ runScanPull,
9
11
  runSweep,
10
12
  scanAndCleanRepo,
11
13
  installHook,
@@ -21,11 +23,38 @@ const args = process.argv.slice(2);
21
23
  const command = args[0] ? args[0].toLowerCase() : 'menu';
22
24
  const isGlobalFlag = args.includes('--global') || args.includes('-g');
23
25
 
26
+ /** After a global install: offer the shell function that scans every git pull. */
27
+ async function offerPullScan() {
28
+ const shell = require('../src/shellIntegration');
29
+ if (shell.shellIntegrationStatus().installed.length) {
30
+ shell.installShellIntegration(); // refresh with this version's paths
31
+ return;
32
+ }
33
+ const interactive = process.stdin.isTTY && process.stdout.isTTY && !process.env.CI;
34
+ console.log(`${colors.dim}git runs no hook when a pull is "Already up to date". To scan after EVERY git pull,${colors.reset}`);
35
+ console.log(`${colors.dim}GitSafty can add a small git function to your shell profile (.zshrc / .bashrc / PowerShell profile).${colors.reset}`);
36
+ if (!interactive) {
37
+ console.log(` Turn it on: ${colors.cyan}gitsafty pull-scan on${colors.reset}\n`);
38
+ return;
39
+ }
40
+ const readline = require('readline');
41
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
42
+ const answer = await new Promise(r => rl.question(`${colors.bold}${colors.cyan}? Scan after every git pull? (Y/n): ${colors.reset}`, a => { rl.close(); r(a.trim()); }));
43
+ if (/^n(o)?$/i.test(answer)) {
44
+ console.log(` ${colors.dim}Skipped. Turn it on later: gitsafty pull-scan on${colors.reset}\n`);
45
+ return;
46
+ }
47
+ const res = shell.installShellIntegration();
48
+ console.log(`${colors.green}✔ Pull scan on${colors.reset} ${colors.dim}(${res.files.join(', ')})${colors.reset}. Load it now: ${colors.cyan}${shell.reloadHint()}${colors.reset}\n`);
49
+ }
50
+
24
51
  async function main() {
25
52
  // Check for updates non-blocking on interactive commands
26
- const hookCommands = ['scan-push', 'scan-checkout', 'scan-merge', 'credential'];
27
- if (!hookCommands.includes(command)) {
28
- await notifyIfUpdateAvailable(pkg.version);
53
+ const hookCommands = ['scan-push', 'scan-checkout', 'scan-merge', 'scan-rewrite', 'scan-pull', 'credential'];
54
+ // `gitsafty update` does its own check below.
55
+ if (!hookCommands.includes(command) && command !== 'update' && command !== 'upgrade') {
56
+ // Opening the menu always asks the registry, so a fresh release is never missed.
57
+ await notifyIfUpdateAvailable(pkg.version, { force: command === 'menu' || command === 'interactive' });
29
58
  }
30
59
 
31
60
  switch (command) {
@@ -49,6 +78,7 @@ async function main() {
49
78
  runPostCheckout(args[1], args[2], args[3]);
50
79
  } catch (err) {
51
80
  console.error(`[GitSafty] clone/checkout scan error: ${err.message}`);
81
+ try { require('../src/doctor').printHint(err); } catch (_) {}
52
82
  }
53
83
  process.exit(0);
54
84
  break;
@@ -59,6 +89,7 @@ async function main() {
59
89
  runPostMerge();
60
90
  } catch (err) {
61
91
  console.error(`[GitSafty] pull scan error: ${err.message}`);
92
+ try { require('../src/doctor').printHint(err); } catch (_) {}
62
93
  }
63
94
  process.exit(0);
64
95
  break;
@@ -85,6 +116,76 @@ async function main() {
85
116
  break;
86
117
  }
87
118
 
119
+ case 'scan-projects':
120
+ case 'advanced':
121
+ case 'advanced-scan': {
122
+ banner();
123
+ const { runAdvancedScan } = require('../src/advancedScanner');
124
+ const target = args.find((a, i) => i > 0 && !a.startsWith('-')) || process.cwd();
125
+ process.exit(runAdvancedScan(target, {
126
+ clean: args.includes('--clean'),
127
+ deep: args.includes('--deep'),
128
+ json: args.includes('--json')
129
+ }));
130
+ break;
131
+ }
132
+
133
+ case 'doctor':
134
+ case 'fix-install': {
135
+ banner();
136
+ const { runDoctor } = require('../src/doctor');
137
+ process.exit(runDoctor({ fix: args.includes('--fix') }));
138
+ break;
139
+ }
140
+
141
+ // Triggered by the post-rewrite hook (git pull --rebase)
142
+ case 'scan-rewrite':
143
+ try {
144
+ runPostRewrite(args[1]);
145
+ } catch (err) {
146
+ console.error(`[GitSafty] pull scan error: ${err.message}`);
147
+ try { require('../src/doctor').printHint(err); } catch (_) {}
148
+ }
149
+ process.exit(0);
150
+ break;
151
+
152
+ // Called by the optional shell git wrapper after every git pull
153
+ case 'scan-pull':
154
+ try {
155
+ runScanPull();
156
+ } catch (err) {
157
+ console.error(`[GitSafty] pull scan error: ${err.message}`);
158
+ }
159
+ process.exit(0);
160
+ break;
161
+
162
+ case 'pull-scan':
163
+ case 'shell-integration': {
164
+ banner();
165
+ const shell = require('../src/shellIntegration');
166
+ const sub = (args[1] || 'status').toLowerCase();
167
+ if (sub === 'on' || sub === 'install' || sub === 'enable') {
168
+ const res = shell.installShellIntegration();
169
+ if (!res.files.length) {
170
+ console.log(`\n${colors.yellow}No shell profile found to update.${colors.reset}\n`);
171
+ } else {
172
+ console.log(`\n${colors.green}${colors.bold}✔ Every git pull will now be scanned (also "Already up to date").${colors.reset}`);
173
+ for (const f of res.files) console.log(` ${colors.dim}updated ${f}${colors.reset}`);
174
+ console.log(` Load it now: ${colors.cyan}${shell.reloadHint()}${colors.reset}\n`);
175
+ }
176
+ } else if (sub === 'off' || sub === 'remove' || sub === 'disable') {
177
+ const res = shell.removeShellIntegration();
178
+ console.log(`\n${colors.yellow}${colors.bold}✔ Pull scan shell function removed${res.files.length ? ` from ${res.files.join(', ')}` : ' (was not installed)'}.${colors.reset}`);
179
+ console.log(` ${colors.dim}Open a new terminal to finish. Pulls that bring changes are still scanned by the git hooks.${colors.reset}\n`);
180
+ } else {
181
+ const st = shell.shellIntegrationStatus();
182
+ console.log(st.installed.length
183
+ ? `\n${colors.green}✔ Pull scan is ON${colors.reset} ${colors.dim}(${st.installed.join(', ')})${colors.reset}\n`
184
+ : `\n${colors.yellow}Pull scan shell function is OFF.${colors.reset} Pulls that bring changes are still scanned by the git hooks.\n Turn on scanning for every pull: ${colors.cyan}gitsafty pull-scan on${colors.reset}\n`);
185
+ }
186
+ break;
187
+ }
188
+
88
189
  case 'sweep':
89
190
  case 'scan-all': {
90
191
  const target = args.find((a, i) => i > 0 && !a.startsWith('-')) || process.cwd();
@@ -137,6 +238,7 @@ async function main() {
137
238
  }
138
239
  } catch (err) {
139
240
  console.error(`\n${colors.red}${colors.bold}✖ Scan Failed:${colors.reset} ${err.message}\n`);
241
+ require('../src/doctor').printHint(err);
140
242
  process.exit(1);
141
243
  }
142
244
  break;
@@ -201,7 +303,10 @@ async function main() {
201
303
  if (result.success) {
202
304
  console.log(`\n${colors.green}${colors.bold}✔ ${result.message}${colors.reset}\n`);
203
305
  console.log(`${colors.cyan}Your git environment is now protected!${colors.reset}`);
204
- console.log(`${colors.dim}Every 'git push' will automatically scan outgoing commits for malware & secret leaks.${colors.reset}\n`);
306
+ console.log(`${colors.dim}Every git push, clone and pull${isGlobalFlag ? ' on this PC' : ' in this repository'} is scanned for malware & secret leaks.${colors.reset}\n`);
307
+ if (isGlobalFlag) await offerPullScan();
308
+ const { offerPermanentInstall } = require('../src/updateNotifier');
309
+ await offerPermanentInstall(['init', ...(isGlobalFlag ? ['--global'] : [])]);
205
310
  } else {
206
311
  console.error(`\n${colors.red}${colors.bold}✖ ${result.message}${colors.reset}\n`);
207
312
  process.exit(1);
@@ -212,9 +317,13 @@ async function main() {
212
317
  case 'uninstall':
213
318
  case 'remove': {
214
319
  banner();
215
- const result = uninstallHook();
320
+ const result = uninstallHook(process.cwd(), isGlobalFlag);
216
321
  if (result.success) {
217
322
  console.log(`\n${colors.yellow}${colors.bold}✔ ${result.message}${colors.reset}\n`);
323
+ if (/global/i.test(result.message)) {
324
+ const removed = require('../src/shellIntegration').removeShellIntegration();
325
+ if (removed.files.length) console.log(`${colors.dim}Also removed the git pull scan function from ${removed.files.join(', ')}.${colors.reset}\n`);
326
+ }
218
327
  } else {
219
328
  console.error(`\n${colors.red}${colors.bold}✖ ${result.message}${colors.reset}\n`);
220
329
  process.exit(1);
@@ -229,10 +338,10 @@ async function main() {
229
338
  banner();
230
339
  console.log(`
231
340
  ${colors.bold}Usage:${colors.reset}
232
- npx git-safty <command>
341
+ npx @arifbiswas/git-pre-push <command>
233
342
 
234
343
  ${colors.bold}Commands:${colors.reset}
235
- ${colors.green}init${colors.reset} Install the pre-push guard hook into .git/hooks/pre-push
344
+ ${colors.green}init${colors.reset} Protect this repo (push + checkout + pull). ${colors.green}init --global${colors.reset}: every repo on this PC
236
345
  ${colors.green}scan${colors.reset} Scan current local repository, staged files & working tree
237
346
  ${colors.green}scan-remote${colors.reset} Scan remote GitHub repository without downloading or cloning
238
347
  ${colors.green}clean${colors.reset} Quarantine injected malware scripts (.bat, .ps1, trojans)
@@ -246,17 +355,22 @@ ${colors.bold}Commands:${colors.reset}
246
355
  ${colors.green}vault status${colors.reset} Show vault / credential helper / SSH key protection status
247
356
  ${colors.green}vault test${colors.reset} Try one unlock (prompt) without using the token
248
357
  ${colors.green}vault remove${colors.reset} Turn the vault off and go back to normal git login
249
- ${colors.green}uninstall${colors.reset} Remove git-safty hook from .git/hooks
358
+ ${colors.green}scan-projects${colors.reset} <folder> Advanced Scanner: audit EVERY project in a folder at once
359
+ (malware, git backdoors, IDE auto-run, secrets) [--clean] [--deep] [--json]
360
+ ${colors.green}pull-scan${colors.reset} on|off Scan after EVERY git pull, also "Already up to date" (adds a git shell function)
361
+ ${colors.green}doctor${colors.reset} Find broken/outdated installs and show the exact fix (--fix applies it)
362
+ ${colors.green}update${colors.reset} Check npm for a new version and install it
363
+ ${colors.green}uninstall${colors.reset} Remove hooks from this repo (outside a repo, or with --global: remove global hooks)
250
364
 
251
365
  ${colors.bold}How it works:${colors.reset}
252
- 1. Run ${colors.cyan}npx git-safty init${colors.reset} in any git repository.
366
+ 1. Run ${colors.cyan}npx @arifbiswas/git-pre-push init${colors.reset} in any git repository.
253
367
  2. Whenever you run ${colors.cyan}git push${colors.reset}, GitSafty automatically intercepts and scans:
254
368
  - Outgoing modified files for blacklisted & trojan scripts (temp_auto_push.bat, .vbs, .ps1, .exe, etc.)
255
369
  - Outgoing diff content for obfuscated payloads (base64 eval, powershell cradles, curl | bash, lolbins)
256
370
  - IDE settings (.vscode/tasks.json, .vscode/settings.json, JetBrains configs)
257
371
  - Leaked API keys, private keys, and .env files
258
372
  3. If malware or critical secrets are detected, ${colors.red}${colors.bold}the push is rejected immediately${colors.reset}!
259
- 4. With ${colors.cyan}npx git-safty init --global${colors.reset}, every ${colors.cyan}git clone${colors.reset} / ${colors.cyan}git pull${colors.reset} on this device is scanned too.
373
+ 4. With ${colors.cyan}npx @arifbiswas/git-pre-push init --global${colors.reset}, every ${colors.cyan}git clone${colors.reset} / ${colors.cyan}git pull${colors.reset} on this device is scanned too.
260
374
  ${colors.bold}Confirmed${colors.reset} malware is removed automatically (backup kept in .git/gitsafty-quarantine/).
261
375
  ${colors.bold}Suspicious${colors.reset} items are only reported, never touched.
262
376
  Disable auto-removal with ${colors.cyan}"autoClean": false${colors.reset} in .gitsafetyrc.json or GITSAFTY_NO_AUTOCLEAN=1.
@@ -268,7 +382,8 @@ ${colors.bold}Zero Dependencies:${colors.reset} 100% pure Node.js built-ins.
268
382
  }
269
383
 
270
384
  main().catch((err) => {
271
- console.error(`[git-safty error]:`, err);
385
+ console.error(`${colors.red}${colors.bold}✖ GitSafty error:${colors.reset} ${err && err.message ? err.message : err}`);
386
+ try { require('../src/doctor').printHint(err); } catch (_) {}
272
387
  process.exit(1);
273
388
  });
274
389
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arifbiswas/git-pre-push",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Zero-dependency pre-push security guard that stops malware, injected scripts, and leaked secrets from reaching GitHub.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -31,5 +31,17 @@ function main() {
31
31
  }
32
32
  }
33
33
 
34
- main();
34
+ // A postinstall error must never make `npm install` fail: explain and move on.
35
+ try {
36
+ main();
37
+ } catch (err) {
38
+ console.warn(`[git-safty] Installed, but hook setup did not finish: ${err && err.message}`);
39
+ try {
40
+ const { hintForError } = require('../src/doctor');
41
+ const hint = hintForError(err);
42
+ console.warn(`[git-safty] ${hint.problem}`);
43
+ for (const c of hint.commands) console.warn(` ${c}`);
44
+ } catch (_) {}
45
+ console.warn('[git-safty] Check everything with: gitsafty doctor');
46
+ }
35
47