@arifbiswas/git-pre-push 1.0.12 โ†’ 1.0.13

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
@@ -62,17 +62,30 @@ gitsafty
62
62
 
63
63
  Select an action to perform:
64
64
 
65
- [1] ๐Ÿ›ก๏ธ Install Local Hook - Protect current repository
66
- [2] ๐ŸŒ Install Global Hook - Lock down ALL git repos across this PC
67
- [3] ๐Ÿ” Scan Local Workspace - Audit staged & untracked files for threats
68
- [4] ๐Ÿš€ Scan Remote GitHub Repo - Zero-clone audit (no download/clone)
69
- [5] ๐Ÿงน Clean & Quarantine - Remove temp_*_push.bat & trojan scripts
70
- [6] โšก Run Push Intercept Demo - Simulate a blocked malware push
71
- [7] ๐Ÿค– Setup GitHub Action CI - Guard repository on GitHub server-side
72
- [8] โŒ Uninstall Hook - Remove pre-push hook
73
- [0] ๐Ÿšช Exit
74
-
75
- Enter your choice (1-8, 0 to exit):
65
+ โ”€โ”€ Protection โ”€โ”€
66
+ [1] ๐Ÿ›ก๏ธ Install Local Hook - Protect current repo (push + checkout + pull)
67
+ [2] ๐ŸŒ Install Global Hook - Protect EVERY repo on this PC: scan on clone, pull & push
68
+ [8] โŒ Uninstall Hook - Remove GitSafty hooks
69
+
70
+ โ”€โ”€ Malware scan & removal โ”€โ”€
71
+ [3] ๐Ÿ” Scan Local Workspace - Deep scan this repo, auto-remove confirmed malware
72
+ [10] ๐Ÿงน Sweep All Repos - Scan every git repo in a folder (whole device)
73
+ [5] ๐Ÿ—‘๏ธ Clean & Quarantine - Remove confirmed malware + trojan scripts here
74
+ [4] ๐Ÿš€ Scan Remote GitHub Repo - Zero-clone audit (no download/clone)
75
+
76
+ โ”€โ”€ GitHub login vault (device stays logged out) โ”€โ”€
77
+ [11] ๐Ÿ” Vault Setup - Encrypt token with Touch ID / Windows Hello / passphrase
78
+ [12] ๐Ÿ“‹ Vault Status - Check vault, credential helper & SSH keys
79
+ [13] ๐Ÿ”“ Vault Test Unlock - Try one unlock prompt (token is not used)
80
+ [14] ๐Ÿšซ Vault Remove - Back to normal git login
81
+
82
+ โ”€โ”€ Other โ”€โ”€
83
+ [6] โšก Run Push Intercept Demo - Simulate a blocked malware push
84
+ [7] ๐Ÿค– Setup GitHub Action CI - Guard repository on GitHub server-side
85
+ [9] ๐Ÿ”„ Check for Updates - Check if a new version is available on npm
86
+ [0] ๐Ÿšช Exit
87
+
88
+ Enter your choice (1-14, 0 to exit):
76
89
  ```
77
90
 
78
91
  ---
package/bin/cli.js CHANGED
@@ -75,46 +75,13 @@ async function main() {
75
75
  case 'vault':
76
76
  case 'login-guard': {
77
77
  banner();
78
- const vault = require('../src/vault');
79
- const sub = (args[1] || 'status').toLowerCase();
78
+ const { runVaultCommand } = require('../src/vaultCli');
80
79
  const hostArg = args.find(a => a.startsWith('--host='));
81
- const host = hostArg ? hostArg.slice(7).toLowerCase() : undefined;
82
-
83
- if (sub === 'setup' || sub === 'on' || sub === 'enable') {
84
- const res = await vault.setupVault({ host: host || 'github.com', mode: args.includes('--passphrase') ? 'passphrase' : 'auto' });
85
- if (!res.success) {
86
- console.error(`\n${colors.red}${colors.bold}โœ– ${res.message}${colors.reset}\n`);
87
- process.exit(1);
88
- }
89
- console.log(`\n${colors.green}${colors.bold}โœ” ${res.message}${colors.reset}`);
90
- for (const step of res.steps) console.log(` ${colors.dim}โ€ข${colors.reset} ${step}`);
91
- for (const key of res.sshWarnings) {
92
- console.log(`\n${colors.yellow}โš  SSH key without passphrase: ${key}${colors.reset}`);
93
- console.log(` ${colors.dim}Anyone who copies it can push as you. Protect it: ${colors.reset}ssh-keygen -p -f ${key}`);
94
- }
95
- console.log('');
96
- } else if (sub === 'test') {
97
- const res = vault.testUnlock();
98
- console.log(`\n${res.success ? colors.green + 'โœ”' : colors.red + 'โœ–'} ${res.message}${colors.reset}\n`);
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`);
103
- } else {
104
- const st = vault.vaultStatus({ host });
105
- const ok = (b) => (b ? `${colors.green}โœ”` : `${colors.red}โœ–`) + colors.reset;
106
- console.log(`\n${colors.bold}GitSafty Vault (${st.host})${colors.reset}`);
107
- console.log(` ${ok(st.vaultExists)} Encrypted token vault ${st.vaultExists ? `(${st.username}, file mode ${st.vaultMode})` : '(not set up: run gitsafty vault setup)'}`);
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('');
117
- }
80
+ const code = await runVaultCommand(args[1], {
81
+ host: hostArg ? hostArg.slice(7).toLowerCase() : undefined,
82
+ passphrase: args.includes('--passphrase')
83
+ });
84
+ if (code) process.exit(code);
118
85
  break;
