@arifbiswas/git-pre-push 1.0.12 โ 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 +111 -11
- package/bin/cli.js +128 -46
- package/package.json +1 -1
- package/scripts/postinstall.js +13 -1
- package/src/advancedScanner.js +438 -0
- package/src/doctor.js +336 -0
- package/src/index.js +61 -5
- package/src/installer.js +111 -27
- package/src/menu.js +127 -16
- package/src/shellIntegration.js +212 -0
- package/src/updateNotifier.js +178 -10
- package/src/vault.js +4 -0
- package/src/vaultCli.js +63 -0
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
|
|
@@ -62,21 +69,39 @@ gitsafty
|
|
|
62
69
|
|
|
63
70
|
Select an action to perform:
|
|
64
71
|
|
|
65
|
-
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
โโ Protection โโ
|
|
73
|
+
[1] ๐ก๏ธ Install Local Hook - Protect current repo (push + checkout + pull)
|
|
74
|
+
[2] ๐ Install Global Hook - Protect EVERY repo on this PC: scan on clone, pull & push
|
|
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)
|
|
77
|
+
|
|
78
|
+
โโ Malware scan & removal โโ
|
|
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
|
|
81
|
+
[10] ๐งน Sweep All Repos - Scan every git repo in a folder (whole device)
|
|
82
|
+
[5] ๐๏ธ Clean & Quarantine - Remove confirmed malware + trojan scripts here
|
|
83
|
+
[4] ๐ Scan Remote GitHub Repo - Zero-clone audit (no download/clone)
|
|
84
|
+
|
|
85
|
+
โโ GitHub login vault (device stays logged out) โโ
|
|
86
|
+
[11] ๐ Vault Setup - Encrypt token with Touch ID / Windows Hello / passphrase
|
|
87
|
+
[12] ๐ Vault Status - Check vault, credential helper & SSH keys
|
|
88
|
+
[13] ๐ Vault Test Unlock - Try one unlock prompt (token is not used)
|
|
89
|
+
[14] ๐ซ Vault Remove - Back to normal git login
|
|
90
|
+
|
|
91
|
+
โโ Other โโ
|
|
92
|
+
[6] โก Run Push Intercept Demo - Simulate a blocked malware push
|
|
93
|
+
[7] ๐ค Setup GitHub Action CI - Guard repository on GitHub server-side
|
|
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
|
|
96
|
+
[0] ๐ช Exit
|
|
97
|
+
|
|
98
|
+
Enter your choice (1-16, 0 to exit):
|
|
76
99
|
```
|
|
77
100
|
|
|
78
101
|
---
|
|
79
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
|
+
|
|
80
105
|
### Option 3: Lock Down an Entire Machine (Global Protection)
|
|
81
106
|
|
|
82
107
|
If you suspect your workstation has been compromised, lock down **all Git repositories on your computer** with a single command:
|
|
@@ -89,6 +114,15 @@ This configures `git config --global core.hooksPath`, ensuring every repository
|
|
|
89
114
|
|
|
90
115
|
> Already installed globally? Run `init --global` again after updating so the new clone/pull hooks are added.
|
|
91
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
|
+
|
|
92
126
|
---
|
|
93
127
|
|
|
94
128
|
## โก How It Works
|
|
@@ -196,6 +230,69 @@ Limits, honestly: the chip stops token theft (copying files, Keychain or browser
|
|
|
196
230
|
|
|
197
231
|
---
|
|
198
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
|
+
|
|
199
296
|
## ๐ ๏ธ CLI Command Reference
|
|
200
297
|
|
|
201
298
|
| Command | Description |
|
|
@@ -209,6 +306,9 @@ Limits, honestly: the chip stops token theft (copying files, Keychain or browser
|
|
|
209
306
|
| `npx @arifbiswas/git-pre-push clean` | Unstages and quarantines injected malware files to `.git/git-safty-quarantine/` |
|
|
210
307
|
| `npx @arifbiswas/git-pre-push demo` | Simulates a blocked push in terminal |
|
|
211
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 |
|
|
212
312
|
| `npx @arifbiswas/git-pre-push uninstall` | Cleanly removes the hook from `.git/hooks` |
|
|
213
313
|
|
|
214
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
|
-
|
|
28
|
-
|
|
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;
|
|
@@ -75,45 +106,82 @@ async function main() {
|
|
|
75
106
|
case 'vault':
|
|
76
107
|
case 'login-guard': {
|
|
77
108
|
banner();
|
|
78
|
-
const
|
|
79
|
-
const sub = (args[1] || 'status').toLowerCase();
|
|
109
|
+
const { runVaultCommand } = require('../src/vaultCli');
|
|
80
110
|
const hostArg = args.find(a => a.startsWith('--host='));
|
|
81
|
-
const
|
|
111
|
+
const code = await runVaultCommand(args[1], {
|
|
112
|
+
host: hostArg ? hostArg.slice(7).toLowerCase() : undefined,
|
|
113
|
+
passphrase: args.includes('--passphrase')
|
|
114
|
+
});
|
|
115
|
+
if (code) process.exit(code);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
82
118
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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`);
|
|
94
175
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
console.log(
|
|
99
|
-
if (!res.success) process.exit(1);
|
|
100
|
-
} else if (sub === 'remove' || sub === 'off' || sub === 'disable') {
|
|
101
|
-
const res = vault.removeVault({ host });
|
|
102
|
-
console.log(`\n${colors.yellow}${colors.bold}โ ${res.message}${colors.reset}\n`);
|
|
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`);
|
|
103
180
|
} else {
|
|
104
|
-
const st =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (st.vaultExists) {
|
|
109
|
-
const hw = st.protection !== 'passphrase';
|
|
110
|
-
console.log(` ${ok(hw)} Locked to this device's security chip ${hw ? `(${st.protection})` : '(passphrase only: run vault setup again on a Mac with Secure Enclave or Windows with Hello)'}`);
|
|
111
|
-
}
|
|
112
|
-
if (st.tokenExpiresAt) console.log(` ${colors.dim}Token expires: ${st.tokenExpiresAt}${colors.reset}`);
|
|
113
|
-
console.log(` ${ok(st.helperActive)} GitSafty is git's credential helper for ${st.host}`);
|
|
114
|
-
console.log(` ${ok(st.otherHelpers.length === 0)} No other helper can store or hand out a token${st.otherHelpers.length ? `: ${st.otherHelpers.join(', ')}` : ''}`);
|
|
115
|
-
console.log(` ${ok(st.sshWarnings.length === 0)} SSH private keys are passphrase-protected${st.sshWarnings.length ? `: ${st.sshWarnings.join(', ')}` : ''}`);
|
|
116
|
-
console.log('');
|
|
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`);
|
|
117
185
|
}
|
|
118
186
|
break;
|
|
119
187
|
}
|
|
@@ -170,6 +238,7 @@ async function main() {
|
|
|
170
238
|
}
|
|
171
239
|
} catch (err) {
|
|
172
240
|
console.error(`\n${colors.red}${colors.bold}โ Scan Failed:${colors.reset} ${err.message}\n`);
|
|
241
|
+
require('../src/doctor').printHint(err);
|
|
173
242
|
process.exit(1);
|
|
174
243
|
}
|
|
175
244
|
break;
|
|
@@ -234,7 +303,10 @@ async function main() {
|
|
|
234
303
|
if (result.success) {
|
|
235
304
|
console.log(`\n${colors.green}${colors.bold}โ ${result.message}${colors.reset}\n`);
|
|
236
305
|
console.log(`${colors.cyan}Your git environment is now protected!${colors.reset}`);
|
|
237
|
-
console.log(`${colors.dim}Every
|
|
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'] : [])]);
|
|
238
310
|
} else {
|
|
239
311
|
console.error(`\n${colors.red}${colors.bold}โ ${result.message}${colors.reset}\n`);
|
|
240
312
|
process.exit(1);
|
|
@@ -245,9 +317,13 @@ async function main() {
|
|
|
245
317
|
case 'uninstall':
|
|
246
318
|
case 'remove': {
|
|
247
319
|
banner();
|
|
248
|
-
const result = uninstallHook();
|
|
320
|
+
const result = uninstallHook(process.cwd(), isGlobalFlag);
|
|
249
321
|
if (result.success) {
|
|
250
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
|
+
}
|
|
251
327
|
} else {
|
|
252
328
|
console.error(`\n${colors.red}${colors.bold}โ ${result.message}${colors.reset}\n`);
|
|
253
329
|
process.exit(1);
|
|
@@ -262,10 +338,10 @@ async function main() {
|
|
|
262
338
|
banner();
|
|
263
339
|
console.log(`
|
|
264
340
|
${colors.bold}Usage:${colors.reset}
|
|
265
|
-
npx git-
|
|
341
|
+
npx @arifbiswas/git-pre-push <command>
|
|
266
342
|
|
|
267
343
|
${colors.bold}Commands:${colors.reset}
|
|
268
|
-
${colors.green}init${colors.reset}
|
|
344
|
+
${colors.green}init${colors.reset} Protect this repo (push + checkout + pull). ${colors.green}init --global${colors.reset}: every repo on this PC
|
|
269
345
|
${colors.green}scan${colors.reset} Scan current local repository, staged files & working tree
|
|
270
346
|
${colors.green}scan-remote${colors.reset} Scan remote GitHub repository without downloading or cloning
|
|
271
347
|
${colors.green}clean${colors.reset} Quarantine injected malware scripts (.bat, .ps1, trojans)
|
|
@@ -279,17 +355,22 @@ ${colors.bold}Commands:${colors.reset}
|
|
|
279
355
|
${colors.green}vault status${colors.reset} Show vault / credential helper / SSH key protection status
|
|
280
356
|
${colors.green}vault test${colors.reset} Try one unlock (prompt) without using the token
|
|
281
357
|
${colors.green}vault remove${colors.reset} Turn the vault off and go back to normal git login
|
|
282
|
-
${colors.green}
|
|
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)
|
|
283
364
|
|
|
284
365
|
${colors.bold}How it works:${colors.reset}
|
|
285
|
-
1. Run ${colors.cyan}npx git-
|
|
366
|
+
1. Run ${colors.cyan}npx @arifbiswas/git-pre-push init${colors.reset} in any git repository.
|
|
286
367
|
2. Whenever you run ${colors.cyan}git push${colors.reset}, GitSafty automatically intercepts and scans:
|
|
287
368
|
- Outgoing modified files for blacklisted & trojan scripts (temp_auto_push.bat, .vbs, .ps1, .exe, etc.)
|
|
288
369
|
- Outgoing diff content for obfuscated payloads (base64 eval, powershell cradles, curl | bash, lolbins)
|
|
289
370
|
- IDE settings (.vscode/tasks.json, .vscode/settings.json, JetBrains configs)
|
|
290
371
|
- Leaked API keys, private keys, and .env files
|
|
291
372
|
3. If malware or critical secrets are detected, ${colors.red}${colors.bold}the push is rejected immediately${colors.reset}!
|
|
292
|
-
4. With ${colors.cyan}npx git-
|
|
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.
|
|
293
374
|
${colors.bold}Confirmed${colors.reset} malware is removed automatically (backup kept in .git/gitsafty-quarantine/).
|
|
294
375
|
${colors.bold}Suspicious${colors.reset} items are only reported, never touched.
|
|
295
376
|
Disable auto-removal with ${colors.cyan}"autoClean": false${colors.reset} in .gitsafetyrc.json or GITSAFTY_NO_AUTOCLEAN=1.
|
|
@@ -301,7 +382,8 @@ ${colors.bold}Zero Dependencies:${colors.reset} 100% pure Node.js built-ins.
|
|
|
301
382
|
}
|
|
302
383
|
|
|
303
384
|
main().catch((err) => {
|
|
304
|
-
console.error(
|
|
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 (_) {}
|
|
305
387
|
process.exit(1);
|
|
306
388
|
});
|
|
307
389
|
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -31,5 +31,17 @@ function main() {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
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
|
|