@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 +199 -323
- package/bin/cli.js +14 -0
- package/package.json +1 -1
- package/src/advancedScanner.js +6 -0
- package/src/archive.js +352 -0
- package/src/envGuard.js +262 -0
- package/src/fullScanner.js +371 -0
- package/src/index.js +42 -0
- package/src/malwareCleaner.js +4 -3
- package/src/menu.js +52 -43
- package/src/reporter.js +1 -1
- package/src/utils/git.js +2 -2
package/README.md
CHANGED
|
@@ -1,455 +1,331 @@
|
|
|
1
|
-
#
|
|
1
|
+
# GitSafty (`@arifbiswas/git-pre-push`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
> Intercepts `git push` in real-time to prevent malware, Trojan scripts, compromised IDE configs, and leaked credentials from ever reaching GitHub or poisoning your software supply chain.
|
|
3
|
+
Protects your code and your GitHub account from malware, without changing how you work.
|
|
5
4
|
|
|
6
|
-
[](https://github.com/arifbiswas/git-pre-push/releases)
|
|
7
|
-
[](https://github.com/arifbiswas/git-pre-push/actions/workflows/ci.yml)
|
|
8
5
|
[](https://www.npmjs.com/package/@arifbiswas/git-pre-push)
|
|
9
6
|
[](LICENSE)
|
|
10
|
-
[](#-test-coverage)
|
|
12
|
-
[](#-cross-platform--zero-dependencies)
|
|
7
|
+
[](#)
|
|
13
8
|
|
|
14
9
|
---
|
|
15
10
|
|
|
16
|
-
##
|
|
11
|
+
## What you get
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
**`git-pre-push` stops this attack chain at the source.**
|
|
27
|
-
Whenever `git push` is invokedβfrom terminal, VS Code UI, or any Git GUIβit intercepts the push in milliseconds, inspects outgoing files and commit diffs, and **hard-blocks the push** if any malicious patterns are found.
|
|
13
|
+
- **Malware never reaches GitHub.** Every `git push` is checked. A push with malware is stopped before it leaves your computer.
|
|
14
|
+
- **Infected projects are cleaned for you.** After every `git clone` and `git pull`, the project is checked and malware that GitSafty is sure about is removed automatically. Anything it is not 100% sure about is only reported, never touched.
|
|
15
|
+
- **Your `.env` stays private.** If a push contains a `.env` file, GitSafty takes it out, adds it to `.gitignore`, and pushes your code without it.
|
|
16
|
+
- **Your GitHub login can't be stolen.** With safe login on, your computer stays logged out of GitHub. Each push asks for Touch ID, Windows Hello or a password, and logs out again.
|
|
17
|
+
- **Check everything at once.** Scan a whole folder of projects, your Downloads, zip/rar files, or a GitHub repo before you clone it.
|
|
18
|
+
- **Backups of everything removed**, and a clear report of what was found and what was done.
|
|
19
|
+
- Works with the terminal, VS Code and any git app, on macOS, Windows and Linux. No extra packages are installed.
|
|
28
20
|
|
|
29
21
|
---
|
|
30
22
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
> **Install globally (`-g`).** `npm i @arifbiswas/git-pre-push` without `-g` only puts GitSafty into that project's `node_modules`: there is no `gitsafty` command and other repos stay unprotected. npm does not let a package install itself globally, so when GitSafty notices it is running from a project (or from `npx`) it asks *"Install GitSafty globally now? (Y/n)"* and does it for you. The recommended command is:
|
|
34
|
-
>
|
|
35
|
-
> ```bash
|
|
36
|
-
> npm install -g @arifbiswas/git-pre-push
|
|
37
|
-
> gitsafty init --global
|
|
38
|
-
> ```
|
|
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 -
|
|
28
|
+
npm install -g @arifbiswas/git-pre-push
|
|
47
29
|
```
|
|
48
30
|
|
|
49
|
-
|
|
31
|
+
```bash
|
|
32
|
+
gitsafty init --global
|
|
33
|
+
```
|
|
50
34
|
|
|
51
|
-
|
|
35
|
+
That's it. Every git project on this computer is now protected.
|
|
52
36
|
|
|
53
|
-
|
|
37
|
+
- Use `-g`. Without it GitSafty only lands inside one project and the `gitsafty` command does not exist. If you forget, GitSafty asks to install itself globally the first time it runs.
|
|
38
|
+
- **Windows: `'gitsafty' is not recognized`?** Open a new terminal. Still not found? Add the folder shown by `npm config get prefix` to your `Path`.
|
|
39
|
+
- After `init --global`, GitSafty offers one extra step: checking pulls that say *"Already up to date"* too. Answer `y` for full coverage.
|
|
54
40
|
|
|
55
|
-
|
|
41
|
+
Protect only one project instead:
|
|
56
42
|
|
|
57
43
|
```bash
|
|
58
|
-
|
|
44
|
+
cd my-project
|
|
45
|
+
gitsafty init
|
|
59
46
|
```
|
|
60
47
|
|
|
61
|
-
|
|
62
|
-
> ```bash
|
|
63
|
-
> npm install -g @arifbiswas/git-pre-push
|
|
64
|
-
> gitsafty init --global
|
|
65
|
-
> ```
|
|
66
|
-
> Then open a **new** terminal. On Windows, if it is still not found, add the folder printed by `npm config get prefix` to your `Path` environment variable.
|
|
48
|
+
---
|
|
67
49
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
gitsafty
|
|
71
|
-
```
|
|
50
|
+
## The menu
|
|
51
|
+
|
|
52
|
+
Run `gitsafty` with nothing after it:
|
|
72
53
|
|
|
73
54
|
```text
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
[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
|
-
|
|
88
|
+
---
|
|
114
89
|
|
|
115
|
-
|
|
90
|
+
## Everyday use
|
|
116
91
|
|
|
117
|
-
|
|
92
|
+
After `gitsafty init --global` you don't need to do anything. Use git as usual:
|
|
118
93
|
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
+
### Scan every pull
|
|
126
103
|
|
|
127
|
-
|
|
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
|
|
131
|
-
gitsafty pull-scan off # remove the function again
|
|
107
|
+
gitsafty pull-scan on
|
|
132
108
|
```
|
|
133
109
|
|
|
134
|
-
|
|
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
|
-
##
|
|
118
|
+
## Scanning
|
|
213
119
|
|
|
214
|
-
|
|
120
|
+
### This project
|
|
215
121
|
|
|
216
122
|
```bash
|
|
217
|
-
|
|
123
|
+
gitsafty scan
|
|
218
124
|
```
|
|
219
125
|
|
|
220
|
-
|
|
126
|
+
Checks the whole project and removes confirmed malware. Add `--no-clean` to only report. Menu **5**.
|
|
221
127
|
|
|
222
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
149
|
+
```bash
|
|
150
|
+
gitsafty full-scan ~/Downloads --clean
|
|
151
|
+
```
|
|
255
152
|
|
|
256
|
-
|
|
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
|
-
|
|
155
|
+
### All git repos on your disk
|
|
263
156
|
|
|
264
|
-
```
|
|
265
|
-
|
|
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
|
|
274
|
-
|
|
275
|
-
---
|
|
276
|
-
|
|
277
|
-
## π©Ί Troubleshooting (`doctor`)
|
|
161
|
+
A fast malware check of every git repository under a folder. Menu **8**.
|
|
278
162
|
|
|
279
|
-
|
|
163
|
+
### A GitHub repo before you clone it
|
|
280
164
|
|
|
281
165
|
```bash
|
|
282
|
-
gitsafty
|
|
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
|
-
|
|
169
|
+
Nothing is downloaded to your disk. Menu **10**.
|
|
287
170
|
|
|
288
|
-
|
|
171
|
+
---
|
|
289
172
|
|
|
290
|
-
|
|
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
|
-
|
|
175
|
+
If you commit a `.env` (or `.env.local`, `.env.production` β¦) and push, GitSafty:
|
|
297
176
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
##
|
|
189
|
+
## Safe GitHub login
|
|
307
190
|
|
|
308
|
-
|
|
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
|
-
|
|
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
|
-
|
|
202
|
+
The token file is useless on any other computer.
|
|
329
203
|
|
|
330
204
|
```bash
|
|
331
|
-
|
|
205
|
+
gitsafty vault status
|
|
332
206
|
```
|
|
333
207
|
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
213
|
+
gitsafty vault remove
|
|
342
214
|
```
|
|
343
215
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
##
|
|
223
|
+
## Protect the repository on GitHub too
|
|
353
224
|
|
|
354
|
-
|
|
225
|
+
Someone can skip local checks with `git push --no-verify`. Add the same check to GitHub Actions:
|
|
355
226
|
|
|
356
227
|
```bash
|
|
357
|
-
|
|
228
|
+
gitsafty action
|
|
358
229
|
```
|
|
359
230
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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
|
-
|
|
367
|
-
β temp_auto_push.bat
|
|
368
|
-
β config.bat
|
|
235
|
+
## Updates
|
|
369
236
|
|
|
370
|
-
|
|
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
|
-
|
|
245
|
+
---
|
|
376
246
|
|
|
377
|
-
|
|
247
|
+
## Something not working?
|
|
378
248
|
|
|
379
249
|
```bash
|
|
380
|
-
|
|
250
|
+
gitsafty doctor
|
|
381
251
|
```
|
|
382
252
|
|
|
383
|
-
|
|
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
|
-
|
|
261
|
+
**Turn GitSafty off without the `gitsafty` command:**
|
|
388
262
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
-
|
|
271
|
+
On Windows PowerShell: `Remove-Item -Recurse -Force "$HOME\.git-hooks-safty"`.
|
|
397
272
|
|
|
398
|
-
|
|
273
|
+
If you used safe login, also run:
|
|
399
274
|
|
|
400
|
-
```
|
|
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
|
-
##
|
|
281
|
+
## All commands
|
|
414
282
|
|
|
415
|
-
|
|
|
416
|
-
|
|
417
|
-
|
|
|
418
|
-
|
|
|
419
|
-
|
|
|
420
|
-
|
|
|
421
|
-
|
|
|
422
|
-
|
|
|
423
|
-
|
|
|
424
|
-
|
|
|
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
|
-
##
|
|
305
|
+
## Settings (optional)
|
|
429
306
|
|
|
430
|
-
|
|
307
|
+
Nothing to set up. To change a project's behaviour, add `.gitsafetyrc.json` to the project folder:
|
|
431
308
|
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
329
|
+
## License
|
|
330
|
+
|
|
331
|
+
MIT
|