@arifbiswas/git-pre-push 1.0.19 β 1.0.21
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 +195 -341
- package/bin/cli.js +25 -20
- package/package.json +1 -1
- package/src/doctor.js +4 -2
- package/src/envGuard.js +262 -0
- package/src/index.js +40 -0
- package/src/menu.js +52 -46
- package/src/reporter.js +1 -1
- package/src/shellIntegration.js +51 -4
- package/src/utils/git.js +2 -2
package/README.md
CHANGED
|
@@ -1,479 +1,333 @@
|
|
|
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
|
+
- `init --global` also turns on the check for pulls that say *"Already up to date"*. Open a new terminal once so it takes effect.
|
|
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 On by default, also "Already up to date". Turn off/on
|
|
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
|
-
|
|
88
|
+
---
|
|
113
89
|
|
|
114
|
-
|
|
90
|
+
## Everyday use
|
|
115
91
|
|
|
116
|
-
|
|
92
|
+
After `gitsafty init --global` you don't need to do anything. Use git as usual:
|
|
117
93
|
|
|
118
|
-
|
|
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. |
|
|
119
99
|
|
|
120
|
-
|
|
121
|
-
npx @arifbiswas/git-pre-push init --global
|
|
122
|
-
```
|
|
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.
|
|
123
101
|
|
|
124
|
-
|
|
102
|
+
### Scan every pull (on by default)
|
|
125
103
|
|
|
126
|
-
|
|
104
|
+
Git runs nothing when a pull says *"Already up to date"*, so GitSafty adds a small `git` helper to your shell profile (`.zshrc`, `.bashrc`, fish or PowerShell) that checks those pulls too. It is **on by default** with the global install, and existing installs get it after updating. Open a new terminal once so it takes effect.
|
|
127
105
|
|
|
128
|
-
|
|
106
|
+
Don't want it? Turn it off. GitSafty remembers this and never turns it back on by itself:
|
|
129
107
|
|
|
130
108
|
```bash
|
|
131
|
-
gitsafty pull-scan
|
|
132
|
-
gitsafty pull-scan off # remove the function again
|
|
109
|
+
gitsafty pull-scan off
|
|
133
110
|
```
|
|
134
111
|
|
|
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)
|
|
112
|
+
```bash
|
|
113
|
+
gitsafty pull-scan on
|
|
162
114
|
```
|
|
163
115
|
|
|
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`.
|
|
116
|
+
Menu option **3** does the same. Pulls that bring new code are always checked, even with this off.
|
|
210
117
|
|
|
211
118
|
---
|
|
212
119
|
|
|
213
|
-
##
|
|
120
|
+
## Scanning
|
|
214
121
|
|
|
215
|
-
|
|
122
|
+
### This project
|
|
216
123
|
|
|
217
124
|
```bash
|
|
218
|
-
|
|
125
|
+
gitsafty scan
|
|
219
126
|
```
|
|
220
127
|
|
|
221
|
-
|
|
128
|
+
Checks the whole project and removes confirmed malware. Add `--no-clean` to only report. Menu **5**.
|
|
222
129
|
|
|
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 |
|
|
130
|
+
### All projects in a folder
|
|
228
131
|
|
|
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.
|
|
132
|
+
```bash
|
|
133
|
+
gitsafty scan-projects ~/projects
|
|
134
|
+
```
|
|
233
135
|
|
|
234
136
|
```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
|
|
137
|
+
gitsafty scan-projects ~/projects --clean
|
|
238
138
|
```
|
|
239
139
|
|
|
240
|
-
|
|
140
|
+
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
141
|
|
|
242
|
-
|
|
142
|
+
- `--deep` also checks `node_modules` and ignored files.
|
|
143
|
+
- `--json` gives machine-readable output.
|
|
243
144
|
|
|
244
|
-
|
|
145
|
+
### Everything in a folder, zip files too
|
|
245
146
|
|
|
246
|
-
|
|
147
|
+
```bash
|
|
148
|
+
gitsafty full-scan ~/Downloads
|
|
149
|
+
```
|
|
247
150
|
|
|
248
151
|
```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
|
|
152
|
+
gitsafty full-scan ~/Downloads --clean
|
|
253
153
|
```
|
|
254
154
|
|
|
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.
|
|
155
|
+
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
156
|
|
|
262
|
-
|
|
157
|
+
### All git repos on your disk
|
|
263
158
|
|
|
264
|
-
|
|
159
|
+
```bash
|
|
160
|
+
gitsafty sweep ~
|
|
161
|
+
```
|
|
265
162
|
|
|
266
|
-
|
|
163
|
+
A fast malware check of every git repository under a folder. Menu **8**.
|
|
267
164
|
|
|
268
|
-
|
|
165
|
+
### A GitHub repo before you clone it
|
|
269
166
|
|
|
270
167
|
```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
|
|
168
|
+
gitsafty scan-remote https://github.com/owner/repo
|
|
275
169
|
```
|
|
276
170
|
|
|
277
|
-
|
|
171
|
+
Nothing is downloaded to your disk. Menu **10**.
|
|
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
|
+
---
|
|
284
174
|
|
|
285
|
-
|
|
175
|
+
## Your `.env` file never gets pushed
|
|
286
176
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
177
|
+
If you commit a `.env` (or `.env.local`, `.env.production` β¦) and push, GitSafty:
|
|
178
|
+
|
|
179
|
+
1. Stops that push.
|
|
180
|
+
2. Adds `.env` to `.gitignore`. `.env.example` stays allowed.
|
|
181
|
+
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.
|
|
182
|
+
4. Removes it from your commits that were not pushed yet.
|
|
183
|
+
5. Pushes your code without it.
|
|
184
|
+
|
|
185
|
+
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.
|
|
295
186
|
|
|
296
|
-
|
|
187
|
+
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
188
|
|
|
298
189
|
---
|
|
299
190
|
|
|
300
|
-
##
|
|
191
|
+
## Safe GitHub login
|
|
301
192
|
|
|
302
|
-
|
|
193
|
+
Malware on a computer usually steals saved logins. With safe login on, there is no saved GitHub login to steal.
|
|
303
194
|
|
|
304
195
|
```bash
|
|
305
|
-
gitsafty
|
|
306
|
-
gitsafty doctor --fix # apply the safe fixes (rewrite hooks, re-register the vault helper)
|
|
196
|
+
gitsafty vault setup
|
|
307
197
|
```
|
|
308
198
|
|
|
309
|
-
|
|
199
|
+
1. Paste a GitHub token once. GitSafty stores it encrypted and locks it to this computer's security chip.
|
|
200
|
+
2. Your other saved GitHub logins are removed.
|
|
201
|
+
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.
|
|
202
|
+
4. A prompt you did not expect means someone else is trying to push: press Cancel.
|
|
310
203
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
| npm error | Fix |
|
|
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`) |
|
|
204
|
+
The token file is useless on any other computer.
|
|
318
205
|
|
|
319
|
-
|
|
206
|
+
```bash
|
|
207
|
+
gitsafty vault status
|
|
208
|
+
```
|
|
320
209
|
|
|
321
210
|
```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
|
|
211
|
+
gitsafty vault test
|
|
325
212
|
```
|
|
326
213
|
|
|
327
|
-
|
|
214
|
+
```bash
|
|
215
|
+
gitsafty vault remove
|
|
216
|
+
```
|
|
328
217
|
|
|
329
|
-
|
|
218
|
+
Tips:
|
|
330
219
|
|
|
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` |
|
|
220
|
+
- Use a fine-grained token that expires and only has access to the repos you need.
|
|
221
|
+
- Safe login covers HTTPS remotes. If you push over SSH, give your SSH key a passphrase: `ssh-keygen -p -f ~/.ssh/id_ed25519`.
|
|
347
222
|
|
|
348
223
|
---
|
|
349
224
|
|
|
350
|
-
##
|
|
225
|
+
## Protect the repository on GitHub too
|
|
351
226
|
|
|
352
|
-
|
|
227
|
+
Someone can skip local checks with `git push --no-verify`. Add the same check to GitHub Actions:
|
|
353
228
|
|
|
354
229
|
```bash
|
|
355
|
-
|
|
230
|
+
gitsafty action
|
|
356
231
|
```
|
|
357
232
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
233
|
+
This adds `.github/workflows/git-safty.yml`. Commit and push it. Menu **17**.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Updates
|
|
238
|
+
|
|
239
|
+
When you open `gitsafty` it tells you if a new version is out and asks `Install now? (Y/n)`. Or update yourself:
|
|
362
240
|
|
|
363
|
-
Or pass the URL directly:
|
|
364
241
|
```bash
|
|
365
|
-
|
|
242
|
+
npm install -g @arifbiswas/git-pre-push
|
|
366
243
|
```
|
|
367
244
|
|
|
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.
|
|
245
|
+
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
246
|
|
|
374
247
|
---
|
|
375
248
|
|
|
376
|
-
##
|
|
377
|
-
|
|
378
|
-
If malware has already generated files in your project, clean them up instantly:
|
|
249
|
+
## Something not working?
|
|
379
250
|
|
|
380
251
|
```bash
|
|
381
|
-
|
|
252
|
+
gitsafty doctor
|
|
382
253
|
```
|
|
383
254
|
|
|
384
|
-
|
|
385
|
-
================================================================
|
|
386
|
-
π‘οΈ GitSafty: Pre-Push Malware & Secret Guard
|
|
387
|
-
================================================================
|
|
388
|
-
Scanning workspace for injected malware scripts to quarantine...
|
|
255
|
+
It finds what is wrong and shows the exact fix. `gitsafty doctor --fix` applies the safe fixes. Menu **15**.
|
|
389
256
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
257
|
+
| Problem | Fix |
|
|
258
|
+
|---|---|
|
|
259
|
+
| `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. |
|
|
260
|
+
| `ENOTFOUND` / `ETIMEDOUT` | Network or proxy problem: check your connection and try again. |
|
|
261
|
+
| Errors about the Node version | Install Node.js 18 or newer. |
|
|
262
|
+
|
|
263
|
+
**Turn GitSafty off without the `gitsafty` command:**
|
|
393
264
|
|
|
394
|
-
|
|
265
|
+
```bash
|
|
266
|
+
git config --global --unset core.hooksPath
|
|
395
267
|
```
|
|
396
268
|
|
|
397
|
-
|
|
269
|
+
```bash
|
|
270
|
+
rm -rf ~/.git-hooks-safty
|
|
271
|
+
```
|
|
398
272
|
|
|
399
|
-
|
|
273
|
+
On Windows PowerShell: `Remove-Item -Recurse -Force "$HOME\.git-hooks-safty"`.
|
|
400
274
|
|
|
401
|
-
|
|
275
|
+
If you used safe login, also run:
|
|
402
276
|
|
|
403
277
|
```bash
|
|
404
|
-
|
|
278
|
+
git config --global --remove-section credential.https://github.com
|
|
405
279
|
```
|
|
406
280
|
|
|
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
281
|
---
|
|
410
282
|
|
|
411
|
-
##
|
|
283
|
+
## All commands
|
|
412
284
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
285
|
+
| Command | What it does |
|
|
286
|
+
|---|---|
|
|
287
|
+
| `gitsafty` | Open the menu |
|
|
288
|
+
| `gitsafty init --global` | Protect every project on this computer |
|
|
289
|
+
| `gitsafty init` | Protect only this project |
|
|
290
|
+
| `gitsafty uninstall` | Remove protection from this project (`--global` for the whole computer) |
|
|
291
|
+
| `gitsafty pull-scan off` / `on` | Check pulls that say "Already up to date" (on by default) |
|
|
292
|
+
| `gitsafty scan` | Scan this project and remove confirmed malware |
|
|
293
|
+
| `gitsafty scan-projects <folder>` | Scan all projects in a folder (`--clean`, `--deep`, `--json`) |
|
|
294
|
+
| `gitsafty full-scan <folder or file>` | Scan everything, including zip/rar files and non-git folders (`--clean`, `--json`) |
|
|
295
|
+
| `gitsafty sweep <folder>` | Quick malware check of every git repo under a folder |
|
|
296
|
+
| `gitsafty scan-remote <github url>` | Scan a GitHub repo without downloading it |
|
|
297
|
+
| `gitsafty clean` | Move malware files in this project to quarantine |
|
|
298
|
+
| `gitsafty vault setup` / `status` / `test` / `remove` | Safe GitHub login |
|
|
299
|
+
| `gitsafty action` | Add the check to GitHub Actions |
|
|
300
|
+
| `gitsafty doctor` | Find and fix problems (`--fix`) |
|
|
301
|
+
| `gitsafty demo` | Show a blocked push |
|
|
302
|
+
|
|
303
|
+
Using `npx` instead of a global install? Put `npx @arifbiswas/git-pre-push` in place of `gitsafty`.
|
|
417
304
|
|
|
418
305
|
---
|
|
419
306
|
|
|
420
|
-
##
|
|
307
|
+
## Settings (optional)
|
|
421
308
|
|
|
422
|
-
|
|
309
|
+
Nothing to set up. To change a project's behaviour, add `.gitsafetyrc.json` to the project folder:
|
|
423
310
|
|
|
424
311
|
```json
|
|
425
312
|
{
|
|
426
|
-
"ignoreFiles": [
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
"
|
|
430
|
-
"strict": false,
|
|
431
|
-
"autoClean": true
|
|
313
|
+
"ignoreFiles": ["tests/fixtures/sample-payload.js"],
|
|
314
|
+
"autoClean": true,
|
|
315
|
+
"envGuard": true,
|
|
316
|
+
"envGuardAutoPush": true
|
|
432
317
|
}
|
|
433
318
|
```
|
|
434
319
|
|
|
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
|
|
320
|
+
| Setting | Meaning |
|
|
321
|
+
|---|---|
|
|
322
|
+
| `ignoreFiles` | Files to skip for name and secret checks (for example test files). Malware checks always run. |
|
|
323
|
+
| `autoClean` | `false` = report malware but don't remove it. |
|
|
324
|
+
| `envGuard` | `false` = don't take `.env` files out of pushes. |
|
|
325
|
+
| `envGuardAutoPush` | `false` = take the `.env` out, but let you run `git push` again yourself. |
|
|
453
326
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
```bash
|
|
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
|
-
```
|
|
327
|
+
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
328
|
|
|
471
329
|
---
|
|
472
330
|
|
|
473
|
-
##
|
|
474
|
-
|
|
475
|
-
MIT License Β© 2026
|
|
476
|
-
|
|
477
|
-
---
|
|
331
|
+
## License
|
|
478
332
|
|
|
479
|
-
|
|
333
|
+
MIT
|