@arifbiswas/git-pre-push 1.0.18 β†’ 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 CHANGED
@@ -1,455 +1,331 @@
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
- > ```
23
+ ## Install (2 minutes)
39
24
 
40
-
41
- ### Option 1: Automatic Setup via npm (Recommended)
42
-
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
+ - 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
- 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
- [10] 🧹 Sweep All Repos - Scan every git repo in a folder (whole device)
90
- [5] πŸ—‘οΈ Clean & Quarantine - Remove confirmed malware + trojan scripts here
91
- [4] πŸš€ Scan Remote GitHub Repo - Zero-clone audit (no download/clone)
92
-
93
- ── GitHub login vault (device stays logged out) ──
94
- [11] πŸ” Vault Setup - Encrypt token with Touch ID / Windows Hello / passphrase
95
- [12] πŸ“‹ Vault Status - Check vault, credential helper & SSH keys
96
- [13] πŸ”“ Vault Test Unlock - Try one unlock prompt (token is not used)
97
- [14] 🚫 Vault Remove - Back to normal git login
98
-
99
- ── Other ──
100
- [6] ⚑ Run Push Intercept Demo - Simulate a blocked malware push
101
- [7] πŸ€– Setup GitHub Action CI - Guard repository on GitHub server-side
102
- [9] πŸ”„ Check for Updates - Check if a new version is available on npm
103
- [15] 🩺 Doctor - Something broken? Find it and show/apply the fix
104
- [0] πŸšͺ Exit
105
-
106
- 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
107
84
  ```
108
85
 
109
- ---
110
-
111
- **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).
86
+ Everything in the menu is also a command, listed below.
112
87
 
113
- 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
+ ---
114
89
 
115
- ### Option 3: Lock Down an Entire Machine (Global Protection)
90
+ ## Everyday use
116
91
 
117
- If you suspect your workstation has been compromised, lock down **all Git repositories on your computer** with a single command:
92
+ After `gitsafty init --global` you don't need to do anything. Use git as usual:
118
93
 
119
- ```bash
120
- npx @arifbiswas/git-pre-push init --global
121
- ```
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. |
122
99
 
123
- 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`**.
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.
124
101
 
125
- > Already installed globally? Run `init --global` again after updating so the new clone/pull hooks are added.
102
+ ### Scan every pull
126
103
 
127
- **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:
104
+ Git runs nothing when a pull says *"Already up to date"*. To check those pulls too:
128
105
 
129
106
  ```bash
130
- gitsafty pull-scan on # turn on (also menu [17])
131
- gitsafty pull-scan off # remove the function again
107
+ gitsafty pull-scan on
132
108
  ```
133
109
 
134
- IDE "Sync"/"Pull" buttons that bring changes are covered by the hooks; only no-change pulls from a terminal need the shell function.
135
-
136
- ---
137
-
138
- ## ⚑ How It Works
139
-
140
- ```
141
- Developer or Malware executes: git push
142
- β”‚
143
- β–Ό
144
- Git triggers: .git/hooks/pre-push
145
- β”‚
146
- β–Ό
147
- πŸ›‘οΈ GitSafty Scanner Engine (< 5ms)
148
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
149
- β”‚ 1. Blacklist check (temp_*_push.bat, .exe, .ps1, .vbs) β”‚
150
- β”‚ 2. Outgoing commit diff inspection for payload cradles β”‚
151
- β”‚ 3. IDE backdoor inspection (.vscode/tasks.json, .idea) β”‚
152
- β”‚ 4. Credential & secret leak detection (.env, RSA keys) β”‚
153
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
154
- β”‚
155
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
156
- β–Ό β–Ό
157
- [Threats Found] [Clean Scan]
158
- β”‚ β”‚
159
- ❌ PUSH REJECTED βœ… PUSH ALLOWED
160
- (Malware blocked locally) (Pushed cleanly to GitHub)
110
+ ```bash
111
+ gitsafty pull-scan off
161
112
  ```
162
113
 