119
86
  }
120
87
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arifbiswas/git-pre-push",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
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": {
package/src/menu.js CHANGED
@@ -1,11 +1,23 @@
1
1
  const readline = require('readline');
2
2
  const { banner, colors } = require('./reporter');
3
- const { runManualScan, installHook, uninstallHook } = require('./index');
3
+ const { runManualScan, runSweep, scanAndCleanRepo, installHook, uninstallHook } = require('./index');
4
4
  const { cleanInfectedFiles } = require('./cleaner');
5
5
  const { setupGitHubAction } = require('./action');
6
6
  const { scanRemoteRepositoryZeroClone, printRemoteScanReport } = require('./remoteScanner');
7
7
  const { scanFilesAndDiff } = require('./scanner');
8
8
  const { printReport, printBlockMessage } = require('./reporter');
9
+ const { runVaultCommand } = require('./vaultCli');
10
+
11
+ /** One-line question on the terminal. */
12
+ function ask(question) {
13
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
14
+ return new Promise((resolve) => {
15
+ rl.question(question, (answer) => {
16
+ rl.close();
17
+ resolve(answer.trim());
18
+ });
19
+ });
20
+ }
9
21
 
10
22
  /**
11
23
  * Runs an interactive numbered menu in terminal
@@ -13,17 +25,34 @@ const { printReport, printBlockMessage } = require('./reporter');
13
25
  async function runInteractiveMenu() {
14
26
  banner();
15
27
 
16
- console.log(`\n${colors.bold}${colors.cyan}Select an action to perform:${colors.reset}\n`);
17
- console.log(` ${colors.green}[1]${colors.reset} ๐Ÿ›ก๏ธ ${colors.bold}Install Local Hook${colors.reset} - Protect current repository`);
18
- console.log(` ${colors.green}[2]${colors.reset} ๐ŸŒ ${colors.bold}Install Global Hook${colors.reset} - Lock down ALL git repos across this PC`);
19
- console.log(` ${colors.green}[3]${colors.reset} ๐Ÿ” ${colors.bold}Scan Local Workspace${colors.reset} - Audit staged & untracked files for threats`);
20
- console.log(` ${colors.green}[4]${colors.reset} ๐Ÿš€ ${colors.bold}Scan Remote GitHub Repo${colors.reset} - Zero-clone audit (no download/clone)`);
21
- console.log(` ${colors.green}[5]${colors.reset} ๐Ÿงน ${colors.bold}Clean & Quarantine${colors.reset} - Remove temp_*_push.bat & trojan scripts`);
22
- console.log(` ${colors.green}[6]${colors.reset} โšก ${colors.bold}Run Push Intercept Demo${colors.reset} - Simulate a blocked malware push`);
23
- console.log(` ${colors.green}[7]${colors.reset} ๐Ÿค– ${colors.bold}Setup GitHub Action CI${colors.reset} - Guard repository on GitHub server-side`);
24
- console.log(` ${colors.green}[8]${colors.reset} โŒ ${colors.bold}Uninstall Hook${colors.reset} - Remove pre-push hook`);
25
- console.log(` ${colors.green}[9]${colors.reset} ๐Ÿ”„ ${colors.bold}Check for Updates${colors.reset} - Check if a new version is available on npm`);
26
- console.log(` ${colors.dim}[0] ๐Ÿšช Exit${colors.reset}\n`);
28
+ const item = (n, icon, title, desc) =>
29
+ console.log(` ${colors.green}[${n}]${colors.reset}${String(n).length === 1 ? ' ' : ''} ${icon} ${colors.bold}${title.padEnd(24)}${colors.reset} - ${desc}`);
30
+ const section = (title) => console.log(`\n ${colors.dim}โ”€โ”€ ${title} โ”€โ”€${colors.reset}`);
31
+
32
+ console.log(`\n${colors.bold}${colors.cyan}Select an action to perform:${colors.reset}`);
33
+
34
+ section('Protection');
35
+ item(1, '๐Ÿ›ก๏ธ ', 'Install Local Hook', 'Protect current repo (push + checkout + pull)');
36
+ item(2, '๐ŸŒ', 'Install Global Hook', 'Protect EVERY repo on this PC: scan on clone, pull & push');
37
+ item(8, 'โŒ', 'Uninstall Hook', 'Remove GitSafty hooks');
38
+
39
+ section('Malware scan & removal');
40
+ item(3, '๐Ÿ”', 'Scan Local Workspace', 'Deep scan this repo, auto-remove confirmed malware');
41
+ item(10, '๐Ÿงน', 'Sweep All Repos', 'Scan every git repo in a folder (whole device)');
42
+ item(5, '๐Ÿ—‘๏ธ ', 'Clean & Quarantine', 'Remove confirmed malware + trojan scripts here');
43
+ item(4, '๐Ÿš€', 'Scan Remote GitHub Repo', 'Zero-clone audit (no download/clone)');
44
+
45
+ section('GitHub login vault (device stays logged out)');
46
+ item(11, '๐Ÿ”', 'Vault Setup', 'Encrypt token with Touch ID / Windows Hello / passphrase');
47
+ item(12, '๐Ÿ“‹', 'Vault Status', 'Check vault, credential helper & SSH keys');
48
+ item(13, '๐Ÿ”“', 'Vault Test Unlock', 'Try one unlock prompt (token is not used)');
49
+ item(14, '๐Ÿšซ', 'Vault Remove', 'Back to normal git login');
50
+
51
+ section('Other');
52
+ item(6, 'โšก', 'Run Push Intercept Demo', 'Simulate a blocked malware push');
53
+ item(7, '๐Ÿค–', 'Setup GitHub Action CI', 'Guard repository on GitHub server-side');
54
+ item(9, '๐Ÿ”„', 'Check for Updates', 'Check if a new version is available on npm');
55
+ console.log(` ${colors.dim}[0] ๐Ÿšช Exit${colors.reset}\n`);
27
56
 
28
57
  const rl = readline.createInterface({
29
58
  input: process.stdin,
@@ -31,7 +60,7 @@ async function runInteractiveMenu() {
31
60
  });
32
61
 
33
62
  const choice = await new Promise((resolve) => {
34
- rl.question(`${colors.bold}${colors.yellow}Enter your choice (1-9, 0 to exit): ${colors.reset}`, (ans) => {
63
+ rl.question(`${colors.bold}${colors.yellow}Enter your choice (1-14, 0 to exit): ${colors.reset}`, (ans) => {
35
64
  rl.close();
36
65
  resolve(ans.trim());
37
66
  });
@@ -39,7 +68,7 @@ async function runInteractiveMenu() {
39
68
 
40
69
  switch (choice) {
41
70
  case '1': {
42
- console.log(`\n${colors.cyan}Installing local pre-push hook...${colors.reset}`);
71
+ console.log(`\n${colors.cyan}Installing local hooks (push + checkout + pull scan)...${colors.reset}`);
43
72
  const res = installHook(process.cwd(), false);
44
73
  if (res.success) {
45
74
  console.log(`\n${colors.green}${colors.bold}โœ” ${res.message}${colors.reset}\n`);
@@ -50,7 +79,7 @@ async function runInteractiveMenu() {
50
79
  }
51
80
 
52
81
  case '2': {
53
- console.log(`\n${colors.cyan}Installing GLOBAL pre-push hook for all repositories...${colors.reset}`);
82
+ console.log(`\n${colors.cyan}Installing GLOBAL hooks (push + clone + pull scan) for all repositories...${colors.reset}`);
54
83
  const res = installHook(process.cwd(), true);
55
84
  if (res.success) {
56
85
  console.log(`\n${colors.green}${colors.bold}โœ” ${res.message}${colors.reset}\n`);
@@ -97,6 +126,8 @@ async function runInteractiveMenu() {
97
126
 
98
127
  case '5': {
99
128
  console.log(`\n${colors.cyan}Scanning workspace for injected malware scripts to quarantine...${colors.reset}`);
129
+ const { getAllRepoFiles } = require('./utils/git');
130
+ scanAndCleanRepo(getAllRepoFiles(), process.cwd(), { reason: 'clean' });
100
131
  const cleanResult = cleanInfectedFiles();
101
132
  if (cleanResult.quarantined.length > 0) {
102
133
  console.log(`\n${colors.yellow}${colors.bold}โš  Quarantined ${cleanResult.quarantined.length} malicious file(s):${colors.reset}`);
@@ -151,6 +182,38 @@ async function runInteractiveMenu() {
151
182
  break;
152
183
  }
153
184
 
185
+ case '10': {
186
+ const folder = await ask(`\n${colors.bold}${colors.cyan}? Folder to sweep (Enter = ${process.cwd()}): ${colors.reset}`);
187
+ const removeAnswer = await ask(`${colors.bold}${colors.cyan}? Automatically remove CONFIRMED malware? Suspicious items are never touched. (Y/n): ${colors.reset}`);
188
+ const clean = !/^n(o)?$/i.test(removeAnswer);
189
+ runSweep(folder || process.cwd(), { clean });
190
+ break;
191
+ }
192
+
193
+ case '11': {
194
+ const mode = await ask(`\n${colors.bold}${colors.cyan}? Protect with this device's security chip (Touch ID / Windows Hello)? (Y = chip, n = passphrase only): ${colors.reset}`);
195
+ await runVaultCommand('setup', { passphrase: /^n(o)?$/i.test(mode) });
196
+ break;
197
+ }
198
+
199
+ case '12':
200
+ await runVaultCommand('status');
201
+ break;
202
+
203
+ case '13':
204
+ await runVaultCommand('test');
205
+ break;
206
+
207
+ case '14': {
208
+ const sure = await ask(`\n${colors.bold}${colors.yellow}? Remove the vault and go back to normal git login? (y/N): ${colors.reset}`);
209
+ if (/^y(es)?$/i.test(sure)) {
210
+ await runVaultCommand('remove');
211
+ } else {
212
+ console.log(`${colors.dim}Vault kept.${colors.reset}\n`);
213
+ }
214
+ break;
215
+ }
216
+
154
217
  case '0':
155
218
  default:
156
219
  console.log(`\n${colors.dim}Goodbye! ๐Ÿ›ก๏ธ${colors.reset}\n`);
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Terminal output for `gitsafty vault <sub>` (shared by the CLI and the menu).
3
+ */
4
+
5
+ const { colors } = require('./reporter');
6
+
7
+ /**
8
+ * @param {string} sub setup | status | test | remove
9
+ * @param {{ host?: string, passphrase?: boolean }} [options]
10
+ * @returns {Promise<number>} exit code
11
+ */
12
+ async function runVaultCommand(sub = 'status', { host, passphrase = false } = {}) {
13
+ const vault = require('./vault');
14
+ sub = String(sub || 'status').toLowerCase();
15
+
16
+ if (sub === 'setup' || sub === 'on' || sub === 'enable') {
17
+ const res = await vault.setupVault({ host: host || 'github.com', mode: passphrase ? 'passphrase' : 'auto' });
18
+ if (!res.success) {
19
+ console.error(`\n${colors.red}${colors.bold}โœ– ${res.message}${colors.reset}\n`);
20
+ return 1;
21
+ }
22
+ console.log(`\n${colors.green}${colors.bold}โœ” ${res.message}${colors.reset}`);
23
+ for (const step of res.steps) console.log(` ${colors.dim}โ€ข${colors.reset} ${step}`);
24
+ for (const key of res.sshWarnings) {
25
+ console.log(`\n${colors.yellow}โš  SSH key without passphrase: ${key}${colors.reset}`);
26
+ console.log(` ${colors.dim}Anyone who copies it can push as you. Protect it: ${colors.reset}ssh-keygen -p -f ${key}`);
27
+ }
28
+ console.log('');
29
+ return 0;
30
+ }
31
+
32
+ if (sub === 'test') {
33
+ const res = vault.testUnlock();
34
+ console.log(`\n${res.success ? colors.green + 'โœ”' : colors.red + 'โœ–'} ${res.message}${colors.reset}\n`);
35
+ return res.success ? 0 : 1;
36
+ }
37
+
38
+ if (sub === 'remove' || sub === 'off' || sub === 'disable') {
39
+ const res = vault.removeVault({ host });
40
+ console.log(`\n${colors.yellow}${colors.bold}โœ” ${res.message}${colors.reset}\n`);
41
+ return 0;
42
+ }
43
+
44
+ const st = vault.vaultStatus({ host });
45
+ const ok = (b) => (b ? `${colors.green}โœ”` : `${colors.red}โœ–`) + colors.reset;
46
+ console.log(`\n${colors.bold}GitSafty Vault (${st.host})${colors.reset}`);
47
+ console.log(` ${ok(st.vaultExists)} Encrypted token vault ${st.vaultExists ? `(${st.username}, file mode ${st.vaultMode})` : '(not set up: run gitsafty vault setup)'}`);
48
+ if (st.vaultExists) {
49
+ const hw = st.protection !== 'passphrase';
50
+ 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)'}`);
51
+ }
52
+ if (st.tokenExpiresAt) console.log(` ${colors.dim}Token expires: ${st.tokenExpiresAt}${colors.reset}`);
53
+ console.log(` ${ok(st.helperActive)} GitSafty is git's credential helper for ${st.host}`);
54
+ console.log(` ${ok(st.otherHelpers.length === 0)} No other helper can store or hand out a token${st.otherHelpers.length ? `: ${st.otherHelpers.join(', ')}` : ''}`);
55
+ console.log(` ${ok(st.sshWarnings.length === 0)} SSH private keys are passphrase-protected${st.sshWarnings.length ? `: ${st.sshWarnings.join(', ')}` : ''}`);
56
+ console.log('');
57
+ return 0;
58
+ }
59
+
60
+ module.exports = { runVaultCommand };