DSH HUB
首页插件商店插件包社区排行榜资源发布指南
插件源码
返回插件目录

x1ptase /

x1ptase/dsh-security-guidance

已验证

Plugin DSH quét code/git diff tìm rủi ro bảo mật và xếp hạng file quan trọng của project để quét sâu trước.

★ 1 Stars0 Forks0 IssuesN/A 社区评分0 已确认安装
查看 GitHub
README来源: main@a424ed15
SECURITY_GUIDANCE — plugin bảo mật cho DeepSeek Harness

Rà soát nhanh rủi ro bảo mật trong code, Git diff và cả project — ngay trong DeepSeek Harness.

pattern-based · read-only · không cần API key · không có dependency

Cài đặt · Prompt mẫu · Xếp hạng file · Quét code/diff · Giới hạn

Tổng quan nhanh

Tool Dùng khi Input Đọc file?
security_guidance_scan Quét một đoạn code hoặc git diff content (+ mode) Không
security_prioritize_files Chọn ra file đáng quét nhất trong cả project root, top_n Có, chỉ đọc

[!TIP] Kết hợp cả hai: xếp hạng bằng security_prioritize_files, rồi quét sâu từng file trong top N bằng security_guidance_scan. Xem prompt mẫu.

Cài đặt

Quick start: cài plugin, gửi nội dung, đọc findings

  1. Mở DeepSeek Harness → Plugins → Add plugin.
  2. Chọn thư mục của plugin này và bật bundle @local/dsh-security-guidance.
  3. Mở một session DSH mới để agent nạp tool.

Plugin không có dependency npm, không cần API key và không có bước build. Giữ thư mục plugin ở vị trí ổn định nếu cài từ local directory; đừng tự sao chép file vào thư mục profile của DSH.

Kiểm tra: nhờ agent "gọi security_guidance_scan để quét eval(userInput) ở chế độ code". Kết quả đúng có finding code.eval mức high. Nếu agent không thấy tool: kiểm tra plugin đã bật, mở session mới (hoặc khởi động lại DSH), rồi chạy npm test.

Prompt mẫu

Dán vào chat DSH trong worktree của project. Cả ba đều chỉ đọc, không sửa file.

Quy trình quét bảo mật trong DeepSeek Harness

1. Xếp hạng file rồi quét (dùng cả hai tool):

Dùng security_prioritize_files để chọn 10 file quan trọng trong thư mục hiện tại, rồi quét từng file bằng security_guidance_scan và báo cáo theo severity. Không sửa file.

2. Chỉ quét một file:

Chỉ dùng security_guidance_scan để quét file <tên file> và báo cáo theo severity. Không sửa file.

3. Quét git diff (lấy bằng git diff --cached, hoặc git diff):

Dùng security_guidance_scan với mode: "diff" để quét git diff dưới đây và báo cáo theo severity. Không sửa file.

<dán output git diff ở đây>

security_guidance_scan nhận tối đa 200.000 ký tự mỗi lần gọi; diff dài hãy chia theo file.

security_guidance_scan

Quét code hoặc unified diff được truyền vào và trả về finding theo rule. Tool không mở file, không gọi mạng, không chạy code.

Tham số Bắt buộc Ý nghĩa
content Có Code hoặc unified diff, tối đa 200.000 ký tự.
filename Không Nhãn hiển thị (tối đa 256 ký tự); plugin không mở file này.
language Không Nhãn ngôn ngữ, ví dụ javascript.
mode Không code (mặc định) hoặc diff (chỉ quét dòng thêm vào, bỏ header +++).

Output gồm findings, summary (đếm theo critical/high/medium/low/info và total) và scanned (mode, filename/language, số dòng đã quét). Một finding:

{
  "rule_id": "code.eval",
  "severity": "high",
  "title": "Dynamic code execution",
  "message": "Dynamic code execution can execute attacker-controlled input.",
  "location": { "line": 2, "column": 1 },
  "snippet": "eval(userInput);",
  "remediation": "Avoid dynamic execution; use a safe parser or allowlist."
}
16 rule hiện có (nguồn: scanner.js)
Rule ID Severity Dấu hiệu
shell.destructive critical rm -rf, mkfs, dd if=, DROP DATABASE.
secret.hardcoded high Giá trị giống credential gán cho api_key, secret, token, password.
code.eval high eval, exec, Function.
shell.interpolation high Chuỗi lệnh shell có khả năng nội suy input.
shell.execution high exec, spawn, subprocess.run, os.system.
sql.interpolation high SQL được nối/nội suy chuỗi.
xss.html-injection high innerHTML, outerHTML, dangerouslySetInnerHTML.
path.traversal high Đường dẫn file có thể bị input không tin cậy ảnh hưởng.
crypto.weak-hash medium Hash yếu: md5, sha1 (hashlib, createHash, MessageDigest).
random.insecure medium Math.random, random.randint... dùng cho token, secret, session, nonce.
tls.verification-disabled medium Tắt kiểm tra chứng chỉ: verify=False, rejectUnauthorized: false, InsecureSkipVerify: true.
cors.wildcard medium CORS cho mọi origin (*).
cookie.insecure-flags low Cookie đặt httpOnly/secure bằng false.
todo.security low TODO/FIXME/HACK liên quan đến bảo mật.
debug.enabled info debug = True.
log.sensitive info Câu lệnh log có chứa password, secret, token, api_key.

