DeepSHPlugins
dsh-security-guard 專案預覽
GITHUB / COMMUNITY PROJECT

dsh-security-guard

安全與運維TypeScriptMIT

dsh 安全守衛外掛:基於規則的靜態掃描覆蓋惡意程式碼、提示詞注入與令牌浪費,執行時攔截危險工具呼叫,提供 /scan 命令、plugin_scan 工具、Web 面板與白名單。

1 Starsbigclawd 更新時間 2026-08-16
訪問 GitHub 倉庫
dsh-security-guard 專案預覽

專案介紹

中文

dsh 安全守衛外掛:基於規則的靜態掃描覆蓋惡意程式碼、提示詞注入與令牌浪費,執行時攔截危險工具呼叫,提供 /scan 命令、plugin_scan 工具、Web 面板與白名單。

English

Static and runtime security guard for dsh: rule-based scans for malicious code, prompt injection and token waste, runtime interception of dangerous tool calls, /scan command, plugin_scan tool, web panel, and allowlist.

專案資訊與收錄訊號

快照 2026-09-11
作者 / 組織
bigclawd
倉庫
bigclawd/dsh-security-guard
GitHub Stars
1
Forks
0
開發語言
TypeScript
許可證
MIT
最近推送
2026-08-16
Manifest
資料中檢測到宣告

公開倉庫不自動等於可商用;許可證與當前相容性以原專案文件為準。Manifest 和資料評分不構成安裝安全認證。

資料評分

52/ 100
維護活躍
82
文件與實用資訊
85
生態關注度
9
安裝便捷訊號
100
專案宣告訊號
100

README 含完整安裝與使用說明;關注度尚低(1);標準命令一鍵安裝。

評分來自已有資料快照的五維模型,僅作瀏覽參考,不是實際使用評測或安全檢測結論。

安裝與使用

所有專案資料與許可均以對應 GitHub 倉庫為準。

dsh plugin --profile web add dsh-security-guard

複製命令不會自動執行。請先閱讀倉庫文件,確認環境要求與許可證。

專案截圖

倉庫 README

GitHub 原文

已儲存的倉庫文件快照;文件抓取時間未記錄,可能與上方目錄介紹處於不同版本。安裝前請核對當前倉庫說明。

儲存庫檔案保留原文,指令與授權文字不作自動改寫。

🛡️ dsh-security-guard

English | 中文

A security guard for the DeepSeek Harness (dsh).
Static scanning and runtime interception that never executes the code it protects you from.

Static Analysis Runtime Language Tests License dsh


✨ Highlights

🔍 Static scanRule-based analysis of source files — ts.createSourceFile only, scanned code is never imported or executed
👁️ Runtime watchIntercepts dangerous tool calls, prompt steps and file operations before they happen
📊 VerdictsEvery finding classified `block \warn \clean`, written to JSON or human-readable reports
🧩 Extensible rulesPlain auditable JSON rules, overridable per id, no opaque signatures
🪝 Install hookAuto-scans every freshly installed plugin (profile-manifest watcher)
🖥️ Surfaces/scan command, plugin_scan tool, live web panel, user-managed allowlist

🎯 Threat model

ClassExamplesDefault severity
🧨 Malicious codeeval / new Function, child_process, require("node:..."), postinstall hooks, process.env exfiltration, hidden base64/hex payloads, computed access on globalsblock
💉 Context injection"ignore previous instructions" / 忽略之前的指令 prompt-override phrases, unvetted URL hostsblock / warn
⏳ Token wasteoversized files, base64-dominant blobs, repeated words/characters, filler commentswarn
🔐 Sensitive paths~/.ssh, .env, credential stores touched by codewarn

🔍 Detector families

  • AST pass (src/static/ast.ts) — parses TS/JS with the TypeScript compiler

API (ts.createSourceFile), walks the tree, matches rule patterns (ast-call, ast-member, ast-computed, ast-import). Text is never executed.

  • Content pass (src/static/content.ts) — regex / phrase / url / file rules

over text, code strings, image alt attributes and markdown.

  • Token pass — size, base64 ratio, repetition and comment-padding heuristics

(src/static/content.ts heuristics, src/rules/token.json tuning).

  • Runtime watch (src/runtime/watcher.ts) — pre-step / pre-tool / post-tool

gates, shell-pipe and destructive-shell patterns, SSH-write and token-drain telemetry, session usage monitoring.

  • Whitelist (src/whitelist.ts) — user-managed allowlist persisted to disk;

