Zero-dependency CLI that audits text, source code, and domains for Unicode homoglyphs, invisible and bidi characters, and Trojan Source attacks, with JSON reports and CI exit-code gating.
Unicode 同形字與不可見字元安全稽核引擎
輕量級、零依賴、純標準函式庫的命令列工具:偵測 Unicode 同形字(homoglyph)釣魚、不可見/格式字元,以及 Trojan Source 雙向文字攻擊(CVE-2021-42574)。
現代文字早已不限於 ASCII。攻擊者可利用 Unicode 同形字 讓 аррle.com 看起來像 apple.com,利用 零寬字元 在原始碼中藏匿惡意邏輯,或利用 雙向控制字元(Trojan Source,CVE-2021-42574)顛倒註解與程式碼的視覺順序。這些字元在編輯器裡「看不見」,卻能繞過人工 Code Review。
GlyphGuard 是一款面向開發者的安全稽核引擎,能在本地、離線、零依賴的條件下,對文字、原始碼與網域進行系統化的 Unicode 安全體檢:
аррle → apple.pyz,透過 zipapp 零依賴建置)靈感來源:Unicode Technical Report #36 / #39、Trojan Source 研究,以及 codebox/homoglyph 等社群實踐。與帳號內既有的安全工具(RepoShield、VulnScan、MCPShield、PromptShield)領域完全不同,相似度 < 10%。
unicodedata / argparse / json),無 pip install 負擔,可在任意離線環境執行。audit 指令回傳結構化退出碼,可直接接入 GitHub Actions / GitLab CI 作為合併門禁。.pyz 單檔可執行程式。1. 單檔可執行程式(推薦,零安裝)
從 Releases 下載對應平台的 glyphguard-<os>.pyz,直接執行:
python glyphguard-<os>.pyz audit ./src --recursive
2. 原始碼執行
git clone https://github.com/gitstq/GlyphGuard.git
cd GlyphGuard
python -m glyphguard audit ./src --recursive
3. 可編輯安裝
pip install -e .
glyphguard audit ./src --recursive
| 指令 | 作用 |
|---|---|
audit PATH... | 稽核檔案/目錄中的 Unicode 風險 |
skeleton TEXT | 將文字映射為 ASCII 骨架 |
invisibles TEXT | 列出不可見/控制字元 |
normalize TEXT | Unicode 規範化或清洗 |
escape TEXT | 跳脫非 ASCII/控制字元 |
unescape TEXT | 反跳脫 |
width TEXT | 計算終端機顯示寬度 |
inspect TEXT | 逐字元 Unicode 內省 |
domain NAME | 網域同形字稽核 |
# 遞迴稽核目錄
glyphguard audit ./src --recursive
# CI 門禁:遇到 critical 即非零退出
glyphguard audit ./src -r --fail-on critical
echo $? # 0=乾淨, 1=warning, 2=critical
# 同形字骨架
glyphguard skeleton "аррle" # apple
# 網域稽核
glyphguard domain "аррle.com" # Looks like (ASCII): apple.com
安全工具往往需要在受限/離線環境(CI Runner、稽核沙箱)中執行。引入第三方依賴會帶來供應鏈風險與安裝負擔。GlyphGuard 堅持零依賴,僅依賴 unicodedata(Python 內建的 Unicode 資料庫),因而可在任何安裝了 Python 的機器上即開即用。
data.py):手工精選、確鑿無誤的對應(西里爾/希臘/亞美尼亞等腳本與 ASCII 的視覺等價),並輔以演算法化區間(全角、數學字母、帶圈字母),避免誤報。.glyphguard.toml 自訂白名單與閾值python -m compileall -q glyphguard
python - <<'PY'
import shutil, zipapp
shutil.copytree("glyphguard", "stage/glyphguard")
zipapp.create_archive("stage", "dist/glyphguard.pyz",
main="glyphguard.cli:main",
interpreter="/usr/bin/env python3")
PY
python dist/glyphguard.pyz version
倉庫已內建兩條工作流:
.github/workflows/ci.yml:在 Windows / macOS / Linux × Python 3.9–3.13 上做語法校驗與 unittest 測試(僅標準函式庫)。.github/workflows/release.yml:推送 v* 標籤時,使用 zipapp 在三大平台建置 .pyz,並自動建立 GitHub Release 與附件。git tag v1.0.0
git push origin v1.0.0 # 自動觸發建置與發佈
📥 下載入口:GitHub Releases v1.0.0
歡迎貢獻!請閱讀 CONTRIBUTING.md:
feat: / fix: / docs: …)本專案基於 MIT License 開源。
Made with 🔥 by gitstq