163
- ---
164
-
165
- ## 🎯 Threat Detection Capabilities
166
-
167
- ### 1. Injected Scripts & Trojan Filenames
168
- - Known malicious auto-push scripts: `temp_auto_push.bat`, `temp_interactive_push.bat`, `config.bat`, `autorun.bat`, `hidden_push.sh`
169
- - Blocked executable extensions: `*.exe`, `*.scr`, `*.msi`, `*.dll`, `*.vbs`, `*.ps1`, `*.hta`, `*.pif`, `*.cpl`
170
- - Deceptive double-extension tricks: `document.pdf.exe`, `invoice.xlsx.bat`
171
-
172
- ### 2. Obfuscated Payloads & Reverse Shells
173
- - PowerShell obfuscated execution: `powershell -enc`, `powershell -encodedcommand`
174
- - Web download cradles: `Invoke-WebRequest`, `DownloadString`, `IEX`
175
- - Remote pipe-to-shell: `curl ... | bash`, `wget ... | sh`, `curl ... | python`
176
- - Dynamic base64 evaluation: `eval(base64_decode(...))`, `Buffer.from(..., 'base64')`
177
- - Windows LOLBins abuse: `certutil -urlcache`, `bitsadmin /transfer`, `mshta http`
178
- - TCP socket reverse shells: `/bin/sh -i >& /dev/tcp/...`, `nc -e /bin/sh`
179
-
180
- ### 3. IDE Configuration Backdoors
181
- - `.vscode/tasks.json`: Auto-executing shell tasks triggered on folder open (`runOn: "folderOpen"`)
182
- - `.vscode/settings.json`: Malicious terminal profile overrides or shell binary path hijacking
183
- - JetBrains `.idea/`: Suspicious external tool execution in `workspace.xml` or `tasks.xml`
184
-
185
- ### 4. Credential Exfiltration & Secret Leaks
186
- - Hardcoded Discord webhook dumps (`https://discord.com/api/webhooks/...`)
187
- - Telegram Bot token exfiltration endpoints
188
- - Temporary file drop & webhook logging services (`webhook.site`, `pipedream.net`, `filebin.net`)
189
- - Unencrypted production `.env` files being committed
190
- - Leaked cryptographic private keys (`BEGIN RSA PRIVATE KEY`, `ghp_...`, AWS Access Keys)
191
-
192
- ### 5. Deep Malware Engine (clone, pull, push)
193
- Built from real samples of a repository-injection campaign. Every finding gets a verdict:
194
-
195
- | Verdict | Meaning | What GitSafty does |
196
- |---|---|---|
197
- | **MALWARE** (confirmed) | Proof-level signature that legitimate code never produces | Reports it, backs the file up, **removes it automatically**, re-scans to verify |
198
- | **SUSPECT** | Dangerous-looking but can be legitimate | Reports only, never touches the file |
199
-
200
- Confirmed signatures:
201
- - Exact SHA-256 of known malware samples
202
- - `global['!']='9-5756'` loader marker next to an obfuscated decoder
203
- - 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
204
- - Script disguised as a font or image (`.woff2`, `.ttf`, `.png`, ... whose bytes are JavaScript, not the real format; Git LFS pointers are ignored)
205
- - `.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
206
- - `package.json` install scripts that run a font/image as code
207
-
208
- 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.
209
115
 
210
116
  ---
211
117
 
212
- ## πŸ” Always-Logged-Out Vault (last line of defence)
118
+ ## Scanning
213
119
 
214
- 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**:
120
+ ### This project
215
121
 
216
122
  ```bash
217
- npx @arifbiswas/git-pre-push vault setup
123
+ gitsafty scan
218
124
  ```
219
125
 
220
- 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**:
126
+ Checks the whole project and removes confirmed malware. Add `--no-clean` to only report. Menu **5**.
221
127
 
222
- | OS | Protection | Each push asks for |
223
- |---|---|---|
224
- | macOS (Apple Silicon / T2) | **Secure Enclave** P-256 key (`.userPresence`), ECDH β†’ HKDF-SHA256 β†’ **AES-256-GCM** | Touch ID or Mac password (system dialog) |
225
- | 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 |
226
- | Linux / no chip | Passphrase β†’ **scrypt** (N=2¹⁷, r=8, p=1) β†’ **AES-256-GCM** | Your vault passphrase |
128
+ ### All projects in a folder
227
129
 
228
- 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`.
229
- 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.
230
- 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**.
231
- 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
+ ```
232
133
 
233
134
  ```bash
234
- npx @arifbiswas/git-pre-push vault status # helper, chip, vault and SSH key checks
235
- npx @arifbiswas/git-pre-push vault test # one unlock prompt, token is not used
236
- npx @arifbiswas/git-pre-push vault remove # back to normal git login
135
+ gitsafty scan-projects ~/projects --clean
237
136
  ```
238
137
 
239
- 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`).
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**.
240
139
 
241
- ---
140
+ - `--deep` also checks `node_modules` and ignored files.
141
+ - `--json` gives machine-readable output.
242
142
 
