Skip to content

Commit 719ea36

Browse files
Update Malware guard to v6 (local check + cloud scan)
1 parent 83fea1b commit 719ea36

7 files changed

Lines changed: 1653 additions & 274 deletions

File tree

‎.github/MALWARE-GUARD.md‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# 🛡️ Malware guard v6
2+
3+
This repository is protected by the **Malware guard**. It was added after a real attack (the
4+
"PolinRider" malware) spread through our repos, and it is built for AI-assisted ("vibe") coding,
5+
where an AI tool, a poisoned project or an infected PC can quietly add dangerous code.
6+
7+
One engine - `.github/malware-guard/guard.py` - does all the checking, in three places:
8+
9+
| Layer | Where it runs | When |
10+
|---|---|---|
11+
| **1. Local check** | your PC | whenever you run it (commands below) |
12+
| **2. Automatic commit/push check** | your PC | every `git commit` and `git push`, in every repo (after a one-time `install`) |
13+
| **3. Cloud scan** | GitHub's servers | every push and fork pull request, plus every Monday for the whole history |
14+
15+
Layers 1-2 stop problems **before** they leave your PC. Layer 3 catches anything that reached GitHub
16+
from any computer - for example a teammate's infected PC - **before** you pull it.
17+
18+
---
19+
20+
## 1. Local check - run it any time
21+
22+
Checks **every file in the project on your disk** - including untracked files and files hidden by
23+
`.gitignore` (the worm hides its files there) - plus `.env` safety and your PC itself.
24+
25+
| Your system | Command (run from the project folder) |
26+
|---|---|
27+
| Windows (easiest) | double-click `.github\malware-guard\check.cmd` |
28+
| Windows PowerShell | `.github\malware-guard\check.cmd` |
29+
| macOS / Linux / Git Bash | `sh .github/malware-guard/check.sh` |
30+
| Node.js projects | `npm run security:check` (add it once: `python .github/malware-guard/guard.py add-npm-script`) |
31+
| Any system | `python .github/malware-guard/guard.py check` |
32+
33+
Options (same for every command, e.g. `check.cmd -Fix` or `check.sh --fix`):
34+
35+
| Option | What it does |
36+
|---|---|
37+
| `--fix` / `-Fix` | moves malware files to quarantine, cuts malware lines out of normal files, protects `.env` files. Nothing is deleted - every change keeps a copy in `~/.code-guard/quarantine/` |
38+
| `--root <folder>` / `-Root <folder>` | checks **every project** in a folder, e.g. `C:\Users\you\Documents\Office_Projects` |
39+
| `--deep` | also checks `node_modules`, `build`, `venv`... (slower) |
40+
| `--offline` | skips the online package-name check |
41+
42+
What the local check looks at:
43+
44+
- **Your project files** - all the checks listed in "What it detects" below.
45+
- **Your `.env` files** - is each real `.env` protected by `.gitignore`? Was one committed by mistake?
46+
- **Your PC** - is malware **running right now** (e.g. `node` started on a font file)? Are automatic
47+
tasks switched off in VS Code / Cursor / Antigravity? Is the automatic commit/push check on?
48+
49+
Python 3.8 or newer is needed (https://www.python.org/downloads/ - tick "Add to PATH"). Nothing to install with pip.
50+
51+
## 2. Automatic check on every commit and push (once per PC)
52+
53+
```
54+
python .github/malware-guard/guard.py install # all git repos on this PC, every commit + push
55+
python .github/malware-guard/guard.py harden # VS Code / Cursor / Antigravity: automatic tasks OFF, Workspace Trust ON
56+
```
57+
58+
When something dangerous is committed, the commit stops, the dangerous files are taken out of the
59+
commit (your other changes stay), malware files go to quarantine, and you get a plain explanation.
60+
A normal commit takes about a tenth of a second. Pushes are checked too - including commits made
61+
with `--no-verify`. Remove it any time with `guard.py uninstall`.
62+
63+
## 3. Cloud scan (automatic, nothing to do)
64+
65+
`.github/workflows/malware-guard.yml` runs on GitHub after every push. It first verifies that the
66+
guard engine has not been modified, then checks the code **and every commit in the push** - so
67+
malware hidden inside a merge commit, or added and then "removed", is still caught. It has read-only
68+
access, never changes your code and never blocks a push. Every Monday it re-checks the whole history.
69+
70+
If it finds something: the commit gets a **red ❌** and a **"🚨 Malware guard alert"** issue is opened
71+
(everyone watching the repo gets an email). Warnings (⚠️) never turn the run red.
72+
73+
---
74+
75+
## What it detects
76+
77+
| Category | Examples |
78+
|---|---|
79+
| **Malware** | fake fonts/images that are really scripts, `dist/setup.js` droppers, worm files (`temp_auto_push.bat`), VS Code auto-run tasks (`runOn: folderOpen`, `allowAutomaticTasks`), `.gitignore` hiding worm files, loaders injected into `postcss/tailwind/vite` configs, `eval(atob(...))` and other encoded code, base64 strings that decode to code, reverse shells, crypto miners, browser-password and crypto-wallet stealers, code sending all your environment secrets away, code hidden off-screen, malware running on your PC |
80+
| **Viruses** | programs disguised as other files (`MZ` inside a `.png`), `invoice.pdf.exe` double extensions, risky Windows script types, archives with disguised programs, Office macros, the EICAR test file |
81+
| **Phishing** | `https://github.com@evil.site`, look-alike domains (`g00gle.com`), brand + "login/verify" domains (`paypal-account-verify.com`), fake login pages on free hosting (`github-login.vercel.app`), look-alike international domains, login forms that post passwords to other sites, cookie theft |
82+
| **AI attacks** | invisible hidden text ("Rules File Backdoor") and dangerous hidden instructions in `.cursorrules`, `AGENTS.md`, `CLAUDE.md`, `copilot-instructions.md`, `.agents/`; risky AI tool (MCP) configs |
83+
| **Supply chain** | packages an AI invented that don't exist (checked live on npm / PyPI), typo-named packages, known malicious packages, install scripts that download code, unusual package servers |
84+
| **Secrets** | GitHub, AWS, Google/Firebase, OpenAI, Anthropic, Stripe, Slack, npm, PyPI, Telegram keys, private keys, database URLs and connection strings with passwords, real `.env` files |
85+
| **Hidden text** | text-direction tricks (Trojan Source), invisible zero-width characters, look-alike letters in names - Sinhala and emoji joiners are allowed |
86+
87+
Tested on 37 attack/safe samples and on 7,030 files of six large open-source projects with **no false blocks**.
88+
89+
## If you see a red ❌, an alert issue, or a stopped commit
90+
91+
1. **Don't pull that branch and don't open the project in VS Code / Cursor** until it is clean.
92+
This malware runs the moment an infected folder is opened.
93+
2. Read which file, which commit and why (in the run summary, the issue, or your terminal).
94+
3. On a **clean** PC run the local check with fix: `check.cmd -Fix` / `sh check.sh --fix`, then commit and push.
95+
4. Whoever pushed it should treat their PC as infected: disconnect it, run a full and an offline
96+
Microsoft Defender scan, and secure the GitHub account from another device:
97+
`python .github/malware-guard/guard.py protect` opens every page you need.
98+
5. Leaked key or password? Change / revoke it now - bots scan GitHub for keys within minutes.
99+
6. False alarm? See below, then comment on the issue and close it.
100+
101+
## False alarms
102+
103+
- One line: add the text `codeguard:allow` in a comment on that line.
104+
- A file or a rule: create `.codeguard.json` in the repo root:
105+
106+
```json
107+
{ "allow": [ { "path": "tests/certs/*", "rule": "private-key" } ],
108+
"disable": ["url-ip"] }
109+
```
110+
111+
- Once, in an emergency: `CODE_GUARD_SKIP=1 git commit ...` (the push check and the cloud scan still run).
112+
113+
## Keep yourself safe (1 minute, once per PC)
114+
115+
- Run `guard.py harden` - or in VS Code set **Task: Allow Automatic Tasks** = `off` and keep **Workspace Trust** on.
116+
- Click **"No, I don't trust the authors"** for projects from anyone you don't know.
117+
- Never open "coding tests" or projects from strangers or recruiters on your work PC.
118+
- Never `npm install` / `pip install` a package an AI suggested before checking it is real.
119+
120+
## Files
121+
122+
| File | Purpose |
123+
|---|---|
124+
| `.github/malware-guard/guard.py` | the engine (local check, commit/push check, cloud scan) |
125+
| `.github/malware-guard/check.cmd`, `check.ps1` | Windows local check |
126+
| `.github/malware-guard/check.sh` | macOS / Linux / Git Bash local check |
127+
| `.github/malware-guard/run.cjs` | launcher for `npm run security:check` |
128+
| `.github/workflows/malware-guard.yml` | the cloud scan |
129+
| `.github/MALWARE-GUARD.md` | this guide |
130+
131+
Please don't edit these files by hand - the cloud scan verifies the engine and reports any change.

‎.github/malware-guard/check.cmd‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@echo off
2+
rem Malware guard - local check. Double-click, or run: .github\malware-guard\check.cmd [-Fix] [-Root <folder>]
3+
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0check.ps1" %*
4+
set RC=%ERRORLEVEL%
5+
if "%~1"=="" pause
6+
exit /b %RC%

‎.github/malware-guard/check.ps1‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Malware guard - local check (Windows PowerShell)
2+
# .\.github\malware-guard\check.ps1 check this project + this PC
3+
# .\.github\malware-guard\check.ps1 -Fix ...and quarantine malware / protect .env files
4+
# .\.github\malware-guard\check.ps1 -Root C:\Users\me\Documents\Office_Projects check every project in a folder
5+
param([switch]$Fix, [string]$Root, [switch]$Deep, [switch]$Offline, [switch]$NoPC)
6+
$guard = Join-Path $PSScriptRoot 'guard.py'
7+
$candidates = @(@{ exe = 'py'; pre = @('-3') }, @{ exe = 'python'; pre = @() }, @{ exe = 'python3'; pre = @() })
8+
$py = $null
9+
foreach ($c in $candidates) {
10+
if (-not (Get-Command $c.exe -ErrorAction SilentlyContinue)) { continue }
11+
& $c.exe @($c.pre) -c "import sys; sys.exit(0 if sys.version_info >= (3, 8) else 1)" 2>$null
12+
if ($LASTEXITCODE -eq 0) { $py = $c; break }
13+
}
14+
if (-not $py) {
15+
Write-Host "Malware guard needs Python 3.8+ - install it from https://www.python.org/downloads/ (tick 'Add to PATH')." -ForegroundColor Red
16+
exit 2
17+
}
18+
$argsOut = @('check')
19+
if ($Fix) { $argsOut += '--fix' }
20+
if ($Deep) { $argsOut += '--deep' }
21+
if ($Offline) { $argsOut += '--offline' }
22+
if ($NoPC) { $argsOut += '--no-pc' }
23+
if ($Root) { $argsOut += @('--root', $Root) }
24+
& $py.exe @($py.pre) $guard @argsOut
25+
exit $LASTEXITCODE

‎.github/malware-guard/check.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
# Malware guard - local check (macOS / Linux / Git Bash)
3+
# sh .github/malware-guard/check.sh check this project + this PC
4+
# sh .github/malware-guard/check.sh --fix ...and quarantine malware / protect .env files
5+
# sh .github/malware-guard/check.sh --root ~/projects check every project in a folder
6+
DIR="$(cd "$(dirname "$0")" && pwd)"
7+
for PY in python3 python; do
8+
if command -v "$PY" >/dev/null 2>&1 && "$PY" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 8) else 1)' 2>/dev/null; then
9+
exec "$PY" "$DIR/guard.py" check "$@"
10+
fi
11+
done
12+
echo "Malware guard needs Python 3.8+ (https://www.python.org/downloads/)" >&2
13+
exit 2

0 commit comments

Comments
 (0)