skills/dev-vulnerability-patterns/SKILL.md
程式碼漏洞模式資料庫。提供 Python/JS/Java/Go 語言特定的漏洞程式碼模式、CWE 分類、安全替代方案與嚴重度評估標準。適用於「漏洞模式」、「CWE」、「SQL Injection」、「XSS」、「安全漏洞」、「安全編碼」、「漏洞程式碼」等安全性審查任務。強化 security-analyst 的分析能力。注意:滲透測試執行與 WAF 設定不在此技能範圍內。
npx skillsauth add vincent119/ai-rules-kit dev-vulnerability-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
security-analyst 在安全性審查時使用的漏洞程式碼模式、CWE 分類與安全替代方案參考。
dev-code-reviewer 技能使用| CWE | 名稱 | 嚴重度 | 頻率 | |-----|------|--------|------| | CWE-89 | SQL Injection | Critical | 高 | | CWE-78 | OS Command Injection | Critical | 中 | | CWE-798 | Hardcoded Credentials | Critical | 高 | | CWE-862 | Missing Authorization | Critical | 高 | | CWE-306 | Missing Authentication | Critical | 中 | | CWE-502 | Insecure Deserialization | Critical | 中 | | CWE-79 | XSS (Cross-Site Scripting) | High | 極高 | | CWE-22 | Path Traversal | High | 中 | | CWE-352 | CSRF | High | 高 | | CWE-918 | SSRF | High | 中 |
# 漏洞
query = f"SELECT * FROM users WHERE name = '{user_input}'"
cursor.execute(query)
# 安全
cursor.execute("SELECT * FROM users WHERE name = %s", (user_input,))
# 或使用 ORM(SQLAlchemy、Django ORM)
# 漏洞
os.system(f"ping {user_input}")
subprocess.call(f"ls {user_input}", shell=True)
# 安全
subprocess.run(["ping", user_input], shell=False)
# 漏洞
file_path = os.path.join(BASE_DIR, user_input)
open(file_path).read()
# 安全
file_path = os.path.realpath(os.path.join(BASE_DIR, user_input))
if not file_path.startswith(os.path.realpath(BASE_DIR)):
raise ValueError("Invalid path")
# 漏洞
data = yaml.load(user_input) # 可能執行任意程式碼
# 安全
data = yaml.safe_load(user_input)
// 漏洞(React)
<div dangerouslySetInnerHTML={{ __html: userInput }} />
// 安全
<div>{userInput}</div> // React 自動跳脫
// 必要時使用 DOMPurify
import DOMPurify from 'dompurify';
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(userInput) }} />
// 漏洞
function merge(target, source) {
for (let key in source) {
target[key] = source[key]; // __proto__ 污染
}
}
// 安全
function merge(target, source) {
for (let key of Object.keys(source)) {
if (key === '__proto__' || key === 'constructor') continue;
target[key] = source[key];
}
}
// 漏洞(災難性回溯)
const regex = /^(a+)+$/;
regex.test("aaaaaaaaaaaaaaaaaaaab"); // 指數時間
// 安全:移除巢狀重複
const regex = /^a+$/;
// 漏洞
eval(userInput);
new Function(userInput)();
// 安全:永遠不使用 eval,改用替代邏輯
// 漏洞
String query = "SELECT * FROM users WHERE id = " + userId;
stmt.executeQuery(query);
// 安全
PreparedStatement ps = conn.prepareStatement(
"SELECT * FROM users WHERE id = ?"
);
ps.setInt(1, userId);
ps.executeQuery();
// 漏洞
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
db.parse(userInput);
// 安全
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
// 漏洞
ObjectInputStream ois = new ObjectInputStream(userInputStream);
Object obj = ois.readObject(); // 可能執行任意程式碼
// 安全:使用 JSON/XML 序列化(Jackson、Gson)
// 或使用 ObjectInputFilter(Java 9+)
// 漏洞
query := fmt.Sprintf("SELECT * FROM users WHERE name = '%s'", userInput)
db.Query(query)
// 安全
db.Query("SELECT * FROM users WHERE name = $1", userInput)
// 漏洞
http.ServeFile(w, r, filepath.Join(baseDir, r.URL.Path))
// 安全
cleanPath := filepath.Clean(r.URL.Path)
fullPath := filepath.Join(baseDir, cleanPath)
if !strings.HasPrefix(fullPath, baseDir) {
http.Error(w, "Forbidden", 403)
return
}
| 因素 | 權重 | 評估標準 | |------|------|---------| | 攻擊向量 | 高 | 網路(遠端)> 本地 | | 攻擊複雜度 | 高 | 低複雜度 > 高複雜度 | | 所需權限 | 中 | 無 > 低 > 高 | | 使用者互動 | 中 | 無需 > 需要 | | CIA 影響 | 高 | 機密性/完整性/可用性各自評估 |
| 因素 | 高風險 | 低風險 | |------|--------|--------| | 輸入來源 | 外部使用者輸入 | 內部設定 | | 資料敏感度 | PII、憑證 | 公開資料 | | 認證要求 | 未認證可存取 | 僅管理員 | | 利用複雜度 | 簡單字串注入 | 多步驟鏈 | | 現有防禦 | 無 | WAF、輸入驗證已存在 |
### [Critical/High/Medium/Low] 漏洞標題(CWE-XXX)
- **位置**:`file.py:42`
- **說明**:漏洞描述與攻擊情境
- **漏洞程式碼**:
```python
# 有問題的程式碼
# 安全的替代方案
tools
基於 SLA/SLO 量化評估事故影響的計算模型與業務影響矩陣。適用於「SLA 影響」、「SLO 違反」、「影響評估」、「營收損失估算」、「Error Budget」、「可用性計算」、「事故成本評估」等量化事故業務影響的任務。強化 impact-assessor 的評估能力。注意:事故原因分析與改善規劃不在此技能範圍內。
research
根因分析(RCA)方法論詳細指南。提供 5 Whys、Fishbone 圖、Fault Tree Analysis、變更分析等結構化 RCA 技術,以及認知偏誤防範清單。適用於「根因分析」、「RCA」、「5 Whys」、「魚骨圖」、「Fault Tree」、「原因分析方法論」、「變更分析」等事故原因分析任務。強化 root-cause-investigator 的分析能力。注意:時間軸重建與改善規劃不在此技能範圍內。
testing
事故事後分析(Postmortem)完整流程。協調 7 個執行階段:資訊收集 → 時間軸重建 → 根因分析 → 影響評估 → 改善規劃 → 報告審查 → 整合報告,最終產出完整的 Postmortem 報告。適用於「寫事故報告」、「post-incident 分析」、「RCA 報告」、「事故時間軸整理」、「建立改善措施」等請求。注意:即時 Incident Response(on-call)、監控系統設定、告警配置不在此技能範圍內。
content-media
投影片版面模式庫。提供 20 種投影片類型的最佳版面配置、格線系統、色彩與字型設計 Token。適用於「投影片版面」、「Slide Layout」、「設計系統」、「格線」、「字型」、「色彩規範」等投影片視覺設計任務。強化 visual-designer 的設計能力。注意:PPT/Keynote 檔案直接輸出不在此技能範圍內。