243
- ## πŸ”¬ Advanced Scanner (many projects at once)
244
-
245
- Got a folder with 20 projects? Audit all of them in one go:
143
+ ### Everything in a folder, zip files too
246
144
 
247
145
  ```bash
248
- gitsafty scan-projects ~/projects # report only
249
- gitsafty scan-projects ~/projects --clean # also remove CONFIRMED malware
250
- gitsafty scan-projects ~/projects --deep # include node_modules, build output, ignored files
251
- gitsafty scan-projects ~/projects --json # machine-readable output
146
+ gitsafty full-scan ~/Downloads
252
147
  ```
253
148
 
254
- Every direct sub-folder is a project (git repository or not; nested repos are found too). For each one it checks:
149
+ ```bash
150
+ gitsafty full-scan ~/Downloads --clean
151
+ ```
255
152
 
256
- - **Malware**: the confirmed-malware engine on every file (always on, even for ignored paths)
257
- - **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
258
- - **IDE auto-run**: `.vscode` / `.idea` tasks and settings
259
- - **Exposed secrets**: keys and tokens in code, and `.env` files that git tracks (masked in the output)
260
- - **Dangerous files**: executables, disguised double extensions
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
- 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:
155
+ ### All git repos on your disk
263
156
 
264
- ```text
265
- Results per project
266
- Project Status Found Removed To review
267
- shop-backend CLEANED 8 8 0
268
- admin-panel DANGER 2 0 2
269
- mobile-app SECRETS 3 0 3
270
- landing CLEAN 0 0 0
157
+ ```bash
158
+ gitsafty sweep ~
271
159
  ```
272
160
 
273
- 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.
274
-
275
- ---
276
-
277
- ## 🩺 Troubleshooting (`doctor`)
161
+ A fast malware check of every git repository under a folder. Menu **8**.
278
162
 
279
- Something not working? One command finds out what and prints the exact fix:
163
+ ### A GitHub repo before you clone it
280
164
 
281
165
  ```bash
282
- gitsafty doctor # report
283
- gitsafty doctor --fix # apply the safe fixes (rewrite hooks, re-register the vault helper)
166
+ gitsafty scan-remote https://github.com/owner/repo
284
167
  ```
285
168
 
286
- 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.
169
+ Nothing is downloaded to your disk. Menu **10**.
287
170
 
288
- **Can't install or update?**
171
+ ---
289
172
 
290
- | npm error | Fix |
291
- |---|---|
292
- | `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) |
293
- | `ENOTFOUND` / `ETIMEDOUT` | Network/proxy: `npm config get registry`, `npm cache verify`, try again |
294
- | `Unexpected token` / engine warning | Node.js too old: install Node 18+ (`nvm install --lts`) |
173
+ ## Your `.env` file never gets pushed
295
174
 
