@arifbiswas/git-pre-push 1.0.19 β 1.0.20
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 +194 -342
- package/package.json +1 -1
- package/src/envGuard.js +262 -0
- package/src/index.js +40 -0
- package/src/menu.js +45 -45
- package/src/reporter.js +1 -1
- package/src/utils/git.js +2 -2
package/README.md
CHANGED
|
@@ -1,479 +1,331 @@
|
|
|
1
|
-
#
|
|
1
|
+
# GitSafty (`@arifbiswas/git-pre-push`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
> Intercepts `git push` in real-time to prevent malware, Trojan scripts, compromised IDE configs, and leaked credentials from ever reaching GitHub or poisoning your software supply chain.
|
|
3
|
+
Protects your code and your GitHub account from malware, without changing how you work.
|
|
5
4
|
|
|
6
|
-
[](https://github.com/arifbiswas/git-pre-push/releases)
|
|
7
|
-
[](https://github.com/arifbiswas/git-pre-push/actions/workflows/ci.yml)
|
|
8
5
|
[](https://www.npmjs.com/package/@arifbiswas/git-pre-push)
|
|
9
6
|
[](LICENSE)
|
|
10
|
-
[](#-test-coverage)
|
|
12
|
-
[](#-cross-platform--zero-dependencies)
|
|
7
|
+
[](#)
|
|
13
8
|
|
|
14
9
|
---
|
|
15
10
|
|
|
16
|
-
##
|
|
11
|
+
## What you get
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
**`git-pre-push` stops this attack chain at the source.**
|
|
27
|
-
Whenever `git push` is invokedβfrom terminal, VS Code UI, or any Git GUIβit intercepts the push in milliseconds, inspects outgoing files and commit diffs, and **hard-blocks the push** if any malicious patterns are found.
|
|
13
|
+
- **Malware never reaches GitHub.** Every `git push` is checked. A push with malware is stopped before it leaves your computer.
|
|
14
|
+
- **Infected projects are cleaned for you.** After every `git clone` and `git pull`, the project is checked and malware that GitSafty is sure about is removed automatically. Anything it is not 100% sure about is only reported, never touched.
|
|
15
|
+
- **Your `.env` stays private.** If a push contains a `.env` file, GitSafty takes it out, adds it to `.gitignore`, and pushes your code without it.
|
|
16
|
+
- **Your GitHub login can't be stolen.** With safe login on, your computer stays logged out of GitHub. Each push asks for Touch ID, Windows Hello or a password, and logs out again.
|
|
17
|
+
- **Check everything at once.** Scan a whole folder of projects, your Downloads, zip/rar files, or a GitHub repo before you clone it.
|
|
18
|
+
- **Backups of everything removed**, and a clear report of what was found and what was done.
|
|
19
|
+
- Works with the terminal, VS Code and any git app, on macOS, Windows and Linux. No extra packages are installed.
|
|
28
20
|
|
|
29
21
|
---
|
|
30
22
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
> **Install globally (`-g`).** `npm i @arifbiswas/git-pre-push` without `-g` only puts GitSafty into that project's `node_modules`: there is no `gitsafty` command and other repos stay unprotected. npm does not let a package install itself globally, so when GitSafty notices it is running from a project (or from `npx`) it asks *"Install GitSafty globally now? (Y/n)"* and does it for you. The recommended command is:
|
|
34
|
-
>
|
|
35
|
-
> ```bash
|
|
36
|
-
> npm install -g @arifbiswas/git-pre-push
|
|
37
|
-
> gitsafty init --global
|
|
38
|
-
> ```
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Option 1: Automatic Setup via npm (Recommended)
|
|
23
|
+
## Install (2 minutes)
|
|
42
24
|
|
|
43
|
-
|
|
25
|
+
You need [Node.js](https://nodejs.org) 18 or newer and git.
|
|
44
26
|
|
|
45
27
|
```bash
|
|
46
|
-
npm install -
|
|
28
|
+
npm install -g @arifbiswas/git-pre-push
|
|
47
29
|
```
|
|
48
30
|
|
|
49
|
-
|
|
31
|
+
```bash
|
|
32
|
+
gitsafty init --global
|
|
33
|
+
```
|
|
50
34
|
|
|
51
|
-
|
|
35
|
+
That's it. Every git project on this computer is now protected.
|
|
52
36
|
|
|
53
|
-
|
|
37
|
+
- Use `-g`. Without it GitSafty only lands inside one project and the `gitsafty` command does not exist. If you forget, GitSafty asks to install itself globally the first time it runs.
|
|
38
|
+
- **Windows: `'gitsafty' is not recognized`?** Open a new terminal. Still not found? Add the folder shown by `npm config get prefix` to your `Path`.
|
|
39
|
+
- After `init --global`, GitSafty offers one extra step: checking pulls that say *"Already up to date"* too. Answer `y` for full coverage.
|
|
54
40
|
|
|
55
|
-
|
|
41
|
+
Protect only one project instead:
|
|
56
42
|
|
|
57
43
|
```bash
|
|
58
|
-
|
|
44
|
+
cd my-project
|
|
45
|
+
gitsafty init
|
|
59
46
|
```
|
|
60
47
|
|
|
61
|
-
|
|
62
|
-
> ```bash
|
|
63
|
-
> npm install -g @arifbiswas/git-pre-push
|
|
64
|
-
> gitsafty init --global
|
|
65
|
-
> ```
|
|
66
|
-
> 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.
|
|
48
|
+
---
|
|
67
49
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
gitsafty
|
|
71
|
-
```
|
|
50
|
+
## The menu
|
|
51
|
+
|
|
52
|
+
Run `gitsafty` with nothing after it:
|
|
72
53
|
|
|
73
54
|
```text
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
[9] π Check for Updates - Check if a new version is available on npm
|
|
104
|
-
[15] π©Ί Doctor - Something broken? Find it and show/apply the fix
|
|
105
|
-
[0] πͺ Exit
|
|
106
|
-
|
|
107
|
-
Enter your choice (1-16, 0 to exit):
|
|
55
|
+
What do you want to do?
|
|
56
|
+
|
|
57
|
+
Protect your code
|
|
58
|
+
1. Protect this project Check every push, clone and pull in this project
|
|
59
|
+
2. Protect all projects on this PC Same, for every git project on this computer
|
|
60
|
+
3. Scan every git pull Also when git says "Already up to date" (on/off)
|
|
61
|
+
4. Remove protection Uninstall GitSafty from this project or this PC
|
|
62
|
+
|
|
63
|
+
Scan and clean
|
|
64
|
+
5. Scan this project Find malware here and remove it automatically
|
|
65
|
+
6. Scan all projects in a folder Malware, hidden backdoors and leaked passwords/keys
|
|
66
|
+
7. Scan everything in a folder Also zip/rar files and folders that are not git projects
|
|
67
|
+
8. Scan all git repos under a folder Quick malware check, e.g. your whole disk
|
|
68
|
+
9. Clean this project Move malware files in this project to quarantine
|
|
69
|
+
10. Scan a GitHub repo before cloning Check a GitHub link without downloading it
|
|
70
|
+
|
|
71
|
+
Safe GitHub login (stay logged out)
|
|
72
|
+
11. Turn on safe GitHub login Touch ID / Windows Hello / password before every push
|
|
73
|
+
12. Check safe login status See if your GitHub login is protected
|
|
74
|
+
13. Test safe login Try the unlock prompt once
|
|
75
|
+
14. Turn off safe login Go back to normal git login
|
|
76
|
+
|
|
77
|
+
Help and tools
|
|
78
|
+
15. Fix problems Find what is broken and how to fix it
|
|
79
|
+
16. Check for updates Install the newest GitSafty
|
|
80
|
+
17. Add GitSafty to GitHub Actions Check every push on GitHub too
|
|
81
|
+
18. See a demo Show what a blocked push looks like
|
|
82
|
+
|
|
83
|
+
0. Exit
|
|
108
84
|
```
|
|
109
85
|
|
|
110
|
-
|
|
86
|
+
Everything in the menu is also a command, listed below.
|
|
111
87
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
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`.
|
|
88
|
+
---
|
|
115
89
|
|
|
116
|
-
|
|
90
|
+
## Everyday use
|
|
117
91
|
|
|
118
|
-
|
|
92
|
+
After `gitsafty init --global` you don't need to do anything. Use git as usual:
|
|
119
93
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
94
|
+
| You run | GitSafty does |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `git push` | Checks what you push. Blocks malware and leaked secrets. Takes `.env` files out and pushes without them. |
|
|
97
|
+
| `git clone` | Checks the new project and removes confirmed malware right away. |
|
|
98
|
+
| `git pull` | Checks the project again after new code arrives. |
|
|
123
99
|
|
|
124
|
-
|
|
100
|
+
When something is removed, you see what it was and where the backup is. Files inside a project are changed only in your working folder: check `git status`, then commit the clean version.
|
|
125
101
|
|
|
126
|
-
|
|
102
|
+
### Scan every pull
|
|
127
103
|
|
|
128
|
-
|
|
104
|
+
Git runs nothing when a pull says *"Already up to date"*. To check those pulls too:
|
|
129
105
|
|
|
130
106
|
```bash
|
|
131
|
-
gitsafty pull-scan on
|
|
132
|
-
gitsafty pull-scan off # remove the function again
|
|
107
|
+
gitsafty pull-scan on
|
|
133
108
|
```
|
|
134
109
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## β‘ How It Works
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
Developer or Malware executes: git push
|
|
143
|
-
β
|
|
144
|
-
βΌ
|
|
145
|
-
Git triggers: .git/hooks/pre-push
|
|
146
|
-
β
|
|
147
|
-
βΌ
|
|
148
|
-
π‘οΈ GitSafty Scanner Engine (< 5ms)
|
|
149
|
-
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
150
|
-
β 1. Blacklist check (temp_*_push.bat, .exe, .ps1, .vbs) β
|
|
151
|
-
β 2. Outgoing commit diff inspection for payload cradles β
|
|
152
|
-
β 3. IDE backdoor inspection (.vscode/tasks.json, .idea) β
|
|
153
|
-
β 4. Credential & secret leak detection (.env, RSA keys) β
|
|
154
|
-
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
155
|
-
β
|
|
156
|
-
βββββββββββββββββββββββ΄ββββββββββββββββββββββ
|
|
157
|
-
βΌ βΌ
|
|
158
|
-
[Threats Found] [Clean Scan]
|
|
159
|
-
β β
|
|
160
|
-
β PUSH REJECTED β
PUSH ALLOWED
|
|
161
|
-
(Malware blocked locally) (Pushed cleanly to GitHub)
|
|
110
|
+
```bash
|
|
111
|
+
gitsafty pull-scan off
|
|
162
112
|
```
|
|
163
113
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
## π― Threat Detection Capabilities
|
|
167
|
-
|
|
168
|
-
### 1. Injected Scripts & Trojan Filenames
|
|
169
|
-
- Known malicious auto-push scripts: `temp_auto_push.bat`, `temp_interactive_push.bat`, `config.bat`, `autorun.bat`, `hidden_push.sh`
|
|
170
|
-
- Blocked executable extensions: `*.exe`, `*.scr`, `*.msi`, `*.dll`, `*.vbs`, `*.ps1`, `*.hta`, `*.pif`, `*.cpl`
|
|
171
|
-
- Deceptive double-extension tricks: `document.pdf.exe`, `invoice.xlsx.bat`
|
|
172
|
-
|
|
173
|
-
### 2. Obfuscated Payloads & Reverse Shells
|
|
174
|
-
- PowerShell obfuscated execution: `powershell -enc`, `powershell -encodedcommand`
|
|
175
|
-
- Web download cradles: `Invoke-WebRequest`, `DownloadString`, `IEX`
|
|
176
|
-
- Remote pipe-to-shell: `curl ... | bash`, `wget ... | sh`, `curl ... | python`
|
|
177
|
-
- Dynamic base64 evaluation: `eval(base64_decode(...))`, `Buffer.from(..., 'base64')`
|
|
178
|
-
- Windows LOLBins abuse: `certutil -urlcache`, `bitsadmin /transfer`, `mshta http`
|
|
179
|
-
- TCP socket reverse shells: `/bin/sh -i >& /dev/tcp/...`, `nc -e /bin/sh`
|
|
180
|
-
|
|
181
|
-
### 3. IDE Configuration Backdoors
|
|
182
|
-
- `.vscode/tasks.json`: Auto-executing shell tasks triggered on folder open (`runOn: "folderOpen"`)
|
|
183
|
-
- `.vscode/settings.json`: Malicious terminal profile overrides or shell binary path hijacking
|
|
184
|
-
- JetBrains `.idea/`: Suspicious external tool execution in `workspace.xml` or `tasks.xml`
|
|
185
|
-
|
|
186
|
-
### 4. Credential Exfiltration & Secret Leaks
|
|
187
|
-
- Hardcoded Discord webhook dumps (`https://discord.com/api/webhooks/...`)
|
|
188
|
-
- Telegram Bot token exfiltration endpoints
|
|
189
|
-
- Temporary file drop & webhook logging services (`webhook.site`, `pipedream.net`, `filebin.net`)
|
|
190
|
-
- Unencrypted production `.env` files being committed
|
|
191
|
-
- Leaked cryptographic private keys (`BEGIN RSA PRIVATE KEY`, `ghp_...`, AWS Access Keys)
|
|
192
|
-
|
|
193
|
-
### 5. Deep Malware Engine (clone, pull, push)
|
|
194
|
-
Built from real samples of a repository-injection campaign. Every finding gets a verdict:
|
|
195
|
-
|
|
196
|
-
| Verdict | Meaning | What GitSafty does |
|
|
197
|
-
|---|---|---|
|
|
198
|
-
| **MALWARE** (confirmed) | Proof-level signature that legitimate code never produces | Reports it, backs the file up, **removes it automatically**, re-scans to verify |
|
|
199
|
-
| **SUSPECT** | Dangerous-looking but can be legitimate | Reports only, never touches the file |
|
|
200
|
-
|
|
201
|
-
Confirmed signatures:
|
|
202
|
-
- Exact SHA-256 of known malware samples
|
|
203
|
-
- `global['!']='9-5756'` loader marker next to an obfuscated decoder
|
|
204
|
-
- Obfuscated payload hidden after 120+ spaces at the end of a normal line (e.g. infected `tailwind.js`). Only the hidden part is cut out, the rest of the file is kept
|
|
205
|
-
- Script disguised as a font or image (`.woff2`, `.ttf`, `.png`, ... whose bytes are JavaScript, not the real format; Git LFS pointers are ignored)
|
|
206
|
-
- `.vscode/tasks.json` task with `runOn: folderOpen` that runs a font/image with `node`/`python`/... or pipes the internet into a shell. Only that task is removed
|
|
207
|
-
- `package.json` install scripts that run a font/image as code
|
|
208
|
-
|
|
209
|
-
Backups (read-only) and a `report.json` go to `.git/gitsafty-quarantine/<time>/`. Turn auto-removal off with `"autoClean": false` or `GITSAFTY_NO_AUTOCLEAN=1`.
|
|
114
|
+
Open a new terminal afterwards. Menu option **3** does the same.
|
|
210
115
|
|
|
211
116
|
---
|
|
212
117
|
|
|
213
|
-
##
|
|
118
|
+
## Scanning
|
|
214
119
|
|
|
215
|
-
|
|
120
|
+
### This project
|
|
216
121
|
|
|
217
122
|
```bash
|
|
218
|
-
|
|
123
|
+
gitsafty scan
|
|
219
124
|
```
|
|
220
125
|
|
|
221
|
-
|
|
126
|
+
Checks the whole project and removes confirmed malware. Add `--no-clean` to only report. Menu **5**.
|
|
222
127
|
|
|
223
|
-
|
|
224
|
-
|---|---|---|
|
|
225
|
-
| macOS (Apple Silicon / T2) | **Secure Enclave** P-256 key (`.userPresence`), ECDH β HKDF-SHA256 β **AES-256-GCM** | Touch ID or Mac password (system dialog) |
|
|
226
|
-
| Windows 10/11 | **Windows Hello** key in the **TPM**, signature of a random challenge β SHA-256 β HKDF-SHA256 β **AES-256-GCM** | Hello PIN, face or fingerprint |
|
|
227
|
-
| Linux / no chip | Passphrase β **scrypt** (N=2ΒΉβ·, r=8, p=1) β **AES-256-GCM** | Your vault passphrase |
|
|
128
|
+
### All projects in a folder
|
|
228
129
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
4. Every unlock and every refused unlock shows a desktop notification. A prompt or notification for a push you did not start means someone else is on your machine: press Cancel.
|
|
130
|
+
```bash
|
|
131
|
+
gitsafty scan-projects ~/projects
|
|
132
|
+
```
|
|
233
133
|
|
|
234
134
|
```bash
|
|
235
|
-
|
|
236
|
-
npx @arifbiswas/git-pre-push vault test # one unlock prompt, token is not used
|
|
237
|
-
npx @arifbiswas/git-pre-push vault remove # back to normal git login
|
|
135
|
+
gitsafty scan-projects ~/projects --clean
|
|
238
136
|
```
|
|
239
137
|
|
|
240
|
-
|
|
138
|
+
For a folder with many projects. For each project it reports malware, hidden backdoors (things that run code when you open the project or use git), and passwords or API keys written in the code. At the end you get a table per project: what was found, what was removed, and what you still need to look at, with the command to fix it. Only `--clean` removes anything. Menu **6**.
|
|
241
139
|
|
|
242
|
-
|
|
140
|
+
- `--deep` also checks `node_modules` and ignored files.
|
|
141
|
+
- `--json` gives machine-readable output.
|
|
243
142
|
|
|
244
|
-
|
|
143
|
+
### Everything in a folder, zip files too
|
|
245
144
|
|
|
246
|
-
|
|
145
|
+
```bash
|
|
146
|
+
gitsafty full-scan ~/Downloads
|
|
147
|
+
```
|
|
247
148
|
|
|
248
149
|
```bash
|
|
249
|
-
gitsafty full-scan ~/Downloads
|
|
250
|
-
gitsafty full-scan ~/Downloads --clean # also remove CONFIRMED malware
|
|
251
|
-
gitsafty full-scan ./some-file.zip # a single archive
|
|
252
|
-
gitsafty full-scan ~/projects --json # machine-readable output
|
|
150
|
+
gitsafty full-scan ~/Downloads --clean
|
|
253
151
|
```
|
|
254
152
|
|
|
255
|
-
|
|
256
|
-
- **Inside archives**: zip, jar, war, apk, aab, aar, ipa, xpi, vsix, nupkg, whl, crx, docx/xlsx/pptx, tar, tar.gz/tgz, gz, and also archives inside archives. Archives are found by their first bytes, so a renamed one is still opened. Nothing is extracted to disk and nothing inside is run.
|
|
257
|
-
- **7z, rar, bz2, xz, cab**: read through the system `bsdtar` (built into macOS and Windows 10+) or 7-Zip if it is installed. If neither can open it, the report says so.
|
|
258
|
-
- **Password-protected archives** can't be read. One that contains programs (`.exe`, `.js`, `.bat` β¦) is flagged, because malware is often sent that way.
|
|
259
|
-
- **Skipped**: `node_modules`, composer `vendor`, `Pods`, virtualenvs, `.gradle`, package caches and lock files (`package-lock.json`, `composer.lock` β¦). These are downloaded packages, not your code. `package.json` and `composer.json` are still checked, because malicious install scripts live there.
|
|
260
|
-
- Zip-bomb safe: at most 64 MB per file inside an archive, 1 GB per archive, 4 levels of nesting.
|
|
153
|
+
Checks every file, also folders that are not git projects, and the files **inside** zip, rar, 7z, tar.gz, jar, apk and similar archives, without unpacking them. Use it for downloads, old backups or a project someone sent you as a zip. `node_modules`, `vendor` and other downloaded packages are skipped. With `--clean`, an infected archive is moved to quarantine. Menu **7**.
|
|
261
154
|
|
|
262
|
-
|
|
155
|
+
### All git repos on your disk
|
|
263
156
|
|
|
264
|
-
|
|
157
|
+
```bash
|
|
158
|
+
gitsafty sweep ~
|
|
159
|
+
```
|
|
265
160
|
|
|
266
|
-
|
|
161
|
+
A fast malware check of every git repository under a folder. Menu **8**.
|
|
267
162
|
|
|
268
|
-
|
|
163
|
+
### A GitHub repo before you clone it
|
|
269
164
|
|
|
270
165
|
```bash
|
|
271
|
-
gitsafty scan-
|
|
272
|
-
gitsafty scan-projects ~/projects --clean # also remove CONFIRMED malware
|
|
273
|
-
gitsafty scan-projects ~/projects --deep # include node_modules, build output, ignored files
|
|
274
|
-
gitsafty scan-projects ~/projects --json # machine-readable output
|
|
166
|
+
gitsafty scan-remote https://github.com/owner/repo
|
|
275
167
|
```
|
|
276
168
|
|
|
277
|
-
|
|
169
|
+
Nothing is downloaded to your disk. Menu **10**.
|
|
170
|
+
|
|
171
|
+
---
|
|
278
172
|
|
|
279
|
-
|
|
280
|
-
- **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
|
|
281
|
-
- **IDE auto-run**: `.vscode` / `.idea` tasks and settings
|
|
282
|
-
- **Exposed secrets**: keys and tokens in code, and `.env` files that git tracks (masked in the output)
|
|
283
|
-
- **Dangerous files**: executables, disguised double extensions
|
|
173
|
+
## Your `.env` file never gets pushed
|
|
284
174
|
|
|
285
|
-
|
|
175
|
+
If you commit a `.env` (or `.env.local`, `.env.production` β¦) and push, GitSafty:
|
|
286
176
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
mobile-app SECRETS 3 0 3
|
|
293
|
-
landing CLEAN 0 0 0
|
|
294
|
-
```
|
|
177
|
+
1. Stops that push.
|
|
178
|
+
2. Adds `.env` to `.gitignore`. `.env.example` stays allowed.
|
|
179
|
+
3. Takes the `.env` out of git, including a `.env` that git kept tracking even though it was already in `.gitignore`. The file stays on your computer.
|
|
180
|
+
4. Removes it from your commits that were not pushed yet.
|
|
181
|
+
5. Pushes your code without it.
|
|
295
182
|
|
|
296
|
-
|
|
183
|
+
Git then shows `failed to push` for the first attempt, the one that still had the `.env`. That is expected: your code is already on GitHub without it.
|
|
184
|
+
|
|
185
|
+
If a `.env` was pushed **before** you used GitSafty, it is removed from GitHub with your next push, but old versions can still be seen in the history. **Change the passwords and keys in it.**
|
|
297
186
|
|
|
298
187
|
---
|
|
299
188
|
|
|
300
|
-
##
|
|
189
|
+
## Safe GitHub login
|
|
301
190
|
|
|
302
|
-
|
|
191
|
+
Malware on a computer usually steals saved logins. With safe login on, there is no saved GitHub login to steal.
|
|
303
192
|
|
|
304
193
|
```bash
|
|
305
|
-
gitsafty
|
|
306
|
-
gitsafty doctor --fix # apply the safe fixes (rewrite hooks, re-register the vault helper)
|
|
194
|
+
gitsafty vault setup
|
|
307
195
|
```
|
|
308
196
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
**
|
|
197
|
+
1. Paste a GitHub token once. GitSafty stores it encrypted and locks it to this computer's security chip.
|
|
198
|
+
2. Your other saved GitHub logins are removed.
|
|
199
|
+
3. On every push you confirm with **Touch ID or your Mac password** (macOS), **Windows Hello** (Windows), or a passphrase (Linux / no chip). After the push you are logged out again.
|
|
200
|
+
4. A prompt you did not expect means someone else is trying to push: press Cancel.
|
|
312
201
|
|
|
313
|
-
|
|
314
|
-
|---|---|
|
|
315
|
-
| `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) |
|
|
316
|
-
| `ENOTFOUND` / `ETIMEDOUT` | Network/proxy: `npm config get registry`, `npm cache verify`, try again |
|
|
317
|
-
| `Unexpected token` / engine warning | Node.js too old: install Node 18+ (`nvm install --lts`) |
|
|
202
|
+
The token file is useless on any other computer.
|
|
318
203
|
|
|
319
|
-
|
|
204
|
+
```bash
|
|
205
|
+
gitsafty vault status
|
|
206
|
+
```
|
|
320
207
|
|
|
321
208
|
```bash
|
|
322
|
-
|
|
323
|
-
rm -rf ~/.git-hooks-safty # Windows PowerShell: Remove-Item -Recurse -Force "$HOME\.git-hooks-safty"
|
|
324
|
-
git config --global --remove-section credential.https://github.com # only if you used the vault
|
|
209
|
+
gitsafty vault test
|
|
325
210
|
```
|
|
326
211
|
|
|
327
|
-
|
|
212
|
+
```bash
|
|
213
|
+
gitsafty vault remove
|
|
214
|
+
```
|
|
328
215
|
|
|
329
|
-
|
|
216
|
+
Tips:
|
|
330
217
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
| `npx @arifbiswas/git-pre-push init` | Installs the pre-push security hook into `.git/hooks/pre-push` |
|
|
334
|
-
| `npx @arifbiswas/git-pre-push init --global` | Protects **all** Git repositories across the entire PC |
|
|
335
|
-
| `npx @arifbiswas/git-pre-push scan` | Manually audits local workspace files, untracked scripts & staged diffs |
|
|
336
|
-
| `npx @arifbiswas/git-pre-push scan-remote` | **Zero-Clone Audit:** Scans any remote GitHub repo without cloning or downloading |
|
|
337
|
-
| `npx @arifbiswas/git-pre-push sweep [folder]` | Scans **every** Git repo under a folder (e.g. your projects folder) and removes confirmed malware |
|
|
338
|
-
| `npx @arifbiswas/git-pre-push vault setup` | Keeps the device logged out of GitHub; token is encrypted and unlocked only for each push |
|
|
339
|
-
| `npx @arifbiswas/git-pre-push clean` | Unstages and quarantines injected malware files to `.git/git-safty-quarantine/` |
|
|
340
|
-
| `npx @arifbiswas/git-pre-push demo` | Simulates a blocked push in terminal |
|
|
341
|
-
| `npx @arifbiswas/git-pre-push action` | Generates a `.github/workflows/git-safty.yml` CI workflow |
|
|
342
|
-
| `npx @arifbiswas/git-pre-push scan-projects <folder>` | **Advanced Scanner**: audit every project in a folder (malware, git backdoors, IDE, secrets) |
|
|
343
|
-
| `npx @arifbiswas/git-pre-push full-scan <folder> [--clean]` | **Full Scan**: everything in a folder, also non-git projects and inside zip/jar/apk/tar/gz/7z/rar |
|
|
344
|
-
| `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) |
|
|
345
|
-
| `npx @arifbiswas/git-pre-push doctor [--fix]` | Finds broken/outdated installs and shows (or applies) the exact fix |
|
|
346
|
-
| `npx @arifbiswas/git-pre-push uninstall` | Cleanly removes the hook from `.git/hooks` |
|
|
218
|
+
- Use a fine-grained token that expires and only has access to the repos you need.
|
|
219
|
+
- Safe login covers HTTPS remotes. If you push over SSH, give your SSH key a passphrase: `ssh-keygen -p -f ~/.ssh/id_ed25519`.
|
|
347
220
|
|
|
348
221
|
---
|
|
349
222
|
|
|
350
|
-
##
|
|
223
|
+
## Protect the repository on GitHub too
|
|
351
224
|
|
|
352
|
-
|
|
225
|
+
Someone can skip local checks with `git push --no-verify`. Add the same check to GitHub Actions:
|
|
353
226
|
|
|
354
227
|
```bash
|
|
355
|
-
|
|
228
|
+
gitsafty action
|
|
356
229
|
```
|
|
357
230
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
231
|
+
This adds `.github/workflows/git-safty.yml`. Commit and push it. Menu **17**.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Updates
|
|
236
|
+
|
|
237
|
+
When you open `gitsafty` it tells you if a new version is out and asks `Install now? (Y/n)`. Or update yourself:
|
|
362
238
|
|
|
363
|
-
Or pass the URL directly:
|
|
364
239
|
```bash
|
|
365
|
-
|
|
240
|
+
npm install -g @arifbiswas/git-pre-push
|
|
366
241
|
```
|
|
367
242
|
|
|
368
|
-
|
|
369
|
-
1. Fetches the repository's recursive Git tree metadata via GitHub REST API in **1 single HTTP request**.
|
|
370
|
-
2. Performs instant in-memory path matching against all trojan filenames and blacklisted extensions.
|
|
371
|
-
3. Only if a suspicious file is discovered, fetches the specific blob directly into RAM for static payload/secret analysis.
|
|
372
|
-
4. **0 MB downloaded to disk** β fast, lightweight, and completely bandwidth-friendly.
|
|
243
|
+
npm 11 may print `install scripts not yet covered by allowScripts`. The update still worked. GitSafty finishes its setup by itself the next time it runs.
|
|
373
244
|
|
|
374
245
|
---
|
|
375
246
|
|
|
376
|
-
##
|
|
377
|
-
|
|
378
|
-
If malware has already generated files in your project, clean them up instantly:
|
|
247
|
+
## Something not working?
|
|
379
248
|
|
|
380
249
|
```bash
|
|
381
|
-
|
|
250
|
+
gitsafty doctor
|
|
382
251
|
```
|
|
383
252
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
253
|
+
It finds what is wrong and shows the exact fix. `gitsafty doctor --fix` applies the safe fixes. Menu **15**.
|
|
254
|
+
|
|
255
|
+
| Problem | Fix |
|
|
256
|
+
|---|---|
|
|
257
|
+
| `EACCES` / permission denied while installing | `mkdir -p ~/.npm-global && npm config set prefix ~/.npm-global`, add `~/.npm-global/bin` to your `PATH`, install again. Windows: run the terminal as Administrator. |
|
|
258
|
+
| `ENOTFOUND` / `ETIMEDOUT` | Network or proxy problem: check your connection and try again. |
|
|
259
|
+
| Errors about the Node version | Install Node.js 18 or newer. |
|
|
389
260
|
|
|
390
|
-
|
|
391
|
-
β temp_auto_push.bat
|
|
392
|
-
β config.bat
|
|
261
|
+
**Turn GitSafty off without the `gitsafty` command:**
|
|
393
262
|
|
|
394
|
-
|
|
263
|
+
```bash
|
|
264
|
+
git config --global --unset core.hooksPath
|
|
395
265
|
```
|
|
396
266
|
|
|
397
|
-
|
|
267
|
+
```bash
|
|
268
|
+
rm -rf ~/.git-hooks-safty
|
|
269
|
+
```
|
|
398
270
|
|
|
399
|
-
|
|
271
|
+
On Windows PowerShell: `Remove-Item -Recurse -Force "$HOME\.git-hooks-safty"`.
|
|
400
272
|
|
|
401
|
-
|
|
273
|
+
If you used safe login, also run:
|
|
402
274
|
|
|
403
275
|
```bash
|
|
404
|
-
|
|
276
|
+
git config --global --remove-section credential.https://github.com
|
|
405
277
|
```
|
|
406
278
|
|
|
407
|
-
This creates `.github/workflows/git-safty.yml`. Any pull request or push containing blacklisted scripts or suspicious payloads will fail CI on GitHub's servers automatically.
|
|
408
|
-
|
|
409
279
|
---
|
|
410
280
|
|
|
411
|
-
##
|
|
281
|
+
## All commands
|
|
412
282
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
283
|
+
| Command | What it does |
|
|
284
|
+
|---|---|
|
|
285
|
+
| `gitsafty` | Open the menu |
|
|
286
|
+
| `gitsafty init --global` | Protect every project on this computer |
|
|
287
|
+
| `gitsafty init` | Protect only this project |
|
|
288
|
+
| `gitsafty uninstall` | Remove protection from this project (`--global` for the whole computer) |
|
|
289
|
+
| `gitsafty pull-scan on` / `off` | Also check pulls that say "Already up to date" |
|
|
290
|
+
| `gitsafty scan` | Scan this project and remove confirmed malware |
|
|
291
|
+
| `gitsafty scan-projects <folder>` | Scan all projects in a folder (`--clean`, `--deep`, `--json`) |
|
|
292
|
+
| `gitsafty full-scan <folder or file>` | Scan everything, including zip/rar files and non-git folders (`--clean`, `--json`) |
|
|
293
|
+
| `gitsafty sweep <folder>` | Quick malware check of every git repo under a folder |
|
|
294
|
+
| `gitsafty scan-remote <github url>` | Scan a GitHub repo without downloading it |
|
|
295
|
+
| `gitsafty clean` | Move malware files in this project to quarantine |
|
|
296
|
+
| `gitsafty vault setup` / `status` / `test` / `remove` | Safe GitHub login |
|
|
297
|
+
| `gitsafty action` | Add the check to GitHub Actions |
|
|
298
|
+
| `gitsafty doctor` | Find and fix problems (`--fix`) |
|
|
299
|
+
| `gitsafty demo` | Show a blocked push |
|
|
300
|
+
|
|
301
|
+
Using `npx` instead of a global install? Put `npx @arifbiswas/git-pre-push` in place of `gitsafty`.
|
|
417
302
|
|
|
418
303
|
---
|
|
419
304
|
|
|
420
|
-
##
|
|
305
|
+
## Settings (optional)
|
|
421
306
|
|
|
422
|
-
|
|
307
|
+
Nothing to set up. To change a project's behaviour, add `.gitsafetyrc.json` to the project folder:
|
|
423
308
|
|
|
424
309
|
```json
|
|
425
310
|
{
|
|
426
|
-
"ignoreFiles": [
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
"
|
|
430
|
-
"strict": false,
|
|
431
|
-
"autoClean": true
|
|
311
|
+
"ignoreFiles": ["tests/fixtures/sample-payload.js"],
|
|
312
|
+
"autoClean": true,
|
|
313
|
+
"envGuard": true,
|
|
314
|
+
"envGuardAutoPush": true
|
|
432
315
|
}
|
|
433
316
|
```
|
|
434
317
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
|
440
|
-
|
|
441
|
-
| **Runtime Dependencies** | β 50+ packages (heavy) | β
**0 (Pure Node.js built-ins)** |
|
|
442
|
-
| **Supply Chain Vulnerability** | β οΈ High (dependency tree) | π‘οΈ **Zero** (no external modules) |
|
|
443
|
-
| **Execution Overhead** | π’ 1 - 3 seconds | β‘ **< 5 milliseconds** |
|
|
444
|
-
| **Infostealer Malware Detection** | β No | β
**Full signature & payload engine** |
|
|
445
|
-
| **IDE Backdoor Detection (.vscode)** | β No | β
**Built-in static analysis** |
|
|
446
|
-
| **Global Machine Lockdown (`--global`)** | β No | β
**One-command PC protection** |
|
|
447
|
-
| **Auto-Quarantine Cleaner (`clean`)** | β No | β
**Automatic remediation** |
|
|
448
|
-
| **Shell Fallback Guard** | β No | β
**Built-in POSIX shell fallback** |
|
|
449
|
-
|
|
450
|
-
---
|
|
451
|
-
|
|
452
|
-
## π§ͺ Test Coverage
|
|
453
|
-
|
|
454
|
-
Verified with Node.js native test runner across all supported platforms:
|
|
318
|
+
| Setting | Meaning |
|
|
319
|
+
|---|---|
|
|
320
|
+
| `ignoreFiles` | Files to skip for name and secret checks (for example test files). Malware checks always run. |
|
|
321
|
+
| `autoClean` | `false` = report malware but don't remove it. |
|
|
322
|
+
| `envGuard` | `false` = don't take `.env` files out of pushes. |
|
|
323
|
+
| `envGuardAutoPush` | `false` = take the `.env` out, but let you run `git push` again yourself. |
|
|
455
324
|
|
|
456
|
-
|
|
457
|
-
npm test
|
|
458
|
-
```
|
|
459
|
-
```
|
|
460
|
-
β Cloud Scanner Webhook Signature Verification (2 tests)
|
|
461
|
-
β Cloud Scanner Remote Tree Audit (1 test)
|
|
462
|
-
β Filename & Extension Checks (4 tests)
|
|
463
|
-
β Payload Signatures Detection (5 tests)
|
|
464
|
-
β Secret & Credential Checks (3 tests)
|
|
465
|
-
β IDE Configuration Tampering (2 tests)
|
|
466
|
-
β Hook Installer and Uninstaller (1 test)
|
|
467
|
-
|
|
468
|
-
βΉ tests 18 | pass 18 | fail 0 | duration_ms ~300ms
|
|
469
|
-
```
|
|
325
|
+
Backups of removed files are kept in `.git/gitsafty-quarantine/` inside the project, or in `~/.gitsafty/quarantine/` for full scans. Reports are saved in `~/.gitsafty/reports/`.
|
|
470
326
|
|
|
471
327
|
---
|
|
472
328
|
|
|
473
|
-
##
|
|
474
|
-
|
|
475
|
-
MIT License Β© 2026
|
|
476
|
-
|
|
477
|
-
---
|
|
329
|
+
## License
|
|
478
330
|
|
|
479
|
-
|
|
331
|
+
MIT
|
package/package.json
CHANGED
package/src/envGuard.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .env guard for git push.
|
|
3
|
+
*
|
|
4
|
+
* A .env file must never reach the remote. When a push contains one:
|
|
5
|
+
* 1. The push is blocked.
|
|
6
|
+
* 2. .env patterns are added to .gitignore (examples/templates stay allowed).
|
|
7
|
+
* 3. The .env file is removed from every commit that is not on the remote yet
|
|
8
|
+
* (only local, unpushed commits are rewritten, so no force push is needed).
|
|
9
|
+
* The file itself stays on your disk, now ignored.
|
|
10
|
+
* 4. .env that git still tracks ("cached", even if .gitignore lists it) is
|
|
11
|
+
* untracked with `git rm --cached`, and the .gitignore change is committed.
|
|
12
|
+
* 5. The cleaned branch is pushed right away (the original push, which still
|
|
13
|
+
* had the .env, is the one git reports as failed).
|
|
14
|
+
*
|
|
15
|
+
* Rewriting uses git plumbing on a temporary index, so it works with
|
|
16
|
+
* uncommitted changes in the working tree and never touches them.
|
|
17
|
+
* Merge commits in the unpushed range are not rewritten: the user gets the
|
|
18
|
+
* exact commands instead.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const os = require('os');
|
|
23
|
+
const path = require('path');
|
|
24
|
+
const { spawnSync } = require('child_process');
|
|
25
|
+
|
|
26
|
+
const ZERO_OID = '0000000000000000000000000000000000000000';
|
|
27
|
+
const GITIGNORE_LINES = ['.env', '.env.*', '!.env.example', '!.env.sample', '!.env.template', '!.env.dist', '!.env.defaults'];
|
|
28
|
+
|
|
29
|
+
/** True for .env, .env.local, .env.production β¦, but not for examples / templates. */
|
|
30
|
+
function isEnvFile(filePath) {
|
|
31
|
+
const base = String(filePath).replace(/\\/g, '/').split('/').pop().toLowerCase();
|
|
32
|
+
if (!/^\.env(\.[^/]+)?$/.test(base)) return false;
|
|
33
|
+
return !/(example|sample|template|dist|defaults?|schema)/.test(base);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function git(args, cwd, opts = {}) {
|
|
37
|
+
const r = spawnSync('git', args, { cwd, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, ...opts });
|
|
38
|
+
return { ok: r.status === 0, out: (r.stdout || '').toString(), err: (r.stderr || '').toString() };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function must(args, cwd, opts) {
|
|
42
|
+
const r = git(args, cwd, opts);
|
|
43
|
+
if (!r.ok) throw new Error(`git ${args.join(' ')}: ${r.err.trim()}`);
|
|
44
|
+
return r.out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function lines(text) {
|
|
48
|
+
return text.split(/\r?\n/).map(s => s.trim()).filter(Boolean);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Commits being pushed that the remote does not have yet, oldest first. */
|
|
52
|
+
function unpushedCommits(localOid, cwd) {
|
|
53
|
+
const r = git(['rev-list', '--reverse', '--topo-order', localOid, '--not', '--remotes'], cwd);
|
|
54
|
+
return r.ok ? lines(r.out) : [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** .env files the push would put on the remote (in the pushed tip, or added by an unpushed commit). */
|
|
58
|
+
function envFilesInPush(push, cwd) {
|
|
59
|
+
const found = new Set();
|
|
60
|
+
for (const f of lines(git(['ls-tree', '-r', '--name-only', push.localOid], cwd).out)) {
|
|
61
|
+
if (isEnvFile(f)) found.add(f);
|
|
62
|
+
}
|
|
63
|
+
const commits = unpushedCommits(push.localOid, cwd);
|
|
64
|
+
if (commits.length) {
|
|
65
|
+
const r = git(['log', '--format=', '--name-only', '--diff-filter=ACMR', push.localOid, '--not', '--remotes'], cwd);
|
|
66
|
+
for (const f of lines(r.out)) if (isEnvFile(f)) found.add(f);
|
|
67
|
+
}
|
|
68
|
+
return [...found];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function tmpIndex() {
|
|
72
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gitsafty-idx-'));
|
|
73
|
+
return { file: path.join(dir, 'index'), done: () => fs.rmSync(dir, { recursive: true, force: true }) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Raw commit -> { tree, parents, author, committer, message } */
|
|
77
|
+
function readCommit(oid, cwd) {
|
|
78
|
+
const raw = must(['cat-file', 'commit', oid], cwd);
|
|
79
|
+
const split = raw.indexOf('\n\n');
|
|
80
|
+
const header = raw.slice(0, split);
|
|
81
|
+
const message = raw.slice(split + 2);
|
|
82
|
+
const get = (k) => (header.match(new RegExp(`^${k} (.*)$`, 'm')) || [])[1];
|
|
83
|
+
const parents = [...header.matchAll(/^parent (\S+)$/gm)].map(m => m[1]);
|
|
84
|
+
return { tree: get('tree'), parents, author: get('author'), committer: get('committer'), message, signed: /^gpgsig /m.test(header) };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function identityEnv(ident, prefix) {
|
|
88
|
+
const m = String(ident).match(/^(.*) <(.*)> (\d+ [+-]\d{4})$/);
|
|
89
|
+
if (!m) return {};
|
|
90
|
+
return { [`GIT_${prefix}_NAME`]: m[1], [`GIT_${prefix}_EMAIL`]: m[2], [`GIT_${prefix}_DATE`]: m[3] };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Tree of `oid` without the given paths. */
|
|
94
|
+
function treeWithout(treeish, files, cwd) {
|
|
95
|
+
const idx = tmpIndex();
|
|
96
|
+
try {
|
|
97
|
+
const env = { ...process.env, GIT_INDEX_FILE: idx.file };
|
|
98
|
+
must(['read-tree', treeish], cwd, { env });
|
|
99
|
+
must(['rm', '--cached', '--ignore-unmatch', '-q', '--', ...files], cwd, { env });
|
|
100
|
+
return must(['write-tree'], cwd, { env }).trim();
|
|
101
|
+
} finally {
|
|
102
|
+
idx.done();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Rewrites the unpushed commits of `ref` without `files`.
|
|
108
|
+
* @returns {{ ok: boolean, newTip?: string, rewritten?: number, dropped?: number, reason?: string, signed?: boolean }}
|
|
109
|
+
*/
|
|
110
|
+
function rewriteUnpushed(ref, localOid, files, cwd) {
|
|
111
|
+
const commits = unpushedCommits(localOid, cwd);
|
|
112
|
+
if (!commits.length) return { ok: true, newTip: localOid, rewritten: 0, dropped: 0 };
|
|
113
|
+
const map = new Map();
|
|
114
|
+
let dropped = 0;
|
|
115
|
+
let signed = false;
|
|
116
|
+
for (const oid of commits) {
|
|
117
|
+
const c = readCommit(oid, cwd);
|
|
118
|
+
if (c.parents.length > 1) return { ok: false, reason: 'merge commits in the unpushed range' };
|
|
119
|
+
signed = signed || c.signed;
|
|
120
|
+
const parent = c.parents[0] ? (map.get(c.parents[0]) || c.parents[0]) : null;
|
|
121
|
+
const tree = treeWithout(oid, files, cwd);
|
|
122
|
+
const parentTree = parent ? must(['rev-parse', `${parent}^{tree}`], cwd).trim() : null;
|
|
123
|
+
const origParentTree = c.parents[0] ? must(['rev-parse', `${c.parents[0]}^{tree}`], cwd).trim() : null;
|
|
124
|
+
// A commit that only added the .env file becomes empty: drop it.
|
|
125
|
+
if (parent && tree === parentTree && c.tree !== origParentTree) {
|
|
126
|
+
map.set(oid, parent);
|
|
127
|
+
dropped++;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const env = { ...process.env, ...identityEnv(c.author, 'AUTHOR'), ...identityEnv(c.committer, 'COMMITTER') };
|
|
131
|
+
const args = ['commit-tree', tree];
|
|
132
|
+
if (parent) args.push('-p', parent);
|
|
133
|
+
const newOid = must(args, cwd, { env, input: c.message }).trim();
|
|
134
|
+
map.set(oid, newOid);
|
|
135
|
+
}
|
|
136
|
+
const newTip = map.get(localOid);
|
|
137
|
+
must(['update-ref', '-m', 'GitSafty: remove .env from unpushed commits', ref, newTip, localOid], cwd);
|
|
138
|
+
return { ok: true, newTip, rewritten: commits.length - dropped, dropped, signed };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Lines of GITIGNORE_LINES that .gitignore does not have yet. */
|
|
142
|
+
function missingIgnoreLines(text) {
|
|
143
|
+
const have = new Set(lines(text));
|
|
144
|
+
return GITIGNORE_LINES.filter(l => !have.has(l));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function appendLines(text, add) {
|
|
148
|
+
if (!add.length) return text;
|
|
149
|
+
const base = text && !text.endsWith('\n') ? text + '\n' : text;
|
|
150
|
+
return `${base}${base ? '\n' : ''}# Environment files: never commit (added by GitSafty)\n${add.join('\n')}\n`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Commits the .gitignore update on top of `ref` (only for the checked-out branch),
|
|
155
|
+
* and updates the working tree / index copy without touching other changes.
|
|
156
|
+
*/
|
|
157
|
+
function commitGitignore(ref, cwd, files = []) {
|
|
158
|
+
const head = must(['rev-parse', ref], cwd).trim();
|
|
159
|
+
const inHead = git(['show', `${head}:.gitignore`], cwd);
|
|
160
|
+
const headText = inHead.ok ? inHead.out : '';
|
|
161
|
+
const add = missingIgnoreLines(headText);
|
|
162
|
+
|
|
163
|
+
// Working tree copy (may contain the user's own unstaged edits: keep them).
|
|
164
|
+
const wtFile = path.join(cwd, '.gitignore');
|
|
165
|
+
const wtText = fs.existsSync(wtFile) ? fs.readFileSync(wtFile, 'utf8') : '';
|
|
166
|
+
const wtAdd = missingIgnoreLines(wtText);
|
|
167
|
+
if (wtAdd.length) fs.writeFileSync(wtFile, appendLines(wtText, wtAdd));
|
|
168
|
+
// .env files still in the tip (e.g. pushed earlier): this commit removes them too.
|
|
169
|
+
const stillThere = lines(git(['ls-tree', '-r', '--name-only', head, '--', ...files], cwd).out);
|
|
170
|
+
if (!add.length && !stillThere.length) return null;
|
|
171
|
+
|
|
172
|
+
const blob = must(['hash-object', '-w', '--stdin'], cwd, { input: appendLines(headText, add) }).trim();
|
|
173
|
+
const idx = tmpIndex();
|
|
174
|
+
let commit;
|
|
175
|
+
try {
|
|
176
|
+
const env = { ...process.env, GIT_INDEX_FILE: idx.file };
|
|
177
|
+
must(['read-tree', head], cwd, { env });
|
|
178
|
+
if (stillThere.length) must(['rm', '--cached', '-q', '--', ...stillThere], cwd, { env });
|
|
179
|
+
if (add.length) must(['update-index', '--add', '--cacheinfo', `100644,${blob},.gitignore`], cwd, { env });
|
|
180
|
+
const tree = must(['write-tree'], cwd, { env }).trim();
|
|
181
|
+
const msg = stillThere.length ? 'chore: stop tracking .env files' : 'chore: never commit .env files';
|
|
182
|
+
commit = must(['commit-tree', tree, '-p', head], cwd, { input: `${msg}\n\nAdded by GitSafty: .env files are ignored and kept out of git.\n` }).trim();
|
|
183
|
+
} finally {
|
|
184
|
+
idx.done();
|
|
185
|
+
}
|
|
186
|
+
must(['update-ref', '-m', 'GitSafty: ignore .env files', ref, commit, head], cwd);
|
|
187
|
+
|
|
188
|
+
// Real index: if it had HEAD's .gitignore (nothing staged there), move it to the new one.
|
|
189
|
+
const staged = git(['ls-files', '-s', '--', '.gitignore'], cwd).out.split(/\s+/)[1];
|
|
190
|
+
const oldBlob = inHead.ok ? must(['rev-parse', `${head}:.gitignore`], cwd).trim() : undefined;
|
|
191
|
+
if (add.length && (staged === oldBlob || (!staged && !oldBlob))) {
|
|
192
|
+
must(['update-index', '--add', '--cacheinfo', `100644,${blob},.gitignore`], cwd);
|
|
193
|
+
}
|
|
194
|
+
return commit;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Runs the guard for a pre-push.
|
|
199
|
+
* @param {Array<{localRef, localOid, remoteRef, remoteOid}>} pushes
|
|
200
|
+
* @returns {{ blocked: boolean, files: string[], fixes: string[], manual: string[], alreadyOnRemote: boolean, repush: Array<{ref, remoteRef}> }}
|
|
201
|
+
*/
|
|
202
|
+
function guardEnvOnPush(pushes, cwd = process.cwd()) {
|
|
203
|
+
const result = { blocked: false, files: [], fixes: [], manual: [], alreadyOnRemote: false, repush: [] };
|
|
204
|
+
const currentRef = git(['symbolic-ref', '-q', 'HEAD'], cwd).out.trim();
|
|
205
|
+
|
|
206
|
+
for (const push of pushes) {
|
|
207
|
+
if (!push || push.localOid === ZERO_OID) continue;
|
|
208
|
+
const files = envFilesInPush(push, cwd);
|
|
209
|
+
if (!files.length) continue;
|
|
210
|
+
result.blocked = true;
|
|
211
|
+
result.files.push(...files.filter(f => !result.files.includes(f)));
|
|
212
|
+
|
|
213
|
+
if (push.remoteOid && push.remoteOid !== ZERO_OID && git(['cat-file', '-e', push.remoteOid], cwd).ok) {
|
|
214
|
+
const onRemote = lines(git(['ls-tree', '-r', '--name-only', push.remoteOid], cwd).out).filter(isEnvFile);
|
|
215
|
+
if (onRemote.length) result.alreadyOnRemote = true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const ref = push.localRef;
|
|
219
|
+
const refNow = ref.startsWith('refs/heads/') ? git(['rev-parse', '-q', '--verify', ref], cwd).out.trim() : '';
|
|
220
|
+
if (!ref.startsWith('refs/heads/') || refNow !== push.localOid) {
|
|
221
|
+
result.manual.push(`Pushed ${push.localRef || push.localOid} is not a local branch tip, so it was not rewritten. Remove the file: git rm --cached ${files.map(f => `"${f}"`).join(' ')} && git commit --amend`);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const rw = rewriteUnpushed(ref, push.localOid, files, cwd);
|
|
226
|
+
if (!rw.ok) {
|
|
227
|
+
result.manual.push(`Could not rewrite ${ref.replace('refs/heads/', '')} automatically (${rw.reason}). Run: git rm --cached ${files.map(f => `"${f}"`).join(' ')} && git commit -m "Remove .env" ; then remove it from history with git rebase -i or git filter-repo`);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (rw.rewritten || rw.dropped) {
|
|
231
|
+
result.fixes.push(`Removed ${files.join(', ')} from ${rw.rewritten + rw.dropped} unpushed commit(s) on ${ref.replace('refs/heads/', '')}${rw.dropped ? ` (${rw.dropped} commit(s) that only added it were dropped)` : ''}. New commit ids.`);
|
|
232
|
+
if (rw.signed) result.fixes.push('Some of those commits were GPG/SSH signed; the rewritten ones are not signed anymore.');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (ref === currentRef) {
|
|
236
|
+
// Keep the files on disk, but out of the index.
|
|
237
|
+
const tracked = lines(git(['ls-files', '--', ...files], cwd).out);
|
|
238
|
+
if (tracked.length) must(['rm', '--cached', '-q', '--', ...tracked], cwd);
|
|
239
|
+
if (commitGitignore(ref, cwd, files)) result.fixes.push('Added .env patterns to .gitignore and committed it.');
|
|
240
|
+
else result.fixes.push('.gitignore already ignores .env files.');
|
|
241
|
+
} else {
|
|
242
|
+
const left = lines(git(['ls-tree', '-r', '--name-only', ref, '--', ...files], cwd).out);
|
|
243
|
+
if (left.length) {
|
|
244
|
+
result.manual.push(`${ref.replace('refs/heads/', '')} is not checked out. Switch to it and push again, GitSafty will finish the fix: git switch ${ref.replace('refs/heads/', '')}`);
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Fully fixed: safe to push the cleaned branch.
|
|
249
|
+
result.repush.push({ ref, remoteRef: push.remoteRef });
|
|
250
|
+
}
|
|
251
|
+
if (result.blocked && result.files.length) {
|
|
252
|
+
result.fixes.push(`Your ${result.files.join(', ')} is still on your disk, now ignored by git.`);
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
module.exports = {
|
|
258
|
+
isEnvFile,
|
|
259
|
+
guardEnvOnPush,
|
|
260
|
+
envFilesInPush,
|
|
261
|
+
GITIGNORE_LINES
|
|
262
|
+
};
|
package/src/index.js
CHANGED
|
@@ -259,6 +259,46 @@ async function runPrePush() {
|
|
|
259
259
|
|
|
260
260
|
const pushes = parsePrePushInput(stdinData);
|
|
261
261
|
|
|
262
|
+
// .env must never reach the remote: block, then fix (ignore + remove from unpushed commits).
|
|
263
|
+
if (pushes.length && loadConfig(process.cwd()).envGuard !== false) {
|
|
264
|
+
const { guardEnvOnPush } = require('./envGuard');
|
|
265
|
+
let env;
|
|
266
|
+
try {
|
|
267
|
+
env = guardEnvOnPush(pushes, process.cwd());
|
|
268
|
+
} catch (err) {
|
|
269
|
+
env = { blocked: true, files: ['.env'], fixes: [], manual: [`Automatic fix failed (${err.message}). Run: git rm --cached .env && echo .env >> .gitignore && git commit -am "Remove .env"`] };
|
|
270
|
+
}
|
|
271
|
+
if (env.blocked) {
|
|
272
|
+
console.log(`\n${colors.red}${colors.bold}β PUSH BLOCKED: .env file in this push${colors.reset} ${colors.dim}(${env.files.join(', ')})${colors.reset}`);
|
|
273
|
+
console.log(`${colors.dim}.env files hold passwords and API keys. GitSafty never lets them reach the remote.${colors.reset}\n`);
|
|
274
|
+
for (const f of env.fixes) console.log(` ${colors.green}β${colors.reset} ${f}`);
|
|
275
|
+
for (const m of env.manual) console.log(` ${colors.yellow}β ${colors.reset} ${m}`);
|
|
276
|
+
if (env.alreadyOnRemote) {
|
|
277
|
+
console.log(` ${colors.yellow}β The remote already had a .env from an earlier push. This push removes it, but it is still in the remote's history: change (rotate) every key in it.${colors.reset}`);
|
|
278
|
+
}
|
|
279
|
+
// Push the cleaned commits now (once; the inner push runs the hooks again).
|
|
280
|
+
const remote = process.argv[3];
|
|
281
|
+
const config = loadConfig(process.cwd());
|
|
282
|
+
let pushed = false;
|
|
283
|
+
if (remote && !env.manual.length && env.repush.length && !process.env.GITSAFTY_ENV_REPUSH && config.envGuardAutoPush !== false) {
|
|
284
|
+
console.log(`\n${colors.cyan}Pushing the fixed commits (without .env) to ${remote}...${colors.reset}`);
|
|
285
|
+
const r = require('child_process').spawnSync('git', ['push', remote, ...env.repush.map(p => `${p.ref}:${p.remoteRef}`)], {
|
|
286
|
+
stdio: 'inherit',
|
|
287
|
+
env: { ...process.env, GITSAFTY_ENV_REPUSH: '1' }
|
|
288
|
+
});
|
|
289
|
+
pushed = r.status === 0;
|
|
290
|
+
}
|
|
291
|
+
if (pushed) {
|
|
292
|
+
console.log(`\n${colors.green}${colors.bold}β Fixed and pushed without .env.${colors.reset}`);
|
|
293
|
+
console.log(`${colors.dim}Git prints "failed to push" below for the ORIGINAL push (the one with .env). That one was stopped on purpose; your code is on the remote.${colors.reset}\n`);
|
|
294
|
+
} else {
|
|
295
|
+
console.log(`\n${colors.bold}Now run ${colors.cyan}git push${colors.reset}${colors.bold} again.${colors.reset}${env.manual.length ? '' : ' Nothing else to do.'}\n`);
|
|
296
|
+
}
|
|
297
|
+
notifyDesktop('GitSafty: .env blocked', pushed ? '.env was removed and your code was pushed without it.' : `.env was kept out of the push${env.manual.length ? '' : ' and fixed automatically'}.`);
|
|
298
|
+
process.exit(1);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
262
302
|
let allFiles = [];
|
|
263
303
|
let combinedDiff = '';
|
|
264
304
|
|
package/src/menu.js
CHANGED
|
@@ -25,38 +25,38 @@ function ask(question) {
|
|
|
25
25
|
async function runInteractiveMenu() {
|
|
26
26
|
banner();
|
|
27
27
|
|
|
28
|
-
const item = (n,
|
|
29
|
-
console.log(` ${colors.green}
|
|
30
|
-
const section = (title) => console.log(`\n ${colors.
|
|
31
|
-
|
|
32
|
-
console.log(`\n${colors.bold}
|
|
33
|
-
|
|
34
|
-
section('
|
|
35
|
-
item(1, '
|
|
36
|
-
item(2, '
|
|
37
|
-
item(
|
|
38
|
-
item(
|
|
39
|
-
|
|
40
|
-
section('
|
|
41
|
-
item(
|
|
42
|
-
item(
|
|
43
|
-
item(
|
|
44
|
-
item(
|
|
45
|
-
item(
|
|
46
|
-
item(
|
|
47
|
-
|
|
48
|
-
section('GitHub login
|
|
49
|
-
item(11, '
|
|
50
|
-
item(12, '
|
|
51
|
-
item(13, '
|
|
52
|
-
item(14, '
|
|
53
|
-
|
|
54
|
-
section('
|
|
55
|
-
item(
|
|
56
|
-
item(
|
|
57
|
-
item(
|
|
58
|
-
item(
|
|
59
|
-
console.log(
|
|
28
|
+
const item = (n, title, desc) =>
|
|
29
|
+
console.log(` ${colors.green}${String(n).padStart(2)}.${colors.reset} ${colors.bold}${title.padEnd(34)}${colors.reset} ${colors.dim}${desc}${colors.reset}`);
|
|
30
|
+
const section = (title) => console.log(`\n ${colors.cyan}${title}${colors.reset}`);
|
|
31
|
+
|
|
32
|
+
console.log(`\n${colors.bold}What do you want to do?${colors.reset}`);
|
|
33
|
+
|
|
34
|
+
section('Protect your code');
|
|
35
|
+
item(1, 'Protect this project', 'Check every push, clone and pull in this project');
|
|
36
|
+
item(2, 'Protect all projects on this PC', 'Same, for every git project on this computer');
|
|
37
|
+
item(3, 'Scan every git pull', 'Also when git says "Already up to date" (on/off)');
|
|
38
|
+
item(4, 'Remove protection', 'Uninstall GitSafty from this project or this PC');
|
|
39
|
+
|
|
40
|
+
section('Scan and clean');
|
|
41
|
+
item(5, 'Scan this project', 'Find malware here and remove it automatically');
|
|
42
|
+
item(6, 'Scan all projects in a folder', 'Malware, hidden backdoors and leaked passwords/keys');
|
|
43
|
+
item(7, 'Scan everything in a folder', 'Also zip/rar files and folders that are not git projects');
|
|
44
|
+
item(8, 'Scan all git repos under a folder', 'Quick malware check, e.g. your whole disk');
|
|
45
|
+
item(9, 'Clean this project', 'Move malware files in this project to quarantine');
|
|
46
|
+
item(10, 'Scan a GitHub repo before cloning', 'Check a GitHub link without downloading it');
|
|
47
|
+
|
|
48
|
+
section('Safe GitHub login (stay logged out)');
|
|
49
|
+
item(11, 'Turn on safe GitHub login', 'Touch ID / Windows Hello / password before every push');
|
|
50
|
+
item(12, 'Check safe login status', 'See if your GitHub login is protected');
|
|
51
|
+
item(13, 'Test safe login', 'Try the unlock prompt once');
|
|
52
|
+
item(14, 'Turn off safe login', 'Go back to normal git login');
|
|
53
|
+
|
|
54
|
+
section('Help and tools');
|
|
55
|
+
item(15, 'Fix problems', 'Find what is broken and how to fix it');
|
|
56
|
+
item(16, 'Check for updates', 'Install the newest GitSafty');
|
|
57
|
+
item(17, 'Add GitSafty to GitHub Actions', 'Check every push on GitHub too');
|
|
58
|
+
item(18, 'See a demo', 'Show what a blocked push looks like');
|
|
59
|
+
console.log(`\n ${colors.dim} 0. Exit${colors.reset}\n`);
|
|
60
60
|
|
|
61
61
|
const rl = readline.createInterface({
|
|
62
62
|
input: process.stdin,
|
|
@@ -64,7 +64,7 @@ async function runInteractiveMenu() {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
const choice = await new Promise((resolve) => {
|
|
67
|
-
rl.question(`${colors.bold}${colors.yellow}Enter
|
|
67
|
+
rl.question(`${colors.bold}${colors.yellow}Enter a number (0-18): ${colors.reset}`, (ans) => {
|
|
68
68
|
rl.close();
|
|
69
69
|
resolve(ans.trim());
|
|
70
70
|
});
|
|
@@ -93,12 +93,12 @@ async function runInteractiveMenu() {
|
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
case '
|
|
96
|
+
case '5': {
|
|
97
97
|
runManualScan();
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
case '
|
|
101
|
+
case '10': {
|
|
102
102
|
const askRl = readline.createInterface({
|
|
103
103
|
input: process.stdin,
|
|
104
104
|
output: process.stdout
|
|
@@ -128,7 +128,7 @@ async function runInteractiveMenu() {
|
|
|
128
128
|
break;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
case '
|
|
131
|
+
case '9': {
|
|
132
132
|
console.log(`\n${colors.cyan}Scanning workspace for injected malware scripts to quarantine...${colors.reset}`);
|
|
133
133
|
const { getAllRepoFiles } = require('./utils/git');
|
|
134
134
|
scanAndCleanRepo(getAllRepoFiles(), process.cwd(), { reason: 'clean' });
|
|
@@ -145,7 +145,7 @@ async function runInteractiveMenu() {
|
|
|
145
145
|
break;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
case '
|
|
148
|
+
case '18': {
|
|
149
149
|
console.log(`\n${colors.cyan}Simulating a malicious push intercept test...${colors.reset}\n`);
|
|
150
150
|
const mockFiles = ['src/app.js', 'temp_auto_push.bat', '.vscode/tasks.json'];
|
|
151
151
|
const mockDiff = `+ powershell.exe -enc SQBFAFgAIAAoAE4AZQB3...
|
|
@@ -159,7 +159,7 @@ async function runInteractiveMenu() {
|
|
|
159
159
|
break;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
case '
|
|
162
|
+
case '17': {
|
|
163
163
|
const res = setupGitHubAction();
|
|
164
164
|
if (res.success) {
|
|
165
165
|
console.log(`\n${colors.green}${colors.bold}β ${res.message}${colors.reset}\n`);
|
|
@@ -169,7 +169,7 @@ async function runInteractiveMenu() {
|
|
|
169
169
|
break;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
case '
|
|
172
|
+
case '4': {
|
|
173
173
|
const { isGitRepo } = require('./utils/git');
|
|
174
174
|
let global = !isGitRepo(process.cwd());
|
|
175
175
|
if (!global) {
|
|
@@ -185,14 +185,14 @@ async function runInteractiveMenu() {
|
|
|
185
185
|
break;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
case '
|
|
188
|
+
case '16': {
|
|
189
189
|
const pkg = require('../package.json');
|
|
190
190
|
const { checkUpdateManual } = require('./updateNotifier');
|
|
191
191
|
await checkUpdateManual(pkg.version);
|
|
192
192
|
break;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
case '
|
|
195
|
+
case '8': {
|
|
196
196
|
const folder = await ask(`\n${colors.bold}${colors.cyan}? Folder to sweep (Enter = ${process.cwd()}): ${colors.reset}`);
|
|
197
197
|
const removeAnswer = await ask(`${colors.bold}${colors.cyan}? Automatically remove CONFIRMED malware? Suspicious items are never touched. (Y/n): ${colors.reset}`);
|
|
198
198
|
const clean = !/^n(o)?$/i.test(removeAnswer);
|
|
@@ -235,7 +235,7 @@ async function runInteractiveMenu() {
|
|
|
235
235
|
break;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
case '
|
|
238
|
+
case '6': {
|
|
239
239
|
const { runAdvancedScan } = require('./advancedScanner');
|
|
240
240
|
const folder = await ask(`\n${colors.bold}${colors.cyan}? Folder that contains your projects (Enter = ${process.cwd()}): ${colors.reset}`);
|
|
241
241
|
const deep = await ask(`${colors.bold}${colors.cyan}? Deep scan incl. node_modules & ignored files? Slower. (y/N): ${colors.reset}`);
|
|
@@ -247,7 +247,7 @@ async function runInteractiveMenu() {
|
|
|
247
247
|
break;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
case '
|
|
250
|
+
case '3': {
|
|
251
251
|
const shell = require('./shellIntegration');
|
|
252
252
|
const on = shell.shellIntegrationStatus().installed.length > 0;
|
|
253
253
|
const answer = await ask(`\n${colors.bold}${colors.cyan}? Pull scan is ${on ? 'ON' : 'OFF'}. Turn it ${on ? 'off' : 'on'}? (y/N): ${colors.reset}`);
|
|
@@ -263,7 +263,7 @@ async function runInteractiveMenu() {
|
|
|
263
263
|
break;
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
case '
|
|
266
|
+
case '7': {
|
|
267
267
|
const { runFullScan } = require('./fullScanner');
|
|
268
268
|
const folder = await ask(`\n${colors.bold}${colors.cyan}? Folder to scan completely (Enter = ${process.cwd()}): ${colors.reset}`);
|
|
269
269
|
const clean = await ask(`${colors.bold}${colors.cyan}? Automatically remove CONFIRMED malware? An infected archive is moved to quarantine whole (backup kept). (Y/n): ${colors.reset}`);
|
|
@@ -273,7 +273,7 @@ async function runInteractiveMenu() {
|
|
|
273
273
|
|
|
274
274
|
case '0':
|
|
275
275
|
default:
|
|
276
|
-
console.log(`\n${colors.dim}Goodbye
|
|
276
|
+
console.log(`\n${colors.dim}Goodbye!${colors.reset}\n`);
|
|
277
277
|
break;
|
|
278
278
|
}
|
|
279
279
|
}
|
package/src/reporter.js
CHANGED
|
@@ -28,7 +28,7 @@ const symbols = {
|
|
|
28
28
|
|
|
29
29
|
function banner() {
|
|
30
30
|
console.log(`\n${colors.cyan}${colors.bold}================================================================${colors.reset}`);
|
|
31
|
-
console.log(`${colors.cyan}${colors.bold}
|
|
31
|
+
console.log(`${colors.cyan}${colors.bold} GitSafty: Malware & Secret Guard for Git${colors.reset}`);
|
|
32
32
|
console.log(`${colors.cyan}${colors.bold}================================================================${colors.reset}`);
|
|
33
33
|
}
|
|
34
34
|
|
package/src/utils/git.js
CHANGED
|
@@ -101,10 +101,10 @@ function parsePrePushInput(stdinText) {
|
|
|
101
101
|
*/
|
|
102
102
|
function getChangedFiles(diffRange, cwd = process.cwd()) {
|
|
103
103
|
// Use git diff-tree or git log to extract changed filenames
|
|
104
|
-
const output = runGit(`diff-tree --no-commit-id --name-only -r ${diffRange}`, cwd);
|
|
104
|
+
const output = runGit(`diff-tree --no-commit-id --name-only --diff-filter=d -r ${diffRange}`, cwd);
|
|
105
105
|
if (!output) {
|
|
106
106
|
// Fallback to git log
|
|
107
|
-
const logOutput = runGit(`log ${diffRange} --name-only --oneline`, cwd);
|
|
107
|
+
const logOutput = runGit(`log ${diffRange} --name-only --oneline --diff-filter=d`, cwd);
|
|
108
108
|
if (!logOutput) return [];
|
|
109
109
|
const files = new Set();
|
|
110
110
|
for (const line of logOutput.split('\n')) {
|