@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 +24 -11
- package/bin/cli.js +6 -39
- package/package.json +1 -1
- package/src/menu.js +78 -15
- package/src/vaultCli.js +60 -0
package/README.md
CHANGED
|
@@ -62,17 +62,30 @@ gitsafty
|
|
|
62
62
|
|
|
63
63
|
Select an action to perform:
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
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
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
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
|
-
|
|
17
|
-
|
|
18
|
-
console.log(
|
|
19
|
-
|
|
20
|
-
console.log(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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-
|
|
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
|
|
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
|
|
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`);
|
package/src/vaultCli.js
ADDED
|
@@ -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 };
|