Mức độ: critical (phá hủy dữ liệu), high (dễ thành lỗ hổng khi input bị kiểm soát), medium (rủi ro tùy ngữ cảnh), low (nên theo dõi), info (tham khảo). Ưu tiên xử lý từ critical xuống.

security_prioritize_files

Với project lớn, không cần quét mọi file. Tool chấm điểm từng file theo mức độ nhạy cảm và trả về top N để bạn chỉ quét sâu những file quan trọng. Tool chỉ đọc file trong root: không ghi, không sửa, không chạy code của project. Như tool trên, nó chỉ dùng được trong giao diện DSH (không có CLI độc lập).

Tham số Bắt buộc Mặc định Ý nghĩa
root Có — Thư mục project. Mọi file phải nằm trong root sau khi resolve().
top_n Không 20 Số file trả về (1–500).
languages Không tự phát hiện theo đuôi file Ví dụ ["python"]; chấp nhận alias như typescript, kotlin.
extensions Không đuôi file của các profile Ghi đè đuôi file cần xét, ví dụ [".py", ".go"].

Ngôn ngữ hỗ trợ

Ngôn ngữ Đuôi file Tool tầng 4
Python .py bandit
JavaScript / TypeScript .js .jsx .ts .tsx .mjs semgrep
Java / Kotlin .java .kt semgrep
Go .go gosec
PHP .php semgrep
Ruby .rb brakeman
C# .cs semgrep
Shell .sh shellcheck

File có đuôi không thuộc profile nào không gây lỗi; chỉ được đếm trong summary.unknown_extensions.

4 tầng chấm điểm

Quy trình 4 tầng của security_prioritize_files

  1. Đường dẫn: cộng điểm nếu tên file/thư mục chứa auth, token, payment, admin, config, api... Bỏ qua tests/, node_modules/, venv/, vendor/, dist/, *_test.*, *.spec.*, *.min.js... Chỉnh trọng số ở PATH_WEIGHTS đầu prioritize.js.
  2. Nội dung: sensitive_patterns của profile, mỗi pattern có weight và max_points để file lặp nhiều lần không lấn át. Bỏ qua dòng chú thích và file lớn hơn 1 MB.
  3. Điểm vào request: entrypoint_patterns (route, controller, handler), điểm cao vì là nơi dữ liệu người dùng đi vào. Lý do ghi dạng entrypoint:<pattern>.
  4. Tool ngoài: plugin không tự phân tích luồng dữ liệu. Nếu tool của ngôn ngữ có trong PATH, nó chạy một lần trên root (tham số dạng list, không dùng shell, timeout 60 giây) và cộng điểm theo severity.

Trọng số tầng 2 và 3 nằm trong từng profile ở profiles.js.

[!NOTE] Tầng 4 phụ thuộc tool ngoài mà plugin không cài giúp bạn. Tool không có thì bỏ qua tầng này và ghi <tool>: unavailable vào summary.unavailable; tool lỗi, quá thời gian hoặc trả JSON không đọc được thì ghi <tool>: failed (...). Tool trả kết quả từ tầng 1–3 trong mọi trường hợp. semgrep --config auto có thể tải rule qua mạng; đổi command trong profile nếu không muốn.

Ví dụ output

Kết quả thật trên thư mục mẫu Python, JavaScript và Go (có thêm tests/, node_modules/ và một file .xyz; chưa cài bandit, semgrep, gosec):

Ví dụ kết quả xếp hạng

JSON của cùng thư mục với top_n: 3
{
  "files": [
    {
      "path": "app/auth.py",
      "language": "python",
      "score": 38,
      "reasons": [
        "path:auth",
        "content:subprocess x3",
        "content:os.system"
      ]
    },
    {
      "path": "src/auth.js",
      "language": "javascript",
      "score": 34,
      "reasons": [
        "path:auth",
        "content:child_process",
        "content:execSync x2"
      ]
    },
    {
      "path": "cmd/auth.go",
      "language": "go",
      "score": 26,
      "reasons": [
        "path:auth",
        "content:exec.Command",
        "content:os/exec"
      ]
    }
  ],
  "summary": {
    "root_scanned": true,
    "languages_detected": {
      "python": 2,
      "go": 1,
      "javascript": 2
    },
    "files_considered": 5,
    "files_scored": 5,
    "skipped": {
      "ignored": 0,
      "ignored_dirs": 2,
      "too_large": 0,
      "unreadable": 0,
      "symlink_outside_root": 0,
      "excluded_by_filter": 0,
      "unknown_extension": 1
    },
    "unknown_extensions": {
      ".xyz": 1
    },
    "unavailable": [
      "bandit: unavailable",
      "semgrep: unavailable",
      "gosec: unavailable"
    ],
    "errors": [],
    "truncated": false
  }
}