296
- **Turn GitSafty off without the CLI** (works even when it can't be installed):
175
+ If you commit a `.env` (or `.env.local`, `.env.production` …) and push, GitSafty:
297
176
 
298
- ```bash
299
- git config --global --unset core.hooksPath
300
- rm -rf ~/.git-hooks-safty # Windows PowerShell: Remove-Item -Recurse -Force "$HOME\.git-hooks-safty"
301
- git config --global --remove-section credential.https://github.com # only if you used the vault
302
- ```
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.
182
+
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.**
303
186
 
304
187
  ---
305
188
 
306
- ## πŸ› οΈ CLI Command Reference
189
+ ## Safe GitHub login
307
190
 
308
- | Command | Description |
309
- |---|---|
310
- | `npx @arifbiswas/git-pre-push init` | Installs the pre-push security hook into `.git/hooks/pre-push` |
311
- | `npx @arifbiswas/git-pre-push init --global` | Protects **all** Git repositories across the entire PC |
312
- | `npx @arifbiswas/git-pre-push scan` | Manually audits local workspace files, untracked scripts & staged diffs |
313
- | `npx @arifbiswas/git-pre-push scan-remote` | **Zero-Clone Audit:** Scans any remote GitHub repo without cloning or downloading |
314
- | `npx @arifbiswas/git-pre-push sweep [folder]` | Scans **every** Git repo under a folder (e.g. your projects folder) and removes confirmed malware |
315
- | `npx @arifbiswas/git-pre-push vault setup` | Keeps the device logged out of GitHub; token is encrypted and unlocked only for each push |
316
- | `npx @arifbiswas/git-pre-push clean` | Unstages and quarantines injected malware files to `.git/git-safty-quarantine/` |
317
- | `npx @arifbiswas/git-pre-push demo` | Simulates a blocked push in terminal |
318
- | `npx @arifbiswas/git-pre-push action` | Generates a `.github/workflows/git-safty.yml` CI workflow |
319
- | `npx @arifbiswas/git-pre-push scan-projects <folder>` | **Advanced Scanner**: audit every project in a folder (malware, git backdoors, IDE, secrets) |
320
- | `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) |
321
- | `npx @arifbiswas/git-pre-push doctor [--fix]` | Finds broken/outdated installs and shows (or applies) the exact fix |
322
- | `npx @arifbiswas/git-pre-push uninstall` | Cleanly removes the hook from `.git/hooks` |
191
+ Malware on a computer usually steals saved logins. With safe login on, there is no saved GitHub login to steal.
323
192
 
324
- ---
193
+ ```bash
194
+ gitsafty vault setup
195
+ ```
325
196
 
326
- ## 🌐 Zero-Clone Remote Repository Scanner (`scan-remote`)
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.
327
201
 
328
- Scan any GitHub repository **without cloning or downloading code to your hard drive**:
202
+ The token file is useless on any other computer.
329
203
 
330
204
  ```bash
331
- npx @arifbiswas/git-pre-push scan-remote
205
+ gitsafty vault status
332
206
  ```
333
207
 
334
- The CLI will prompt you for the GitHub URL:
335
- ```text
336
- ? Enter GitHub Repository URL: https://github.com/my-org/my-project
208
+ ```bash
209
+ gitsafty vault test
337
210
  ```
338
211
 
339
- Or pass the URL directly:
340
212
  ```bash
341
- npx @arifbiswas/git-pre-push scan-remote https://github.com/my-org/my-project
213
+ gitsafty vault remove
342
214
  ```
343
215
 
344
- **How it works:**
345
- 1. Fetches the repository's recursive Git tree metadata via GitHub REST API in **1 single HTTP request**.
346
- 2. Performs instant in-memory path matching against all trojan filenames and blacklisted extensions.
347
- 3. Only if a suspicious file is discovered, fetches the specific blob directly into RAM for static payload/secret analysis.
348
- 4. **0 MB downloaded to disk** β€” fast, lightweight, and completely bandwidth-friendly.
216
+ Tips:
217
+
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`.
349
220
 
350
221
  ---
351
222
 
352
- ## 🧹 Quarantine & Remediation (`clean`)
223
+ ## Protect the repository on GitHub too
353
224
 
354
- If malware has already generated files in your project, clean them up instantly:
225
+ Someone can skip local checks with `git push --no-verify`. Add the same check to GitHub Actions:
355
226
 
356
227
  ```bash
357
- npx @arifbiswas/git-pre-push clean
228
+ gitsafty action
358
229
  ```
359
230
 
360
- ```
361
- ================================================================
362
- πŸ›‘οΈ GitSafty: Pre-Push Malware & Secret Guard
363
- ================================================================
364
- Scanning workspace for injected malware scripts to quarantine...
231
+ This adds `.github/workflows/git-safty.yml`. Commit and push it. Menu **17**.
232
+
233
+ ---
365
234
 
366
- ⚠ Quarantined 2 malicious file(s):
367
- βœ– temp_auto_push.bat
368
- βœ– config.bat
235
+ ## Updates
369
236
 
370
- βœ” Cleaned from staging area and moved to quarantine folder (.git/git-safty-quarantine/).
237
+ When you open `gitsafty` it tells you if a new version is out and asks `Install now? (Y/n)`. Or update yourself:
238
+
239
+ ```bash
240
+ npm install -g @arifbiswas/git-pre-push
371
241
  ```
372
242
 
373
- ---
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.
374
244
 
375
- ## πŸ›‘οΈ Defense-in-Depth: GitHub Actions CI Guard
245
+ ---
376
246
 
377
- To guard against attackers attempting to bypass local hooks using `git push --no-verify`, install the GitHub Actions workflow:
247
+ ## Something not working?
378
248
 
379
249
  ```bash
380
- npx @arifbiswas/git-pre-push action
250
+ gitsafty doctor
381
251
  ```
382
252
 
383
- 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.
253
+ It finds what is wrong and shows the exact fix. `gitsafty doctor --fix` applies the safe fixes. Menu **15**.
384
254
 
385
- ---
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. |
386
260
 
387
- ## ☁️ Cloud Scanner & Webhook Platform (`server/`)
261
+ **Turn GitSafty off without the `gitsafty` command:**
388
262
 
389
- The repository includes a standalone cloud scanner microservice in `server/` that integrates with GitHub Apps and Webhooks:
390
- - **Webhook Endpoint (`POST /webhook`):** Verifies HMAC SHA-256 signatures and audits incoming pushes.
391
- - **REST Scan API (`POST /api/scan`):** Recursively fetches remote repository trees (`/git/trees/{sha}?recursive=1`) and inspects file blobs.
392
- - **Auto-Remediation:** Automatically creates remediation commits via GitHub REST API to isolate and remove compromised files.
263
+ ```bash
264
+ git config --global --unset core.hooksPath
265
+ ```
393
266
 
394
- ---
267
+ ```bash
268
+ rm -rf ~/.git-hooks-safty
269
+ ```
395
270
 
396
- ## βš™οΈ Optional Configuration (`.gitsafetyrc.json`)
271
+ On Windows PowerShell: `Remove-Item -Recurse -Force "$HOME\.git-hooks-safty"`.
397
272
 
398
- Works out-of-the-box with zero configuration. You can optionally customize behavior with a `.gitsafetyrc.json` file in your project root:
273
+ If you used safe login, also run:
399
274
 
400
- ```json
401
- {
402
- "ignoreFiles": [
403
- "tests/fixtures/mock-payload.js"
404
- ],
405
- "ignoreRules": [],
406
- "strict": false,
407
- "autoClean": true
408
- }
275
+ ```bash
276
+ git config --global --remove-section credential.https://github.com
409
277
  ```
410
278
 
411
279
  ---
412
280
 
413
- ## πŸ’Ž Comparison: Why git-pre-push Stands Out
281
+ ## All commands
414
282
 
415
- | Feature | Generic Git Hooks / Linters | git-pre-push |
416
- |---|:---:|:---:|
417
- | **Runtime Dependencies** | ❌ 50+ packages (heavy) | βœ… **0 (Pure Node.js built-ins)** |
418
- | **Supply Chain Vulnerability** | ⚠️ High (dependency tree) | πŸ›‘οΈ **Zero** (no external modules) |
419
- | **Execution Overhead** | 🐒 1 - 3 seconds | ⚑ **< 5 milliseconds** |
420
- | **Infostealer Malware Detection** | ❌ No | βœ… **Full signature & payload engine** |
421
- | **IDE Backdoor Detection (.vscode)** | ❌ No | βœ… **Built-in static analysis** |
422
- | **Global Machine Lockdown (`--global`)** | ❌ No | βœ… **One-command PC protection** |
423
- | **Auto-Quarantine Cleaner (`clean`)** | ❌ No | βœ… **Automatic remediation** |
424
- | **Shell Fallback Guard** | ❌ No | βœ… **Built-in POSIX shell fallback** |
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`.
425
302
 
426
303
  ---
427
304
 
428
- ## πŸ§ͺ Test Coverage
305
+ ## Settings (optional)
429
306
 
430
- Verified with Node.js native test runner across all supported platforms:
307
+ Nothing to set up. To change a project's behaviour, add `.gitsafetyrc.json` to the project folder:
431
308
 
432
- ```bash
433
- npm test
434
- ```
435
- ```
436
- βœ” Cloud Scanner Webhook Signature Verification (2 tests)
437
- βœ” Cloud Scanner Remote Tree Audit (1 test)
438
- βœ” Filename & Extension Checks (4 tests)
439
- βœ” Payload Signatures Detection (5 tests)
440
- βœ” Secret & Credential Checks (3 tests)
441
- βœ” IDE Configuration Tampering (2 tests)
442
- βœ” Hook Installer and Uninstaller (1 test)
443
-
444
- β„Ή tests 18 | pass 18 | fail 0 | duration_ms ~300ms
309
+ ```json
310
+ {
311
+ "ignoreFiles": ["tests/fixtures/sample-payload.js"],
312
+ "autoClean": true,
313
+ "envGuard": true,
314
+ "envGuardAutoPush": true
315
+ }
445
316
  ```
446
317
 
447
- ---
448
-
449
- ## πŸ“„ License
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. |
450
324
 
451
- MIT License Β© 2026
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/`.
452
326
 
453
327
  ---
454
328
 
455
- **Built with πŸ›‘οΈ to safeguard developers, teams, and the global software supply chain.**
329
+ ## License
330
+
331
+ MIT