trust / untrust via CLI or panel.

📦 Rules

Rules are plain JSON bundled under src/rules/ — code.json, injection.json, token.json, allowlist.json. A rulesDir option overrides or extends them by id. The full schema lives in src/rules.ts.

{ "id": "code.eval", "kind": "ast-call", "severity": "block", "callee": ["eval"] }

Matcher kinds: ast-call (calls/new), ast-member (dotted access), ast-computed (computed access on globals — obfuscation signal), ast-import (imports/requires), regex (scoped to all/string/comment), phrase, url, file. Beyond the classic malicious patterns, the bundled rules harden against obfuscation: hex/base64 Buffer.from/toString encodings, long hex-only string payloads, and computed member access on globalThis/global/process are all flagged. The full schema lives in src/rules.ts.

🚀 Usage

Install

dsh plugin --profile default add dsh-security-guard

Host application

import { Context } from '@deepseek-ai/cordis'
import Guard from 'dsh-security-guard'

ctx.plugin(Guard, {
  rulesDir: 'config/guard-rules',          // optional overrides
  scan: { maxFiles: 5000, maxFileSize: 4 * 1024 * 1024, skipSegments: ['node_modules', '.git', 'dist', 'lib'] },
  runtime: { enabled: true, blockOnSeverity: ['block'], maxFindingsPerScan: 200 },
  allowlist: { file: 'data/guard-allowlist.json' },
  web: { enabled: true, path: '/scan' },
  installHook: { enabled: true, intervalMs: 5000 },  // auto-scan newly installed plugins
})

Install hook

The host emits no "package installed" event (dsh plugin add is a separate CLI process), so the guard watches the profile manifest ($DSH_HOME/profiles/<name>/package.json — the only file the CLI rewrites after a successful install). Every package added to its dependencies is statically scanned under node_modules; the report is recorded as a runtime event (source: install), emitted as a guard/install-scan event, and appended to guard-install-scans.jsonl in the profile directory. Disable with installHook: { enabled: false }.

Static scan

/scan ./plugin-dir                 # human-readable report
/scan ./plugin-dir --json          # machine-readable
/scan ./plugin-dir --json --out report.json

Or via the plugin_scan tool with parameters target, severity, json, out.

👁️ Runtime watch

Enabled by default. The guard listens on:

EventAction
agent/pre-stepRejects steps matching injection.* or token-drain patterns
tools/*Denies exec/spawn of destructive commands; asks on shell pipelines writing to ~/.ssh or the token cache; blocks write/edit outside workspaceRoots
fs/*Observes read/edit of sensitive paths (~/.ssh, .env, …)
session/eventTracks assistant/message token usage, warns on suspicious consumption

🖥️ Web panel

Served by the harness web server at the configured path (default /scan): live findings, rule overview, allowlist management (trust / untrust), report download.

🧪 Development

pnpm install
pnpm typecheck   # tsc --noEmit
pnpm test        # vitest run (89 tests: static, rules, runtime, whitelist, plugin)
pnpm build       # tsc emit + copy bundled rules into lib/

The test suite runs three fixture families under tests/fixtures/ — clean/, injected/, malicious/ — plus samples/malicious-demo, a deliberately malicious sample plugin that the scanner never executes (scan it with /scan samples/malicious-demo to see it reported).

🔒 Design constraints

  • The scanner is purely static: only ts.createSourceFile / ts.createScanner

are used; scanned source is never imported, evaluated or executed.

  • No unvetted AI-signature or hashing mechanisms; verdicts come from auditable,

id-overridable JSON rules.

  • Runtime gate decisions use the host's native PreToolDecision /

PostToolDecision / PreStepDecision contracts.

⚠️ Known limits

  • Obfuscation is an arms race. Rule patterns reliably catch naive malware,

copy-paste samples, and — most importantly — install-time lifecycle scripts in package.json (unhideable: npm requires the literal key). But a determined attacker can still hide payloads behind runtime decoding or encryption. The scanner is a risk-reduction layer, not a security proof.

  • False positives exist. Legitimate code can trip heuristic rules (e.g. a

hex hash constant); verdicts default to warn, and the allowlist and ruleSeverity overrides handle the rest.

  • Scan before install. A malicious postinstall runs the moment the

package is installed — scan the package first (/scan), then dsh plugin add.

📄 License

MIT

使用前核對

安裝步驟、相容版本與授權範圍以原專案當前文件為準。Stars 和評分是快照中的導航訊號。

安裝與排錯 · 專案問題反饋

同類專案