reasons cho biết điểm đến từ đâu: path:*, content:*, entrypoint:*, tool:*. Chỉ file có score > 0 được xếp hạng.

Thêm ngôn ngữ mới

Thêm một object vào PROFILES trong profiles.js; không cần sửa logic chấm điểm. Ví dụ Rust (đã có test cho một profile .rs thuần dữ liệu, xem tests/prioritize.test.js):

{
  name: 'rust',
  aliases: ['rs'],                       // tùy chọn: tên khác dùng cho tham số languages
  extensions: ['.rs'],
  comment_prefixes: ['//'],
  ignore_dirs: ['target'],
  ignore_globs: ['*_generated.rs'],
  sensitive_patterns: [                  // pattern là chuỗi regex; label tùy chọn (mặc định = pattern)
    { pattern: 'Command::new', weight: 8, max_points: 16 },
    { pattern: '\\bunsafe\\b', weight: 4, max_points: 8, label: 'unsafe' }
  ],
  entrypoint_patterns: [                 // path_regex tùy chọn: chỉ áp dụng cho đường dẫn khớp
    { pattern: '#\\[(?:get|post)\\(', weight: 12, label: '#[get/post]' }
  ],
  external_tool: {                       // tùy chọn; bỏ trường này nếu không có tool
    name: 'cargo-audit',
    command: ['cargo-audit', 'audit', '--json'],   // {root} và {files} được thay thế
    ok_exit_codes: [0],
    results_path: 'items',               // đường dẫn (dấu chấm) tới mảng issue trong JSON; '' = chính JSON
    file_field: 'file',
    severity_field: 'severity',
    severity_points: { HIGH: 12, MEDIUM: 6 },
    max_points: 20
  }
}

Hạn chế

  • Dựa trên heuristic và regex nên có thể bỏ sót hoặc báo nhầm (ví dụ auth khớp cả author).
  • Không kiểm dependency/CVE hay cấu hình triển khai (Docker, CI, hạ tầng).
  • Chất lượng phụ thuộc độ đầy đủ của profile từng ngôn ngữ; ngôn ngữ chưa có profile không được xếp hạng.
  • Tầng 4 phụ thuộc tool ngoài (xem ghi chú ở trên).
  • Không đi theo symlink ra ngoài root hay thư mục symlink; bỏ qua file lớn hơn 1 MB hoặc không phải UTF-8 (ghi vào summary.skipped và summary.errors).

Phát triển

npm test

Test dùng Node.js built-in test runner, không cần cài package. Bộ test bao phủ đăng ký tool, các rule, chế độ diff, và security_prioritize_files (4 tầng, thư mục đa ngôn ngữ, symlink ra ngoài root, tool ngoài không có, profile tùy biến). Sau khi sửa source, chạy npm test rồi khởi động lại DSH để Host nạp lại module.

Giới hạn và lưu ý bảo mật

  • Đây là công cụ dựa trên pattern/regex, không phải SAST và không thay thế security review. Có finding không chứng minh có lỗ hổng; không có finding không chứng minh code an toàn.
  • security_guidance_scan chỉ xử lý content: không mở file theo filename, không gọi mạng, không chạy code.
  • security_prioritize_files chỉ đọc file trong root; chỉ tầng 4 mới chạy tool ngoài.
  • Snippet che chuỗi trong dấu nháy, nhưng đừng dán secret thật vào chat nếu không cần.

Giấy phép

MIT © 2026 x1ptase

Gỡ plugin

Vào Plugins trong DSH, tìm Security guidance (@local/dsh-security-guidance) rồi Remove, hoặc dùng nút disable để tắt tạm.

Tài liệu liên quan

DETAIL.md · LICENSE · SECURITY-CONTRACT.md · package.json · index.js · scanner.js · profiles.js · prioritize.js


Trạng thái: source đã có test cục bộ; cần cài vào một profile DSH và gọi tool thực tế để xác nhận runtime integration.

—/ 5

暂无评分

已验证 DSH bundle

Commit a424ed155a93

社区评论

还没有评论,来写第一条。

DSH HUB

社区维护的 DSH 插件索引。不是 GitHub 或 DeepSeek AI 的官方产品。

社区资源API关于