@arifbiswas/git-pre-push 0.0.0-stage → 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -1,3 +1,207 @@
1
- # Temporary Holding Version
1
+ # 🛡️ git-pre-push (GitSafty)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **The Zero-Dependency Pre-Push Security Guard & Malware Blocker for Git.**
4
+ > Stops infostealers, injected Trojan scripts, IDE backdoors, and leaked credentials from ever reaching GitHub or poisoning your software supply chain.
5
+
6
+ [![npm version](https://img.shields.io/badge/npm-v1.0.0-blue.svg)](https://www.npmjs.com/package/git-pre-push)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
8
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0%20(Pure%20Node.js)-brightgreen.svg)](#-zero-external-runtime-dependencies)
9
+ [![Tests Passing](https://img.shields.io/badge/tests-15%2F15%20passing-success.svg)](#-test-coverage)
10
+
11
+ ---
12
+
13
+ ## 📌 কেন আপনার এই প্যাকেজটি প্রয়োজন? (Why Do You Need This?)
14
+
15
+ আজকাল ডেভেলপারদের পিসি প্রায়ই ইনফোস্টিলার (Infostealer) ম্যালওয়্যার দ্বারা আক্রান্ত হয়। পিসিতে একবার ম্যালওয়্যার ঢুকলে তা ব্যাকগ্রাউন্ডে বসে:
16
+ 1. আপনার কোডবেজে ক্ষতিকর স্ক্রিপ্ট ইনজেক্ট করে (যেমন: `temp_auto_push.bat`, `temp_interactive_push.bat`, `autorun.bat`, `*.ps1`, `*.vbs`)।
17
+ 2. `.vscode/tasks.json` বা `.vscode/settings.json` ফাইলে ব্যাকডোর তৈরি করে, যাতে অন্য কোনো ডেভেলপার বা আপনি প্রোজেক্ট ওপেন করলেই ম্যালওয়্যার অটো-রান হয়ে যায়।
18
+ 3. আপনার প্রোজেক্টের `.env` ফাইল বা প্রাইভেট এপিআই কী Discord Webhook বা Telegram Bot-এ পাচার করে।
19
+ 4. সবচেয়ে মারাত্মক বিষয়: আপনার পিসির সংরক্ষিত GitHub Credentials বা SSH Key ব্যবহার করে **অটোমেটিকভাবে GitHub-এ ম্যালওয়্যার পুশ করে দেয়!**
20
+ 5. এর ফলে আপনার পুরো টিম এবং ক্লায়েন্টদের সফটওয়্যার সাপ্লাই চেইন (Supply Chain) আক্রান্ত হয়ে পড়ে।
21
+
22
+ **`git-pre-push` ঠিক এই আক্রমণের বিরুদ্ধেই প্রাচীর হিসেবে কাজ করে।**
23
+ ডেভেলপার টার্মিনাল, VS Code কিংবা যেকোনো Git GUI থেকে `git push` দিলে, কোড GitHub-এ যাওয়ার আগেই মিলিসেকেন্ডের মধ্যে আউটগোয়িং কোড ও ফাইল স্ক্যান করে ম্যালওয়্যার শনাক্ত হওয়া মাত্র **পুশ রিজেক্ট (Hard Block)** করে দেয়!
24
+
25
+ ---
26
+
27
+ ## 🚀 এক নজরে ইনস্টলেশন ও ব্যবহার (Quick Start)
28
+
29
+ ### ১. যেকোনো প্রজেক্টে অটোমেটিক সেটআপ (Recommended)
30
+
31
+ আপনার প্রজেক্টে প্যাকেজটি ইনস্টল করুন:
32
+
33
+ ```bash
34
+ npm install -D git-pre-push
35
+ ```
36
+
37
+ > **ম্যাজিক:** ইনস্টল হওয়ার সাথে সাথেই এর `postinstall` স্ক্রিপ্ট আপনার প্রজেক্টের `.git/hooks/pre-push` ফাইলটি স্বয়ংক্রিয়ভাবে তৈরি করে প্রোটেকশন চালু করে দেবে। আপনার আর কোনো ম্যানুয়াল কনফিগারেশন করতে হবে না!
38
+
39
+ ---
40
+
41
+ ### ২. কোনো কিছু ইনস্টল না করে সরাসরি চালানো (Zero Install via npx)
42
+
43
+ যেকোনো Git রিপোজিটরিতে ঢুকে টার্মিনালে রান করুন:
44
+
45
+ ```bash
46
+ npx git-pre-push init
47
+ ```
48
+
49
+ ব্যস! আপনার রিপোজিটরি সাথে সাথে সুরক্ষিত।
50
+
51
+ ---
52
+
53
+ ### ৩. আক্রান্ত পিসির সব প্রজেক্ট একসাথে লক করা (Global Protection)
54
+
55
+ আপনার পিসি যদি অলরেডি কোনো ম্যালওয়্যার দ্বারা আক্রান্ত হয়ে থাকে, তবে একটি কমান্ডেই পিসির সমস্ত গিট রিপোজিটরি সুরক্ষিত করুন:
56
+
57
+ ```bash
58
+ npx git-pre-push init --global
59
+ ```
60
+
61
+ এটি আপনার সিস্টেমের `git config --global core.hooksPath` সেট করে দেয়, ফলে আপনার পিসির **যেকোনো ফোল্ডার বা প্রজেক্ট** থেকে পুশ দিলে স্বয়ংক্রিয়ভাবে সিকিউরিটি গার্ড সক্রিয় থাকবে।
62
+
63
+ ---
64
+
65
+ ## ⚡ কীভাবে কাজ করে? (Architecture Flow)
66
+
67
+ ```
68
+ ডেভেলপার বা ম্যালওয়্যার রান করলো: git push
69
+ │
70
+ ▼
71
+ Git ইন্টারসেপ্ট করবে: .git/hooks/pre-push
72
+ │
73
+ ▼
74
+ 🛡️ GitSafty Scanner ইঞ্জিন (< 5ms)
75
+ ┌────────────────────────────────────────────────────────┐
76
+ │ 1. ফাইলনেম ব্লকলিস্ট চেক (temp_*_push.bat, .exe, .ps1) │
77
+ │ 2. আউটগোয়িং কোড ডিফে ম্যালিসিয়াস পেলোড স্ক্যান │
78
+ │ 3. .vscode ও .idea ব্যাকডোর কনফিগারেশন চেকিং │
79
+ │ 4. লিক হওয়া গোপন তথ্য (.env, API Key, Private Key) │
80
+ └────────────────────────────────────────────────────────┘
81
+ │
82
+ ┌──────────────────────┴──────────────────────┐
83
+ ▼ ▼
84
+ [ম্যালওয়্যার পাওয়া গেছে] [সব ক্লিন আছে]
85
+ │ │
86
+ ❌ PUSH REJECTED (Blocked) ✅ PUSH ALLOWED
87
+ (GitHub-এ ক্ষতিকর কোড যেতে পারবে না) (নিরাপদে GitHub-এ পুশ হবে)
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 🎯 আমরা কী কী সমস্যার সমাধান (Solutions) করেছি?
93
+
94
+ ### ১. ইনজেক্টেড ব্যাচ ও ট্রোজান স্ক্রিপ্ট প্রতিরোধ
95
+ - `temp_auto_push.bat`, `temp_interactive_push.bat`, `config.bat`, `autorun.bat`, `hidden_push.sh`
96
+ - বিপজ্জনক এক্সটেনশন: `*.vbs`, `*.ps1`, `*.exe`, `*.scr`, `*.msi`, `*.dll`, `*.hta`
97
+ - ছদ্মবেশী ডাবল এক্সটেনশন ব্লকিং (যেমন: `invoice.pdf.exe`)
98
+
99
+ ### ২. অবফাসকেটেড ম্যালওয়্যার পেলোড ও রিভার্স শেল ডিটেকশন
100
+ - PowerShell Encoded Commands: `powershell -enc ...`, `powershell -encodedcommand`
101
+ - PowerShell Download Cradles: `DownloadString`, `Invoke-WebRequest`, `IEX`
102
+ - রিমোট পাইপ এক্সিকিউশন: `curl ... | bash` বা `wget ... | sh`
103
+ - ডায়নামিক কোড ইভালুয়েশন: `eval(base64_decode(...))`, `Buffer.from(..., 'base64')`
104
+ - Windows LOLBins এক্সপ্লয়েট: `certutil -urlcache`, `bitsadmin /transfer`, `mshta`
105
+ - সরাসরি সকেট রিভার্স শেল: `/bin/sh -i >& /dev/tcp/...`, `nc -e /bin/sh`
106
+
107
+ ### ৩. IDE ব্যাকডোর ও অটো-রান টাস্ক প্রতিরোধ
108
+ - `.vscode/tasks.json`-এ প্রোজেক্ট ওপেন হওয়ার সাথে সাথে অটো-রান ব্যাকডোর (`runOn: "folderOpen"`) শনাক্ত ও ব্লক।
109
+ - `.vscode/settings.json`-এ টার্মিনাল এনভায়রনমেন্ট বা শেল হাইজ্যাকিং প্রতিরোধ।
110
+ - JetBrains `.idea/` ফোল্ডারে লুকানো এক্সটার্নাল স্ক্রিপ্ট টাস্ক শনাক্তকরণ।
111
+
112
+ ### ৪. ক্রেডেনশিয়াল চুরি ও ডেটা এক্সফিল্ট্রেশন রোধ
113
+ - Discord Webhook টোকেন স্টিলার (`https://discord.com/api/webhooks/...`)
114
+ - Telegram Bot API দিয়ে ডেটা চুরি
115
+ - পাবলিক ড্রপার বা রিকোয়েস্ট লগার (`webhook.site`, `pipedream`, ইত্যাদি)
116
+ - ভুলবশত প্রোডাকশন `.env` ফাইল কমিট হওয়া প্রতিরোধ
117
+ - প্রাইভেট ক্রিপ্টোগ্রাফিক কী (`BEGIN RSA PRIVATE KEY`, `ghp_...`, AWS Access Keys)
118
+
119
+ ### ৫. অলরেডি আক্রান্ত পিসি ক্লিন করা (Auto-Quarantine & Fix)
120
+ আক্রান্ত পিসিতে ম্যালওয়্যার যেসব ফাইল তৈরি করে রেখেছে, তা খুঁজতে হবে না। সরাসরি রান করুন:
121
+ ```bash
122
+ npx git-pre-push clean
123
+ ```
124
+ এটি সাথে সাথে রিপোজিটরির সব সংক্রামিত ফাইল শনাক্ত করে গিট ইনডেক্স থেকে আনস্টেজ করবে এবং নিরাপদ কোয়ারেন্টাইন ডিরেক্টরিতে (`.git/git-safty-quarantine/`) পাঠিয়ে দেবে।
125
+
126
+ ### ৬. Zero-Bypass CI Defense (GitHub Action)
127
+ ম্যালওয়্যার যদি কখনো লোকাল হুক বাইপাস করার জন্য `git push --no-verify` কমান্ড ব্যবহার করে, তবে ক্লাউড লেভেলের সুরক্ষার জন্য রান করুন:
128
+ ```bash
129
+ npx git-pre-push action
130
+ ```
131
+ এটি রিপোজিটরিতে `.github/workflows/git-safty.yml` ফাইল তৈরি করে দেবে। ফলে কেউ লোকাল হুক এড়িয়ে পুশ দিলেও GitHub Actions-এ PR বা পুশ সাথে সাথে ফেইল হয়ে ব্লক হয়ে যাবে।
132
+
133
+ ### ৭. ক্লাউড ও রিমোট রিপোজিটরি স্ক্যানার (Cloud Scanner Engine)
134
+ আমরা `server/` ডিরেক্টরিতে একটি সম্পূর্ণ লাইটওয়েট ক্লাউড স্ক্যানার ইঞ্জিন তৈরি করেছি যা GitHub Webhook বা GitHub REST API-এর মাধ্যমে রিমোট রিপোজিটরির ফুল ফাইল ট্রি স্ক্যান করতে পারে এবং ম্যালওয়্যার পাওয়া গেলে স্বয়ংক্রিয়ভাবে `git commit` দিয়ে ফাইল রিমুভ (Auto-Remediation) করতে পারে।
135
+
136
+ ---
137
+
138
+ ## 🛠️ CLI কমান্ড রেফারেন্স (Command Reference)
139
+
140
+ | কমান্ড | বিবরণ |
141
+ |---|---|
142
+ | `npx git-pre-push init` | বর্তমান রিপোজিটরিতে লোকাল `pre-push` সিকিউরিটি হুক ইনস্টল করে |
143
+ | `npx git-pre-push init --global` | আক্রান্ত পিসির **সবগুলো** গিট প্রজেক্ট একসাথে এক কমান্ডে লক করে |
144
+ | `npx git-pre-push scan` | বর্তমান ওয়ার্কস্পেস ও স্টেজড ফাইলে কোনো ম্যালওয়্যার আছে কিনা অডিট করে |
145
+ | `npx git-pre-push clean` | ম্যালওয়্যারের ইনজেক্ট করা সব ফাইল কোয়ারেন্টাইনে পাঠিয়ে পিসি সুরক্ষিত করে |
146
+ | `npx git-pre-push action` | সার্ভার-সাইড সুরক্ষার জন্য GitHub Actions CI ওয়ার্কফ্লো তৈরি করে |
147
+ | `npx git-pre-push uninstall` | রিপোজিটরি থেকে হুকটি পরিষ্কারভাবে রিমুভ করে |
148
+
149
+ ---
150
+
151
+ ## ⚙️ কাস্টম কনফিগারেশন (Optional `.gitsafetyrc.json`)
152
+
153
+ কোনো স্পেসিফিক ফাইল বা রুল ইগনোর করতে চাইলে রুট ফোল্ডারে `.gitsafetyrc.json` তৈরি করতে পারেন (বাই ডিফল্ট কোনো কনফিগারেশন ছাড়াই এটি সেরা পারফরম্যান্সে চলে):
154
+
155
+ ```json
156
+ {
157
+ "ignoreFiles": [
158
+ "tests/fixtures/mock-payload.js"
159
+ ],
160
+ "ignoreRules": [],
161
+ "strict": false
162
+ }
163
+ ```
164
+
165
+ ---
166
+
167
+ ## 💎 কেন `git-pre-push` অন্যান্য টুলস থেকে আলাদা?
168
+
169
+ | ফিচার | সাধারণ লিন্টার / হুক্স | git-pre-push |
170
+ |---|:---:|:---:|
171
+ | **Zero Runtime Dependencies** | ❌ (শতাধিক ডিপেনডেন্সি) | ✅ (১০০% পিওর Node.js built-ins) |
172
+ | **সাপ্লাই চেইন রিস্ক** | ⚠️ রয়েছে | 🛡️ শূন্য (কোনো থার্ড পার্টি প্যাকেজ নেই) |
173
+ | **এক্সিকিউশন টাইম** | 🐢 ১ - ৩ সেকেন্ড | ⚡ < ৫ মিলিসেকেন্ড |
174
+ | **Infostealer ম্যালওয়্যার ব্লকিং** | ❌ নেই | ✅ ফুল ব্লকলিস্ট ও সিগনেচার ডিটেকশন |
175
+ | **IDE ব্যাকডোর চেকার (.vscode)** | ❌ নেই | ✅ ইনবিল্ট স্বয়ংক্রিয় অ্যানালাইসিস |
176
+ | **গ্লোবাল পিসি প্রোটেকশন (`--global`)** | ❌ নেই | ✅ এক কমান্ডেই পুরো পিসির সব প্রজেক্ট লক |
177
+ | **ইনফেক্টেড ফাইল কোয়ারেন্টাইন (`clean`)** | ❌ নেই | ✅ স্বয়ংক্রিয়ভাবে ক্লিনআপ |
178
+ | **শেল ফলব্যাক সাপোর্ট** | ❌ নেই | ✅ Node না থাকলেও শেল স্ক্রিপ্ট প্রটেক্ট করে |
179
+
180
+ ---
181
+
182
+ ## 🧪 টেস্ট কভারেজ (Test Coverage)
183
+
184
+ আমাদের টেস্ট স্যুট সম্পূর্ণ Node.js নেটিভ টেস্ট রানার দিয়ে পরিচালিত:
185
+
186
+ ```bash
187
+ npm test
188
+ ```
189
+ ```
190
+ ✔ Filename & Extension Checks (4 tests)
191
+ ✔ Payload Signatures Detection (5 tests)
192
+ ✔ Secret & Credential Checks (3 tests)
193
+ ✔ IDE Configuration Tampering (2 tests)
194
+ ✔ Hook Installer and Uninstaller (1 test)
195
+
196
+ ℹ tests 15 | pass 15 | fail 0 | duration_ms ~160ms
197
+ ```
198
+
199
+ ---
200
+
201
+ ## 📄 লাইসেন্স (License)
202
+
203
+ MIT License © 2026
204
+
205
+ ---
206
+
207
+ **Made with 🛡️ to protect developers, teams, and the open-source software supply chain.**
package/bin/cli.js ADDED
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { runPrePush, runManualScan, installHook, uninstallHook } = require('../src/index');
4
+ const { cleanInfectedFiles } = require('../src/cleaner');
5
+ const { setupGitHubAction } = require('../src/action');
6
+ const { banner, colors } = require('../src/reporter');
7
+
8
+ const args = process.argv.slice(2);
9
+ const command = args[0] ? args[0].toLowerCase() : 'help';
10
+ const isGlobalFlag = args.includes('--global') || args.includes('-g');
11
+
12
+ async function main() {
13
+ switch (command) {
14
+ case 'scan-push':
15
+ await runPrePush();
16
+ break;
17
+
18
+ case 'scan':
19
+ case 'check':
20
+ runManualScan();
21
+ break;
22
+
23
+ case 'clean':
24
+ case 'fix': {
25
+ banner();
26
+ console.log(`${colors.cyan}Scanning workspace for injected malware scripts to quarantine...${colors.reset}`);
27
+ const cleanResult = cleanInfectedFiles();
28
+ if (cleanResult.quarantined.length > 0) {
29
+ console.log(`\n${colors.yellow}${colors.bold}⚠ Quarantined ${cleanResult.quarantined.length} malicious file(s):${colors.reset}`);
30
+ for (const q of cleanResult.quarantined) {
31
+ console.log(` ${colors.red}✖ ${q}${colors.reset}`);
32
+ }
33
+ console.log(`\n${colors.green}${colors.bold}✔ Cleaned from staging area and moved to quarantine folder (.git/git-safty-quarantine/).${colors.reset}\n`);
34
+ } else {
35
+ console.log(`\n${colors.green}${colors.bold}✔ No known malware scripts found in project files.${colors.reset}\n`);
36
+ }
37
+ break;
38
+ }
39
+
40
+ case 'action':
41
+ case 'ci': {
42
+ banner();
43
+ const res = setupGitHubAction();
44
+ if (res.success) {
45
+ console.log(`\n${colors.green}${colors.bold}✔ ${res.message}${colors.reset}`);
46
+ console.log(`${colors.cyan}Now, even if a compromised PC pushes with --no-verify, GitHub Actions CI will block the build/PR!${colors.reset}\n`);
47
+ } else {
48
+ console.error(`\n${colors.red}${colors.bold}✖ ${res.message}${colors.reset}\n`);
49
+ process.exit(1);
50
+ }
51
+ break;
52
+ }
53
+
54
+ case 'init':
55
+ case 'install': {
56
+ banner();
57
+ const result = installHook(process.cwd(), isGlobalFlag);
58
+ if (result.success) {
59
+ console.log(`\n${colors.green}${colors.bold}✔ ${result.message}${colors.reset}\n`);
60
+ console.log(`${colors.cyan}Your git environment is now protected!${colors.reset}`);
61
+ console.log(`${colors.dim}Every 'git push' will automatically scan outgoing commits for malware & secret leaks.${colors.reset}\n`);
62
+ } else {
63
+ console.error(`\n${colors.red}${colors.bold}✖ ${result.message}${colors.reset}\n`);
64
+ process.exit(1);
65
+ }
66
+ break;
67
+ }
68
+
69
+ case 'uninstall':
70
+ case 'remove': {
71
+ banner();
72
+ const result = uninstallHook();
73
+ if (result.success) {
74
+ console.log(`\n${colors.yellow}${colors.bold}✔ ${result.message}${colors.reset}\n`);
75
+ } else {
76
+ console.error(`\n${colors.red}${colors.bold}✖ ${result.message}${colors.reset}\n`);
77
+ process.exit(1);
78
+ }
79
+ break;
80
+ }
81
+
82
+ case 'help':
83
+ case '--help':
84
+ case '-h':
85
+ default:
86
+ banner();
87
+ console.log(`
88
+ ${colors.bold}Usage:${colors.reset}
89
+ npx git-safty <command>
90
+
91
+ ${colors.bold}Commands:${colors.reset}
92
+ ${colors.green}init${colors.reset} Install the pre-push guard hook into .git/hooks/pre-push
93
+ ${colors.green}scan${colors.reset} Scan current repository, staged files & working tree
94
+ ${colors.green}scan-push${colors.reset} Triggered automatically by git during 'git push'
95
+ ${colors.green}uninstall${colors.reset} Remove git-safty hook from .git/hooks
96
+
97
+ ${colors.bold}How it works:${colors.reset}
98
+ 1. Run ${colors.cyan}npx git-safty init${colors.reset} in any git repository.
99
+ 2. Whenever you run ${colors.cyan}git push${colors.reset}, GitSafty automatically intercepts and scans:
100
+ - Outgoing modified files for blacklisted & trojan scripts (temp_auto_push.bat, .vbs, .ps1, .exe, etc.)
101
+ - Outgoing diff content for obfuscated payloads (base64 eval, powershell cradles, curl | bash, lolbins)
102
+ - IDE settings (.vscode/tasks.json, .vscode/settings.json, JetBrains configs)
103
+ - Leaked API keys, private keys, and .env files
104
+ 3. If malware or critical secrets are detected, ${colors.red}${colors.bold}the push is rejected immediately${colors.reset}!
105
+
106
+ ${colors.bold}Zero Dependencies:${colors.reset} 100% pure Node.js built-ins.
107
+ `);
108
+ break;
109
+ }
110
+ }
111
+
112
+ main().catch((err) => {
113
+ console.error(`[git-safty error]:`, err);
114
+ process.exit(1);
115
+ });
116
+
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@arifbiswas/git-pre-push",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Zero-dependency pre-push security guard that stops malware, injected scripts, and leaked secrets from reaching GitHub.",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "git-pre-push": "./bin/cli.js",
8
+ "git-safty": "./bin/cli.js"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "src",
16
+ "scripts",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "test": "node --test test/*.test.js",
22
+ "init": "node bin/cli.js init",
23
+ "scan": "node bin/cli.js scan",
24
+ "postinstall": "node scripts/postinstall.js"
25
+ },
26
+ "keywords": [
27
+ "git-hook",
28
+ "security",
29
+ "pre-push",
30
+ "malware-detection",
31
+ "infostealer-blocker",
32
+ "secret-leak",
33
+ "gitguard"
34
+ ],
35
+ "engines": {
36
+ "node": ">=16.0.0"
37
+ },
38
+ "author": "",
39
+ "license": "MIT"
40
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Automatically executed on npm postinstall
3
+ */
4
+
5
+ const { installHook } = require('../src/installer');
6
+ const { isGitRepo } = require('../src/utils/git');
7
+
8
+ function main() {
9
+ // In CI or production install without git, exit gracefully
10
+ if (process.env.CI || process.env.CONTINUOUS_INTEGRATION) {
11
+ return;
12
+ }
13
+
14
+ // When installed as a dependency, process.env.INIT_CWD points to the parent project
15
+ const targetDir = process.env.INIT_CWD || process.cwd();
16
+
17
+ if (isGitRepo(targetDir)) {
18
+ const result = installHook(targetDir);
19
+ if (result.success) {
20
+ console.log(`[git-safty] 🛡️ Pre-push security hook installed in ${targetDir}`);
21
+ }
22
+ }
23
+ }
24
+
25
+ main();
26
+
package/src/action.js ADDED
@@ -0,0 +1,63 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const WORKFLOW_YAML = `name: GitSafty Security Guard
5
+
6
+ on:
7
+ push:
8
+ branches: [ "**" ]
9
+ pull_request:
10
+ branches: [ "**" ]
11
+
12
+ jobs:
13
+ security-scan:
14
+ name: Scan Outgoing Commits for Malware & Secrets
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - name: Checkout Code
18
+ uses: actions/checkout@v4
19
+ with:
20
+ fetch-depth: 0
21
+
22
+ - name: Setup Node.js
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: '20'
26
+
27
+ - name: Run GitSafty Security Audit
28
+ run: |
29
+ npx git-safty scan
30
+ `;
31
+
32
+ /**
33
+ * Creates .github/workflows/git-safty.yml for defense in depth
34
+ * @param {string} [cwd]
35
+ * @returns {{ success: boolean, message: string }}
36
+ */
37
+ function setupGitHubAction(cwd = process.cwd()) {
38
+ try {
39
+ const workflowDir = path.join(cwd, '.github', 'workflows');
40
+ if (!fs.existsSync(workflowDir)) {
41
+ fs.mkdirSync(workflowDir, { recursive: true });
42
+ }
43
+
44
+ const workflowFile = path.join(workflowDir, 'git-safty.yml');
45
+ fs.writeFileSync(workflowFile, WORKFLOW_YAML.trim() + '\n', 'utf8');
46
+
47
+ return {
48
+ success: true,
49
+ message: `Created GitHub Actions workflow at: ${workflowFile}`
50
+ };
51
+ } catch (err) {
52
+ return {
53
+ success: false,
54
+ message: `Failed to create GitHub Action: ${err.message}`
55
+ };
56
+ }
57
+ }
58
+
59
+ module.exports = {
60
+ setupGitHubAction,
61
+ WORKFLOW_YAML
62
+ };
63
+
package/src/cleaner.js ADDED
@@ -0,0 +1,57 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { runGit, getAllRepoFiles } = require('./utils/git');
4
+ const { checkFilename } = require('./rules/filenames');
5
+ const { colors } = require('./reporter');
6
+
7
+ /**
8
+ * Automatically finds and cleans injected malware and trojan scripts from the repository
9
+ * @param {string} [cwd]
10
+ * @returns {{ quarantined: string[], uncommitted: string[] }}
11
+ */
12
+ function cleanInfectedFiles(cwd = process.cwd()) {
13
+ const allFiles = getAllRepoFiles(cwd);
14
+ const quarantined = [];
15
+ const uncommitted = [];
16
+
17
+ const quarantineDir = path.join(cwd, '.git', 'git-safty-quarantine');
18
+
19
+ for (const file of allFiles) {
20
+ const threat = checkFilename(file);
21
+ if (threat && threat.severity === 'CRITICAL') {
22
+ const fullPath = path.resolve(cwd, file);
23
+
24
+ // Unstage from git index if staged
25
+ runGit(`reset HEAD "${file}"`, cwd);
26
+ uncommitted.push(file);
27
+
28
+ // Quarantine or delete file
29
+ if (fs.existsSync(fullPath)) {
30
+ if (!fs.existsSync(quarantineDir)) {
31
+ fs.mkdirSync(quarantineDir, { recursive: true });
32
+ }
33
+ const targetQuarantinePath = path.join(quarantineDir, `${Date.now()}_${path.basename(file)}`);
34
+ try {
35
+ fs.renameSync(fullPath, targetQuarantinePath);
36
+ quarantined.push(file);
37
+ } catch (err) {
38
+ // If rename fails, try unlink
39
+ try {
40
+ fs.unlinkSync(fullPath);
41
+ quarantined.push(file);
42
+ } catch (_) {}
43
+ }
44
+ }
45
+ }
46
+ }
47
+
48
+ return {
49
+ quarantined,
50
+ uncommitted
51
+ };
52
+ }
53
+
54
+ module.exports = {
55
+ cleanInfectedFiles
56
+ };
57
+
package/src/config.js ADDED
@@ -0,0 +1,50 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const DEFAULT_CONFIG = {
5
+ // Filenames or glob patterns to exclude from malware checks
6
+ ignoreFiles: [],
7
+ // Rule names to disable if desired
8
+ ignoreRules: [],
9
+ // Custom blacklist patterns
10
+ customSuspiciousFiles: [],
11
+ customPayloads: [],
12
+ // Strict mode: Treat warnings as errors
13
+ strict: false
14
+ };
15
+
16
+ /**
17
+ * Loads configuration from .gitsafetyrc.json or git-safty.config.json
18
+ * @param {string} [cwd]
19
+ * @returns {typeof DEFAULT_CONFIG}
20
+ */
21
+ function loadConfig(cwd = process.cwd()) {
22
+ const possiblePaths = [
23
+ path.join(cwd, '.gitsafetyrc.json'),
24
+ path.join(cwd, '.gitsafetyrc'),
25
+ path.join(cwd, 'git-safty.config.json')
26
+ ];
27
+
28
+ for (const configPath of possiblePaths) {
29
+ if (fs.existsSync(configPath)) {
30
+ try {
31
+ const raw = fs.readFileSync(configPath, 'utf8');
32
+ const parsed = JSON.parse(raw);
33
+ return {
34
+ ...DEFAULT_CONFIG,
35
+ ...parsed
36
+ };
37
+ } catch (err) {
38
+ console.warn(`[git-safty] Warning: Could not parse config file at ${configPath}: ${err.message}`);
39
+ }
40
+ }
41
+ }
42
+
43
+ return DEFAULT_CONFIG;
44
+ }
45
+
46
+ module.exports = {
47
+ loadConfig,
48
+ DEFAULT_CONFIG
49
+ };
50
+