@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 CHANGED
@@ -1,479 +1,333 @@
1
- # πŸ›‘οΈ git-pre-push (GitSafty)
1
+ # GitSafty (`@arifbiswas/git-pre-push`)
2
2
 
3
- > **Zero-Dependency Pre-Push Security Guard & Infostealer Blocker for Git.**
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
- [![Release](https://img.shields.io/github/v/release/arifbiswas/git-pre-push?style=flat-square&color=blue)](https://github.com/arifbiswas/git-pre-push/releases)
7
- [![CI Test Suite](https://github.com/arifbiswas/git-pre-push/actions/workflows/ci.yml/badge.svg)](https://github.com/arifbiswas/git-pre-push/actions/workflows/ci.yml)
8
5
  [![npm version](https://img.shields.io/npm/v/@arifbiswas/git-pre-push.svg?style=flat-square)](https://www.npmjs.com/package/@arifbiswas/git-pre-push)
9
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](LICENSE)
10
- [![Zero Dependencies](https://img.shields.io/badge/dependencies-0%20(Pure%20Node.js)-brightgreen.svg?style=flat-square)](#-zero-external-runtime-dependencies)
11
- [![Tests Passing](https://img.shields.io/badge/tests-20%2F20%20passing-success.svg?style=flat-square)](#-test-coverage)
12
- [![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey.svg?style=flat-square)](#-cross-platform--zero-dependencies)
7
+ [![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey.svg?style=flat-square)](#)
13
8
 
14
9
  ---
15
10
 
16
- ## πŸ“Œ Why Do You Need This?
11
+ ## What you get
17
12
 
18
- Developer workstations are high-value targets for infostealer malware (RedLine, Lumma, Vidar, etc.) and supply-chain attacks. Once a machine is compromised, malware silently:
19
-
20
- 1. **Injects auto-commit/push scripts** into your Git repositories (e.g., `temp_auto_push.bat`, `temp_interactive_push.bat`, `autorun.bat`, `*.ps1`, `*.vbs`).
21
- 2. **Backdoors your IDE configs** (e.g., `.vscode/tasks.json` with `runOn: "folderOpen"`) so that opening the project immediately triggers remote shell execution on any teammate's machine.
22
- 3. **Exfiltrates secrets & `.env` files** to attacker-controlled Discord webhooks or Telegram bots.
23
- 4. **Leverages stored Git credentials / SSH keys** to automatically push backdoored code straight to GitHub.
24
- 5. **Poisons the Software Supply Chain**, affecting every teammate who pulls the code and every production build deployed from it.
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
- ## πŸš€ Quick Start
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
- Add `git-pre-push` to your project:
25
+ You need [Node.js](https://nodejs.org) 18 or newer and git.
44
26
 
45
27
  ```bash
46
- npm install -D @arifbiswas/git-pre-push
28
+ npm install -g @arifbiswas/git-pre-push
47
29
  ```
48
30
 
49
- > **Zero Configuration Required:** The `postinstall` script automatically installs the `.git/hooks/pre-push` guard in your repository.
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
- ### Option 2: Instant Interactive Menu via npx
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
- Run without arguments to open the interactive selection dashboard:
41
+ Protect only one project instead:
56
42
 
57
43
  ```bash
58
- npx @arifbiswas/git-pre-push
44
+ cd my-project
45
+ gitsafty init
59
46
  ```
60
47
 
61
- > **`gitsafty` "not recognized" / "command not found"?** `npx` only runs GitSafty from a temporary cache; it does not install the `gitsafty` command. Install it permanently (GitSafty also offers this after `npx ... init`):
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
- Or if installed globally (`npm i -g @arifbiswas/git-pre-push`):
69
- ```bash
70
- gitsafty
71
- ```
50
+ ## The menu
51
+
52
+ Run `gitsafty` with nothing after it:
72
53
 
73
54
  ```text
74
- ================================================================
75
- πŸ›‘οΈ GitSafty: Pre-Push Malware & Secret Guard
76
- ================================================================
77
-
78
- Select an action to perform:
79
-
80
- ── Protection ──
81
- [1] πŸ›‘οΈ Install Local Hook - Protect current repo (push + checkout + pull)
82
- [2] 🌐 Install Global Hook - Protect EVERY repo on this PC: scan on clone, pull & push
83
- [17] πŸ” Scan Every Pull - Also scan when git pull says "Already up to date"
84
- [8] ❌ Uninstall Hook - Remove GitSafty hooks (this repo or whole PC)
85
-
86
- ── Malware scan & removal ──
87
- [3] πŸ” Scan Local Workspace - Deep scan this repo, auto-remove confirmed malware
88
- [16] πŸ”¬ Advanced Scanner - Audit ALL projects in a folder: malware, backdoors, secrets
89
- [18] πŸ§ͺ Full Scan - EVERYTHING in a folder: non-git projects + zip/tar/7z/rar
90
- [10] 🧹 Sweep All Repos - Scan every git repo in a folder (whole device)
91
- [5] πŸ—‘οΈ Clean & Quarantine - Remove confirmed malware + trojan scripts here
92
- [4] πŸš€ Scan Remote GitHub Repo - Zero-clone audit (no download/clone)
93
-
94
- ── GitHub login vault (device stays logged out) ──
95
- [11] πŸ” Vault Setup - Encrypt token with Touch ID / Windows Hello / passphrase
96
- [12] πŸ“‹ Vault Status - Check vault, credential helper & SSH keys
97
- [13] πŸ”“ Vault Test Unlock - Try one unlock prompt (token is not used)
98
- [14] 🚫 Vault Remove - Back to normal git login
99
-
100
- ── Other ──
101
- [6] ⚑ Run Push Intercept Demo - Simulate a blocked malware push
102
- [7] πŸ€– Setup GitHub Action CI - Guard repository on GitHub server-side
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
- **Updates:** npm 11+ may print `install scripts not yet covered by allowScripts` after `npm install -g`. The update itself worked; only GitSafty's postinstall step was skipped. That is fine: the next time any `gitsafty` command or git hook runs, GitSafty brings your global hooks and the pull-scan shell function up to date by itself (only from a real global install, never from npx or a source checkout).
88
+ ---
113
89
 
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`.
90
+ ## Everyday use
115
91
 
116
- ### Option 3: Lock Down an Entire Machine (Global Protection)
92
+ After `gitsafty init --global` you don't need to do anything. Use git as usual:
117
93
 
118
- If you suspect your workstation has been compromised, lock down **all Git repositories on your computer** with a single command:
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
- ```bash
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
- This configures `git config --global core.hooksPath`, ensuring every repository on your PC runs the security scanner before any push, **and after every `git clone`, `git checkout` and `git pull`**.
102
+ ### Scan every pull (on by default)
125
103
 
126
- > Already installed globally? Run `init --global` again after updating so the new clone/pull hooks are added.
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
- **Every `git pull` is scanned.** Pulls that bring changes (merge, fast-forward or `--rebase`) are scanned by the hooks, and the whole repository is checked, like after a clone. When git says *"Already up to date"* it runs **no hook at all**, so `init --global` offers to add a small `git` function to your shell profile (`~/.zshrc`, `~/.bashrc`, fish, or the PowerShell profile on Windows) that scans after every `git pull`, keeps git's exit code and never scans twice for the same pull:
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 on # turn on (also menu [17])
132
- gitsafty pull-scan off # remove the function again
109
+ gitsafty pull-scan off
133
110
  ```
134
111
 
135
- IDE "Sync"/"Pull" buttons that bring changes are covered by the hooks; only no-change pulls from a terminal need the shell function.
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
- ## πŸ” Always-Logged-Out Vault (last line of defence)
120
+ ## Scanning
214
121
 
215
- If a machine might still be compromised, the most valuable thing on it is your GitHub token (macOS Keychain, `~/.git-credentials`, `gh`). The vault makes sure there is **no usable token on the device**:
122
+ ### This project
216
123
 
217
124
  ```bash
218
- npx @arifbiswas/git-pre-push vault setup
125
+ gitsafty scan
219
126
  ```
220
127
 
221
- 1. You paste a GitHub token once. It is checked with GitHub, then stored **only encrypted** in `~/.gitsafty/vault.json` (mode 600), locked to this device's **security chip**:
128
+ Checks the whole project and removes confirmed malware. Add `--no-clean` to only report. Menu **5**.
222
129
 
223
- | OS | Protection | Each push asks for |
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
- The chip key never leaves the chip, so a copied `vault.json` is useless on any other machine, and the system prompt can't be approved by malware. All metadata is bound as GCM additional data, so edits are detected. On macOS a small Swift helper is compiled once on your Mac during setup (needs `xcode-select --install`). Force the passphrase mode with `vault setup --passphrase`.
230
- 2. GitSafty becomes the **only** git credential helper for `github.com`. Other helpers (osxkeychain, Windows Credential Manager, `store`, `gh`) are switched off for GitHub, and saved GitHub logins in the macOS Keychain and `~/.git-credentials` are deleted.
231
- 3. On `git push`, git asks GitSafty for a login. GitSafty shows the chip prompt, decrypts the token **in memory**, gives it to git for that one command and wipes it. Git's "save this login" step is ignored, so after the push the device is **logged out again**.
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
- npx @arifbiswas/git-pre-push vault status # helper, chip, vault and SSH key checks
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
- Limits, honestly: the chip stops token theft (copying files, Keychain or browser stores), which is how stealers work. It can't stop malware that is running while you approve your own push from riding along with that one approved command, and in passphrase mode a keylogger can capture the passphrase. So also use a **fine-grained token with a short expiry and only the repos you need**, and rotate it. SSH remotes do not use git credential helpers: `vault status` warns about SSH private keys without a passphrase (`ssh-keygen -p -f ~/.ssh/id_ed25519`).
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
- ## πŸ§ͺ Full Scan (everything in a folder, archives too)
145
+ ### Everything in a folder, zip files too
245
146
 
246
- The normal scan and the Advanced Scanner work on projects. **Full Scan** checks *everything* in a folder: projects that were never connected to git, downloads, backups, and the files **inside archives**.
147
+ ```bash
148
+ gitsafty full-scan ~/Downloads
149
+ ```
247
150
 
248
151
  ```bash
249
- gitsafty full-scan ~/Downloads # report only
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
- - **Every file**, git repository or not. Git backdoors are checked in every repository it passes.
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
- With `--clean`, a loose file is repaired or removed exactly like on clone and pull. An **archive with malware inside is moved to quarantine whole**, because an archive can't be safely rewritten. Read-only backups and a report go to `~/.gitsafty/quarantine/full-scan-<time>/`. At the end you see each infected archive or folder, what was found, what was removed, and what still needs review. Menu option **[18]**.
157
+ ### All git repos on your disk
263
158
 
264
- ---
159
+ ```bash
160
+ gitsafty sweep ~
161
+ ```
265
162
 
266
- ## πŸ”¬ Advanced Scanner (many projects at once)
163
+ A fast malware check of every git repository under a folder. Menu **8**.
267
164
 
268
- Got a folder with 20 projects? Audit all of them in one go:
165
+ ### A GitHub repo before you clone it
269
166
 
270
167
  ```bash
271
- gitsafty scan-projects ~/projects # report only
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
- Every direct sub-folder is a project (git repository or not; nested repos are found too). For each one it checks:
171
+ Nothing is downloaded to your disk. Menu **10**.
278
172
 
279
- - **Malware**: the confirmed-malware engine on every file (always on, even for ignored paths)
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
- When it finishes you get, for every project, what was found, what was **removed** (and how: whole file quarantined, or malware cut out and the rest kept), and what still needs your attention with the exact command to fix it, followed by a table:
175
+ ## Your `.env` file never gets pushed
286
176
 
287
- ```text
288
- Results per project
289
- Project Status Found Removed To review
290
- shop-backend CLEANED 8 8 0
291
- admin-panel DANGER 2 0 2
292
- mobile-app SECRETS 3 0 3
293
- landing CLEAN 0 0 0
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
- A JSON report is saved to `~/.gitsafty/reports/`. Only confirmed malware is ever removed (with backups); backdoors and secrets are reported with a fix command. Use `.gitsafetyrc.json` `ignoreFiles` for known test fixtures.
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
- ## 🩺 Troubleshooting (`doctor`)
191
+ ## Safe GitHub login
301
192
 
302
- Something not working? One command finds out what and prints the exact fix:
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 doctor # report
306
- gitsafty doctor --fix # apply the safe fixes (rewrite hooks, re-register the vault helper)
196
+ gitsafty vault setup
307
197
  ```
308
198
 
309
- It checks Node.js, git, the global hooks (missing, outdated, or pointing to a GitSafty that was uninstalled or moved), and the GitHub login helper (e.g. it points to a Node.js version that nvm removed). Every GitSafty error also ends with a "πŸ’‘ What to do" hint, and if GitSafty itself is gone, every `git clone` / `git pull` / `git push` prints how to reinstall or turn it off.
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
- **Can't install or update?**
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
- **Turn GitSafty off without the CLI** (works even when it can't be installed):
206
+ ```bash
207
+ gitsafty vault status
208
+ ```
320
209
 
321
210
  ```bash
322
- git config --global --unset core.hooksPath
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
- ## πŸ› οΈ CLI Command Reference
218
+ Tips:
330
219
 
331
- | Command | Description |
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
- ## 🌐 Zero-Clone Remote Repository Scanner (`scan-remote`)
225
+ ## Protect the repository on GitHub too
351
226
 
352
- Scan any GitHub repository **without cloning or downloading code to your hard drive**:
227
+ Someone can skip local checks with `git push --no-verify`. Add the same check to GitHub Actions:
353
228
 
354
229
  ```bash
355
- npx @arifbiswas/git-pre-push scan-remote
230
+ gitsafty action
356
231
  ```
357
232
 
358
- The CLI will prompt you for the GitHub URL:
359
- ```text
360
- ? Enter GitHub Repository URL: https://github.com/my-org/my-project
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
- npx @arifbiswas/git-pre-push scan-remote https://github.com/my-org/my-project
242
+ npm install -g @arifbiswas/git-pre-push
366
243
  ```
367
244
 
368
- **How it works:**
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
- ## 🧹 Quarantine & Remediation (`clean`)
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
- npx @arifbiswas/git-pre-push clean
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
- ⚠ Quarantined 2 malicious file(s):
391
- βœ– temp_auto_push.bat
392
- βœ– config.bat
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
- βœ” Cleaned from staging area and moved to quarantine folder (.git/git-safty-quarantine/).
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
- ## πŸ›‘οΈ Defense-in-Depth: GitHub Actions CI Guard
273
+ On Windows PowerShell: `Remove-Item -Recurse -Force "$HOME\.git-hooks-safty"`.
400
274
 
401
- To guard against attackers attempting to bypass local hooks using `git push --no-verify`, install the GitHub Actions workflow:
275
+ If you used safe login, also run:
402
276
 
403
277
  ```bash
404
- npx @arifbiswas/git-pre-push action
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
- ## ☁️ Cloud Scanner & Webhook Platform (`server/`)
283
+ ## All commands
412
284
 
413
- The repository includes a standalone cloud scanner microservice in `server/` that integrates with GitHub Apps and Webhooks:
414
- - **Webhook Endpoint (`POST /webhook`):** Verifies HMAC SHA-256 signatures and audits incoming pushes.
415
- - **REST Scan API (`POST /api/scan`):** Recursively fetches remote repository trees (`/git/trees/{sha}?recursive=1`) and inspects file blobs.
416
- - **Auto-Remediation:** Automatically creates remediation commits via GitHub REST API to isolate and remove compromised files.
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
- ## βš™οΈ Optional Configuration (`.gitsafetyrc.json`)
307
+ ## Settings (optional)
421
308
 
422
- Works out-of-the-box with zero configuration. You can optionally customize behavior with a `.gitsafetyrc.json` file in your project root:
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
- "tests/fixtures/mock-payload.js"
428
- ],
429
- "ignoreRules": [],
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
- ## πŸ’Ž Comparison: Why git-pre-push Stands Out
438
-
439
- | Feature | Generic Git Hooks / Linters | git-pre-push |
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
- Verified with Node.js native test runner across all supported platforms:
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
- ## πŸ“„ License
474
-
475
- MIT License Β© 2026
476
-
477
- ---
331
+ ## License
478
332
 
479
- **Built with πŸ›‘οΈ to safeguard developers, teams, and the global software supply chain.**
333
+ MIT