@vigolium/piolium 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/agents/access-auditor.md +300 -0
  4. package/agents/assumption-breaker.md +154 -0
  5. package/agents/attack-designer.md +116 -0
  6. package/agents/code-scanner.md +139 -0
  7. package/agents/concurrency-auditor.md +238 -0
  8. package/agents/confirm-writer.md +257 -0
  9. package/agents/context-reviewer.md +274 -0
  10. package/agents/cross-verifier.md +165 -0
  11. package/agents/cve-scout.md +381 -0
  12. package/agents/env-builder.md +282 -0
  13. package/agents/env-profiler.md +205 -0
  14. package/agents/evidence-collector.md +140 -0
  15. package/agents/finding-grader.md +142 -0
  16. package/agents/finding-writer.md +148 -0
  17. package/agents/flow-tracer.md +106 -0
  18. package/agents/goal-backtracer.md +146 -0
  19. package/agents/history-miner.md +467 -0
  20. package/agents/independent-verifier.md +118 -0
  21. package/agents/intent-mapper.md +183 -0
  22. package/agents/longshot-collector.md +128 -0
  23. package/agents/longshot-prober.md +126 -0
  24. package/agents/patch-auditor.md +73 -0
  25. package/agents/poc-author.md +124 -0
  26. package/agents/poc-runner.md +194 -0
  27. package/agents/probe-lead.md +269 -0
  28. package/agents/red-challenger.md +101 -0
  29. package/agents/report-composer.md +208 -0
  30. package/agents/review-adjudicator.md +216 -0
  31. package/agents/spec-auditor.md +155 -0
  32. package/agents/taint-tracer.md +265 -0
  33. package/agents/test-locator.md +209 -0
  34. package/agents/threat-modeler.md +132 -0
  35. package/agents/variant-scanner.md +108 -0
  36. package/agents/variant-spotter.md +110 -0
  37. package/bin/piolium.mjs +376 -0
  38. package/extensions/piolium/_vendor/yaml.bundle.d.mts +6 -0
  39. package/extensions/piolium/_vendor/yaml.bundle.mjs +139 -0
  40. package/extensions/piolium/agent-runner.ts +322 -0
  41. package/extensions/piolium/agents.ts +266 -0
  42. package/extensions/piolium/audit-state.ts +522 -0
  43. package/extensions/piolium/bundled-resources.ts +97 -0
  44. package/extensions/piolium/candidate-scan.ts +966 -0
  45. package/extensions/piolium/command-target.ts +177 -0
  46. package/extensions/piolium/console-stream.ts +57 -0
  47. package/extensions/piolium/export-results.ts +380 -0
  48. package/extensions/piolium/findings.ts +448 -0
  49. package/extensions/piolium/heartbeat.ts +182 -0
  50. package/extensions/piolium/help.ts +234 -0
  51. package/extensions/piolium/index.ts +1865 -0
  52. package/extensions/piolium/longshot.ts +530 -0
  53. package/extensions/piolium/matcher-suggestions.ts +196 -0
  54. package/extensions/piolium/matcher-utils.ts +83 -0
  55. package/extensions/piolium/modes/balanced.ts +750 -0
  56. package/extensions/piolium/modes/confirm-bootstrap.ts +186 -0
  57. package/extensions/piolium/modes/confirm.ts +697 -0
  58. package/extensions/piolium/modes/deep.ts +917 -0
  59. package/extensions/piolium/modes/diff.ts +177 -0
  60. package/extensions/piolium/modes/lite.ts +540 -0
  61. package/extensions/piolium/modes/longshot.ts +595 -0
  62. package/extensions/piolium/modes/merge.ts +204 -0
  63. package/extensions/piolium/modes/phase-runner.ts +267 -0
  64. package/extensions/piolium/modes/reinvest.ts +546 -0
  65. package/extensions/piolium/modes/revisit.ts +279 -0
  66. package/extensions/piolium/modes.ts +48 -0
  67. package/extensions/piolium/phase-labels.ts +123 -0
  68. package/extensions/piolium/phase-status-strip.ts +92 -0
  69. package/extensions/piolium/prompt-prefix-editor.ts +39 -0
  70. package/extensions/piolium/providers/anthropic-vertex.ts +836 -0
  71. package/extensions/piolium/recon.ts +409 -0
  72. package/extensions/piolium/result-stats.ts +105 -0
  73. package/extensions/piolium/retry.ts +120 -0
  74. package/extensions/piolium/scheduler.ts +212 -0
  75. package/extensions/piolium/secrets.ts +368 -0
  76. package/extensions/piolium/tools/web-tools.ts +148 -0
  77. package/package.json +77 -0
  78. package/skills/agentic-actions-auditor/SKILL.md +327 -0
  79. package/skills/agentic-actions-auditor/references/action-profiles.md +186 -0
  80. package/skills/agentic-actions-auditor/references/cross-file-resolution.md +209 -0
  81. package/skills/agentic-actions-auditor/references/foundations.md +94 -0
  82. package/skills/agentic-actions-auditor/references/vector-a-env-var-intermediary.md +77 -0
  83. package/skills/agentic-actions-auditor/references/vector-b-direct-expression-injection.md +83 -0
  84. package/skills/agentic-actions-auditor/references/vector-c-cli-data-fetch.md +83 -0
  85. package/skills/agentic-actions-auditor/references/vector-d-pr-target-checkout.md +88 -0
  86. package/skills/agentic-actions-auditor/references/vector-e-error-log-injection.md +88 -0
  87. package/skills/agentic-actions-auditor/references/vector-f-subshell-expansion.md +82 -0
  88. package/skills/agentic-actions-auditor/references/vector-g-eval-of-ai-output.md +91 -0
  89. package/skills/agentic-actions-auditor/references/vector-h-dangerous-sandbox-configs.md +102 -0
  90. package/skills/agentic-actions-auditor/references/vector-i-wildcard-allowlists.md +88 -0
  91. package/skills/audit/SKILL.md +562 -0
  92. package/skills/audit/assets/icon.svg +7 -0
  93. package/skills/audit/hooks/scripts/validate_phase_output.py +550 -0
  94. package/skills/audit/references/adversarial-review.md +148 -0
  95. package/skills/audit/references/architecture-aware-sast.md +306 -0
  96. package/skills/audit/references/audit-workflow.md +737 -0
  97. package/skills/audit/references/chamber-protocol.md +384 -0
  98. package/skills/audit/references/creative-attack-modes.md +221 -0
  99. package/skills/audit/references/deep-analysis.md +273 -0
  100. package/skills/audit/references/domain-attack-playbooks.md +1129 -0
  101. package/skills/audit/references/knowledge-base-template.md +513 -0
  102. package/skills/audit/references/real-env-validation.md +191 -0
  103. package/skills/audit/references/report-templates.md +417 -0
  104. package/skills/audit/references/triage-and-prereqs.md +134 -0
  105. package/skills/audit/scripts/consolidate_drafts.py +554 -0
  106. package/skills/audit/scripts/partition_findings.py +152 -0
  107. package/skills/audit/scripts/rg-hotspots.sh +121 -0
  108. package/skills/audit/scripts/stamp_file_state.py +349 -0
  109. package/skills/code-reviewer/SKILL.md +65 -0
  110. package/skills/codeql/SKILL.md +281 -0
  111. package/skills/codeql/references/build-fixes.md +90 -0
  112. package/skills/codeql/references/diagnostic-query-templates.md +339 -0
  113. package/skills/codeql/references/extension-yaml-format.md +209 -0
  114. package/skills/codeql/references/important-only-suite.md +153 -0
  115. package/skills/codeql/references/language-details.md +207 -0
  116. package/skills/codeql/references/macos-arm64e-workaround.md +179 -0
  117. package/skills/codeql/references/performance-tuning.md +111 -0
  118. package/skills/codeql/references/quality-assessment.md +172 -0
  119. package/skills/codeql/references/ruleset-catalog.md +63 -0
  120. package/skills/codeql/references/run-all-suite.md +92 -0
  121. package/skills/codeql/references/sarif-processing.md +79 -0
  122. package/skills/codeql/references/threat-models.md +51 -0
  123. package/skills/codeql/workflows/build-database.md +280 -0
  124. package/skills/codeql/workflows/create-data-extensions.md +261 -0
  125. package/skills/codeql/workflows/run-analysis.md +301 -0
  126. package/skills/differential-review/SKILL.md +220 -0
  127. package/skills/differential-review/adversarial.md +203 -0
  128. package/skills/differential-review/methodology.md +234 -0
  129. package/skills/differential-review/patterns.md +300 -0
  130. package/skills/differential-review/reporting.md +369 -0
  131. package/skills/fp-check/SKILL.md +125 -0
  132. package/skills/fp-check/references/bug-class-verification.md +114 -0
  133. package/skills/fp-check/references/deep-verification.md +143 -0
  134. package/skills/fp-check/references/evidence-templates.md +91 -0
  135. package/skills/fp-check/references/false-positive-patterns.md +115 -0
  136. package/skills/fp-check/references/gate-reviews.md +27 -0
  137. package/skills/fp-check/references/standard-verification.md +78 -0
  138. package/skills/insecure-defaults/SKILL.md +117 -0
  139. package/skills/insecure-defaults/references/examples.md +409 -0
  140. package/skills/last30days/SKILL.md +444 -0
  141. package/skills/sarif-parsing/SKILL.md +483 -0
  142. package/skills/sarif-parsing/resources/jq-queries.md +162 -0
  143. package/skills/sarif-parsing/resources/sarif_helpers.py +331 -0
  144. package/skills/security-threat-model/LICENSE.txt +201 -0
  145. package/skills/security-threat-model/SKILL.md +81 -0
  146. package/skills/security-threat-model/agents/openai.yaml +4 -0
  147. package/skills/security-threat-model/references/prompt-template.md +255 -0
  148. package/skills/security-threat-model/references/security-controls-and-assets.md +32 -0
  149. package/skills/semgrep/SKILL.md +212 -0
  150. package/skills/semgrep/references/rulesets.md +162 -0
  151. package/skills/semgrep/references/scan-modes.md +110 -0
  152. package/skills/semgrep/references/scanner-task-prompt.md +140 -0
  153. package/skills/semgrep/scripts/merge_sarif.py +203 -0
  154. package/skills/semgrep/workflows/scan-workflow.md +311 -0
  155. package/skills/semgrep-rule-creator/SKILL.md +168 -0
  156. package/skills/semgrep-rule-creator/references/quick-reference.md +202 -0
  157. package/skills/semgrep-rule-creator/references/workflow.md +240 -0
  158. package/skills/semgrep-rule-variant-creator/SKILL.md +205 -0
  159. package/skills/semgrep-rule-variant-creator/references/applicability-analysis.md +250 -0
  160. package/skills/semgrep-rule-variant-creator/references/language-syntax-guide.md +324 -0
  161. package/skills/semgrep-rule-variant-creator/references/workflow.md +518 -0
  162. package/skills/sharp-edges/SKILL.md +292 -0
  163. package/skills/sharp-edges/references/auth-patterns.md +252 -0
  164. package/skills/sharp-edges/references/case-studies.md +274 -0
  165. package/skills/sharp-edges/references/config-patterns.md +333 -0
  166. package/skills/sharp-edges/references/crypto-apis.md +190 -0
  167. package/skills/sharp-edges/references/lang-c.md +205 -0
  168. package/skills/sharp-edges/references/lang-csharp.md +285 -0
  169. package/skills/sharp-edges/references/lang-go.md +270 -0
  170. package/skills/sharp-edges/references/lang-java.md +263 -0
  171. package/skills/sharp-edges/references/lang-javascript.md +269 -0
  172. package/skills/sharp-edges/references/lang-kotlin.md +265 -0
  173. package/skills/sharp-edges/references/lang-php.md +245 -0
  174. package/skills/sharp-edges/references/lang-python.md +274 -0
  175. package/skills/sharp-edges/references/lang-ruby.md +273 -0
  176. package/skills/sharp-edges/references/lang-rust.md +272 -0
  177. package/skills/sharp-edges/references/lang-swift.md +287 -0
  178. package/skills/sharp-edges/references/language-specific.md +588 -0
  179. package/skills/spec-to-code-compliance/SKILL.md +357 -0
  180. package/skills/spec-to-code-compliance/resources/COMPLETENESS_CHECKLIST.md +69 -0
  181. package/skills/spec-to-code-compliance/resources/IR_EXAMPLES.md +417 -0
  182. package/skills/spec-to-code-compliance/resources/OUTPUT_REQUIREMENTS.md +105 -0
  183. package/skills/supply-chain-risk-auditor/SKILL.md +67 -0
  184. package/skills/supply-chain-risk-auditor/resources/results-template.md +41 -0
  185. package/skills/variant-analysis/METHODOLOGY.md +327 -0
  186. package/skills/variant-analysis/SKILL.md +142 -0
  187. package/skills/variant-analysis/resources/codeql/cpp.ql +119 -0
  188. package/skills/variant-analysis/resources/codeql/go.ql +69 -0
  189. package/skills/variant-analysis/resources/codeql/java.ql +71 -0
  190. package/skills/variant-analysis/resources/codeql/javascript.ql +63 -0
  191. package/skills/variant-analysis/resources/codeql/python.ql +80 -0
  192. package/skills/variant-analysis/resources/semgrep/cpp.yaml +98 -0
  193. package/skills/variant-analysis/resources/semgrep/go.yaml +63 -0
  194. package/skills/variant-analysis/resources/semgrep/java.yaml +61 -0
  195. package/skills/variant-analysis/resources/semgrep/javascript.yaml +60 -0
  196. package/skills/variant-analysis/resources/semgrep/python.yaml +72 -0
  197. package/skills/variant-analysis/resources/variant-report-template.md +75 -0
  198. package/skills/vuln-report/SKILL.md +137 -0
  199. package/skills/vuln-report/agents/openai.yaml +4 -0
  200. package/skills/vuln-report/references/report-template.md +135 -0
  201. package/skills/wooyun-legacy/SKILL.md +367 -0
  202. package/skills/wooyun-legacy/references/bank-penetration.md +222 -0
  203. package/skills/wooyun-legacy/references/checklists/command-execution-checklist.md +119 -0
  204. package/skills/wooyun-legacy/references/checklists/csrf-checklist.md +74 -0
  205. package/skills/wooyun-legacy/references/checklists/file-upload-checklist.md +108 -0
  206. package/skills/wooyun-legacy/references/checklists/info-disclosure-checklist.md +114 -0
  207. package/skills/wooyun-legacy/references/checklists/logic-flaws-checklist.md +95 -0
  208. package/skills/wooyun-legacy/references/checklists/misconfig-checklist.md +124 -0
  209. package/skills/wooyun-legacy/references/checklists/path-traversal-checklist.md +87 -0
  210. package/skills/wooyun-legacy/references/checklists/rce-checklist.md +93 -0
  211. package/skills/wooyun-legacy/references/checklists/sql-injection-checklist.md +97 -0
  212. package/skills/wooyun-legacy/references/checklists/ssrf-checklist.md +99 -0
  213. package/skills/wooyun-legacy/references/checklists/unauthorized-access-checklist.md +89 -0
  214. package/skills/wooyun-legacy/references/checklists/weak-password-checklist.md +115 -0
  215. package/skills/wooyun-legacy/references/checklists/xss-checklist.md +103 -0
  216. package/skills/wooyun-legacy/references/checklists/xxe-checklist.md +130 -0
  217. package/skills/wooyun-legacy/references/info-disclosure.md +975 -0
  218. package/skills/wooyun-legacy/references/logic-flaws.md +721 -0
  219. package/skills/wooyun-legacy/references/path-traversal.md +1191 -0
  220. package/skills/wooyun-legacy/references/telecom-penetration.md +156 -0
  221. package/skills/wooyun-legacy/references/unauthorized-access.md +980 -0
  222. package/skills/wooyun-legacy/references/xss.md +746 -0
  223. package/skills/zeroize-audit/SKILL.md +371 -0
  224. package/skills/zeroize-audit/configs/c.yaml +21 -0
  225. package/skills/zeroize-audit/configs/default.yaml +128 -0
  226. package/skills/zeroize-audit/configs/rust.yaml +83 -0
  227. package/skills/zeroize-audit/prompts/report_template.md +238 -0
  228. package/skills/zeroize-audit/prompts/system.md +163 -0
  229. package/skills/zeroize-audit/prompts/task.md +97 -0
  230. package/skills/zeroize-audit/references/compile-commands.md +231 -0
  231. package/skills/zeroize-audit/references/detection-strategy.md +191 -0
  232. package/skills/zeroize-audit/references/ir-analysis.md +252 -0
  233. package/skills/zeroize-audit/references/mcp-analysis.md +221 -0
  234. package/skills/zeroize-audit/references/poc-generation.md +470 -0
  235. package/skills/zeroize-audit/references/rust-zeroization-patterns.md +867 -0
  236. package/skills/zeroize-audit/schemas/input.json +83 -0
  237. package/skills/zeroize-audit/schemas/output.json +140 -0
  238. package/skills/zeroize-audit/tools/analyze_asm.sh +202 -0
  239. package/skills/zeroize-audit/tools/analyze_cfg.py +381 -0
  240. package/skills/zeroize-audit/tools/analyze_heap.sh +211 -0
  241. package/skills/zeroize-audit/tools/analyze_ir_semantic.py +429 -0
  242. package/skills/zeroize-audit/tools/diff_ir.sh +135 -0
  243. package/skills/zeroize-audit/tools/diff_rust_mir.sh +189 -0
  244. package/skills/zeroize-audit/tools/emit_asm.sh +67 -0
  245. package/skills/zeroize-audit/tools/emit_ir.sh +77 -0
  246. package/skills/zeroize-audit/tools/emit_rust_asm.sh +178 -0
  247. package/skills/zeroize-audit/tools/emit_rust_ir.sh +150 -0
  248. package/skills/zeroize-audit/tools/emit_rust_mir.sh +158 -0
  249. package/skills/zeroize-audit/tools/extract_compile_flags.py +284 -0
  250. package/skills/zeroize-audit/tools/generate_poc.py +1329 -0
  251. package/skills/zeroize-audit/tools/mcp/apply_confidence_gates.py +113 -0
  252. package/skills/zeroize-audit/tools/mcp/check_mcp.sh +68 -0
  253. package/skills/zeroize-audit/tools/mcp/normalize_mcp_evidence.py +125 -0
  254. package/skills/zeroize-audit/tools/scripts/check_llvm_patterns.py +481 -0
  255. package/skills/zeroize-audit/tools/scripts/check_mir_patterns.py +554 -0
  256. package/skills/zeroize-audit/tools/scripts/check_rust_asm.py +424 -0
  257. package/skills/zeroize-audit/tools/scripts/check_rust_asm_aarch64.py +300 -0
  258. package/skills/zeroize-audit/tools/scripts/check_rust_asm_x86.py +283 -0
  259. package/skills/zeroize-audit/tools/scripts/find_dangerous_apis.py +375 -0
  260. package/skills/zeroize-audit/tools/scripts/semantic_audit.py +923 -0
  261. package/skills/zeroize-audit/tools/track_dataflow.sh +196 -0
  262. package/skills/zeroize-audit/tools/validate_rust_toolchain.sh +298 -0
  263. package/skills/zeroize-audit/workflows/phase-0-preflight.md +150 -0
  264. package/skills/zeroize-audit/workflows/phase-1-source-analysis.md +144 -0
  265. package/skills/zeroize-audit/workflows/phase-2-compiler-analysis.md +139 -0
  266. package/skills/zeroize-audit/workflows/phase-3-interim-report.md +46 -0
  267. package/skills/zeroize-audit/workflows/phase-4-poc-generation.md +46 -0
  268. package/skills/zeroize-audit/workflows/phase-5-poc-validation.md +136 -0
  269. package/skills/zeroize-audit/workflows/phase-6-final-report.md +44 -0
  270. package/skills/zeroize-audit/workflows/phase-7-test-generation.md +42 -0
  271. package/themes/piolium-srcery.json +94 -0
@@ -0,0 +1,331 @@
1
+ """
2
+ SARIF Parsing Helper Functions
3
+
4
+ Reusable utilities for working with SARIF files.
5
+ No external dependencies beyond standard library.
6
+ """
7
+
8
+ import hashlib
9
+ import json
10
+ from collections import defaultdict
11
+ from collections.abc import Iterator
12
+ from dataclasses import dataclass, field
13
+ from pathlib import Path
14
+ from typing import Any
15
+ from urllib.parse import unquote
16
+
17
+
18
+ @dataclass
19
+ class Finding:
20
+ """Structured representation of a SARIF result."""
21
+
22
+ rule_id: str
23
+ level: str
24
+ message: str
25
+ file_path: str | None = None
26
+ start_line: int | None = None
27
+ end_line: int | None = None
28
+ start_column: int | None = None
29
+ end_column: int | None = None
30
+ fingerprint: str | None = None
31
+ tool_name: str | None = None
32
+ rule_name: str | None = None
33
+ raw: dict = field(default_factory=dict, repr=False)
34
+
35
+
36
+ def load_sarif(path: str | Path) -> dict:
37
+ """Load and parse a SARIF file."""
38
+ with open(path) as f:
39
+ return json.load(f)
40
+
41
+
42
+ def save_sarif(sarif: dict, path: str | Path, indent: int = 2) -> None:
43
+ """Save SARIF data to file."""
44
+ with open(path, "w") as f:
45
+ json.dump(sarif, f, indent=indent)
46
+
47
+
48
+ def validate_version(sarif: dict) -> bool:
49
+ """Check if SARIF version is 2.1.0."""
50
+ return sarif.get("version") == "2.1.0"
51
+
52
+
53
+ def normalize_path(uri: str, base_path: str = "") -> str:
54
+ """Normalize SARIF artifact URI to consistent path."""
55
+ if not uri:
56
+ return ""
57
+
58
+ # Remove file:// prefix
59
+ if uri.startswith("file://"):
60
+ uri = uri[7:]
61
+
62
+ # URL decode
63
+ uri = unquote(uri)
64
+
65
+ # Handle relative paths
66
+ if base_path and not Path(uri).is_absolute():
67
+ uri = str(Path(base_path) / uri)
68
+
69
+ return str(Path(uri))
70
+
71
+
72
+ def safe_get(data: dict, *keys, default: Any = None) -> Any:
73
+ """Safely navigate nested dict structure."""
74
+ for key in keys:
75
+ if isinstance(data, dict):
76
+ data = data.get(key, {})
77
+ elif isinstance(data, list) and isinstance(key, int):
78
+ data = data[key] if 0 <= key < len(data) else {}
79
+ else:
80
+ return default
81
+ return data if data != {} else default
82
+
83
+
84
+ def extract_location(result: dict) -> tuple[str | None, int | None, int | None]:
85
+ """Extract file path, start line, and end line from result."""
86
+ loc = safe_get(result, "locations", 0, default={})
87
+ phys = loc.get("physicalLocation", {})
88
+ region = phys.get("region", {})
89
+
90
+ file_path = safe_get(phys, "artifactLocation", "uri")
91
+ start_line = region.get("startLine")
92
+ end_line = region.get("endLine")
93
+
94
+ return file_path, start_line, end_line
95
+
96
+
97
+ def iter_results(sarif: dict) -> Iterator[tuple[dict, dict]]:
98
+ """Iterate over all results with their run context."""
99
+ for run in sarif.get("runs", []):
100
+ for result in run.get("results", []):
101
+ yield result, run
102
+
103
+
104
+ def extract_findings(sarif: dict) -> list[Finding]:
105
+ """Extract all findings as structured objects."""
106
+ findings = []
107
+
108
+ for result, run in iter_results(sarif):
109
+ tool_name = safe_get(run, "tool", "driver", "name")
110
+ file_path, start_line, end_line = extract_location(result)
111
+
112
+ loc = safe_get(result, "locations", 0, default={})
113
+ phys = loc.get("physicalLocation", {})
114
+ region = phys.get("region", {})
115
+
116
+ # Get fingerprint
117
+ fp = None
118
+ if result.get("partialFingerprints"):
119
+ fp = next(iter(result["partialFingerprints"].values()), None)
120
+ elif result.get("fingerprints"):
121
+ fp = next(iter(result["fingerprints"].values()), None)
122
+
123
+ findings.append(
124
+ Finding(
125
+ rule_id=result.get("ruleId", "unknown"),
126
+ level=result.get("level", "warning"),
127
+ message=safe_get(result, "message", "text", default=""),
128
+ file_path=file_path,
129
+ start_line=start_line,
130
+ end_line=end_line,
131
+ start_column=region.get("startColumn"),
132
+ end_column=region.get("endColumn"),
133
+ fingerprint=fp,
134
+ tool_name=tool_name,
135
+ raw=result,
136
+ )
137
+ )
138
+
139
+ return findings
140
+
141
+
142
+ def filter_by_level(findings: list[Finding], *levels: str) -> list[Finding]:
143
+ """Filter findings by severity level(s)."""
144
+ return [f for f in findings if f.level in levels]
145
+
146
+
147
+ def filter_by_file(findings: list[Finding], pattern: str) -> list[Finding]:
148
+ """Filter findings by file path pattern (substring match)."""
149
+ return [f for f in findings if f.file_path and pattern in f.file_path]
150
+
151
+
152
+ def filter_by_rule(findings: list[Finding], *rule_ids: str) -> list[Finding]:
153
+ """Filter findings by rule ID(s)."""
154
+ return [f for f in findings if f.rule_id in rule_ids]
155
+
156
+
157
+ def sort_by_severity(findings: list[Finding], reverse: bool = False) -> list[Finding]:
158
+ """Sort findings by severity (error > warning > note > none)."""
159
+ severity_order = {"error": 0, "warning": 1, "note": 2, "none": 3}
160
+ return sorted(findings, key=lambda f: severity_order.get(f.level, 99), reverse=reverse)
161
+
162
+
163
+ def group_by_file(findings: list[Finding]) -> dict[str, list[Finding]]:
164
+ """Group findings by file path."""
165
+ grouped = defaultdict(list)
166
+ for f in findings:
167
+ key = f.file_path or "unknown"
168
+ grouped[key].append(f)
169
+ return dict(grouped)
170
+
171
+
172
+ def group_by_rule(findings: list[Finding]) -> dict[str, list[Finding]]:
173
+ """Group findings by rule ID."""
174
+ grouped = defaultdict(list)
175
+ for f in findings:
176
+ grouped[f.rule_id].append(f)
177
+ return dict(grouped)
178
+
179
+
180
+ def count_by_level(findings: list[Finding]) -> dict[str, int]:
181
+ """Count findings by severity level."""
182
+ counts = defaultdict(int)
183
+ for f in findings:
184
+ counts[f.level] += 1
185
+ return dict(counts)
186
+
187
+
188
+ def count_by_rule(findings: list[Finding]) -> dict[str, int]:
189
+ """Count findings by rule ID."""
190
+ counts = defaultdict(int)
191
+ for f in findings:
192
+ counts[f.rule_id] += 1
193
+ return dict(counts)
194
+
195
+
196
+ def compute_fingerprint(result: dict, include_message: bool = True) -> str:
197
+ """Compute stable fingerprint from result data."""
198
+ components = [result.get("ruleId", "")]
199
+
200
+ file_path, start_line, _ = extract_location(result)
201
+ if file_path:
202
+ # Use only filename, not full path (more stable across environments)
203
+ components.append(Path(file_path).name)
204
+ if start_line:
205
+ components.append(str(start_line))
206
+ if include_message:
207
+ msg = safe_get(result, "message", "text", default="")
208
+ # First 50 chars of message for stability
209
+ components.append(msg[:50])
210
+
211
+ return hashlib.sha256("|".join(components).encode()).hexdigest()[:16]
212
+
213
+
214
+ def deduplicate(findings: list[Finding]) -> list[Finding]:
215
+ """Remove duplicate findings based on fingerprints."""
216
+ seen = set()
217
+ unique = []
218
+
219
+ for f in findings:
220
+ key = f.fingerprint or compute_fingerprint(f.raw)
221
+ if key not in seen:
222
+ seen.add(key)
223
+ unique.append(f)
224
+
225
+ return unique
226
+
227
+
228
+ def merge_sarif_files(*paths: str | Path) -> dict:
229
+ """Merge multiple SARIF files into one."""
230
+ merged = {
231
+ "version": "2.1.0",
232
+ "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
233
+ "runs": [],
234
+ }
235
+
236
+ for path in paths:
237
+ sarif = load_sarif(path)
238
+ merged["runs"].extend(sarif.get("runs", []))
239
+
240
+ return merged
241
+
242
+
243
+ def diff_findings(
244
+ baseline: list[Finding], current: list[Finding]
245
+ ) -> tuple[list[Finding], list[Finding], list[Finding]]:
246
+ """
247
+ Compare two sets of findings.
248
+
249
+ Returns:
250
+ - new: findings in current but not baseline
251
+ - fixed: findings in baseline but not current
252
+ - unchanged: findings in both
253
+ """
254
+ baseline_fps = {f.fingerprint or compute_fingerprint(f.raw) for f in baseline}
255
+ current_fps = {f.fingerprint or compute_fingerprint(f.raw) for f in current}
256
+
257
+ new = [f for f in current if (f.fingerprint or compute_fingerprint(f.raw)) not in baseline_fps]
258
+ fixed = [
259
+ f for f in baseline if (f.fingerprint or compute_fingerprint(f.raw)) not in current_fps
260
+ ]
261
+ unchanged = [
262
+ f for f in current if (f.fingerprint or compute_fingerprint(f.raw)) in baseline_fps
263
+ ]
264
+
265
+ return new, fixed, unchanged
266
+
267
+
268
+ def get_rules(sarif: dict) -> dict[str, dict]:
269
+ """Extract rule definitions from SARIF file."""
270
+ rules = {}
271
+ for run in sarif.get("runs", []):
272
+ for rule in safe_get(run, "tool", "driver", "rules", default=[]):
273
+ rules[rule.get("id", "")] = rule
274
+ return rules
275
+
276
+
277
+ def to_csv_rows(findings: list[Finding]) -> list[list[str]]:
278
+ """Convert findings to CSV-ready rows."""
279
+ rows = [["rule_id", "level", "file", "line", "message"]]
280
+ for f in findings:
281
+ rows.append(
282
+ [
283
+ f.rule_id,
284
+ f.level,
285
+ f.file_path or "",
286
+ str(f.start_line or ""),
287
+ f.message.replace("\n", " ")[:200],
288
+ ]
289
+ )
290
+ return rows
291
+
292
+
293
+ def summary(findings: list[Finding]) -> dict:
294
+ """Generate summary statistics for findings."""
295
+ return {
296
+ "total": len(findings),
297
+ "by_level": count_by_level(findings),
298
+ "by_rule": count_by_rule(findings),
299
+ "files_affected": len(set(f.file_path for f in findings if f.file_path)),
300
+ "rules_triggered": len(set(f.rule_id for f in findings)),
301
+ }
302
+
303
+
304
+ # Example usage
305
+ if __name__ == "__main__":
306
+ import sys
307
+
308
+ if len(sys.argv) < 2:
309
+ print("Usage: python sarif_helpers.py <sarif_file>")
310
+ sys.exit(1)
311
+
312
+ sarif = load_sarif(sys.argv[1])
313
+
314
+ if not validate_version(sarif):
315
+ print("Warning: SARIF version is not 2.1.0")
316
+
317
+ findings = extract_findings(sarif)
318
+ findings = sort_by_severity(findings)
319
+
320
+ print("\nSummary:")
321
+ stats = summary(findings)
322
+ print(f" Total findings: {stats['total']}")
323
+ print(f" Files affected: {stats['files_affected']}")
324
+ print(f" Rules triggered: {stats['rules_triggered']}")
325
+ print("\nBy severity:")
326
+ for level, count in stats["by_level"].items():
327
+ print(f" {level}: {count}")
328
+
329
+ print("\nTop 5 rules:")
330
+ for rule, count in sorted(stats["by_rule"].items(), key=lambda x: -x[1])[:5]:
331
+ print(f" {rule}: {count}")
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf of
171
+ any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don\'t include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,81 @@
1
+ ---
2
+ name: "security-threat-model"
3
+ description: "Repository-grounded threat modeling that enumerates trust boundaries, assets, attacker capabilities, abuse paths, and mitigations, and writes a concise Markdown threat model. Trigger only when the user explicitly asks to threat model a codebase or path, enumerate threats/abuse paths, or perform AppSec threat modeling. Do not trigger for general architecture summaries, code review, or non-security design work."
4
+ ---
5
+
6
+ # Threat Model Source Code Repo
7
+
8
+ Deliver an actionable AppSec-grade threat model that is specific to the repository or a project path, not a generic checklist. Anchor every architectural claim to evidence in the repo and keep assumptions explicit. Prioritizing realistic attacker goals and concrete impacts over generic checklists.
9
+
10
+ ## Quick start
11
+
12
+ 1) Collect (or infer) inputs:
13
+ - Repo root path and any in-scope paths.
14
+ - Intended usage, deployment model, internet exposure, and auth expectations (if known).
15
+ - Any existing repository summary or architecture spec.
16
+ - Use prompts in `references/prompt-template.md` to generate a repository summary.
17
+ - Follow the required output contract in `references/prompt-template.md`. Use it verbatim when possible.
18
+
19
+ ## Workflow
20
+
21
+ ### 1) Scope and extract the system model
22
+ - Identify primary components, data stores, and external integrations from the repo summary.
23
+ - Identify how the system runs (server, CLI, library, worker) and its entrypoints.
24
+ - Separate runtime behavior from CI/build/dev tooling and from tests/examples.
25
+ - Map the in-scope locations to those components and exclude out-of-scope items explicitly.
26
+ - Do not claim components, flows, or controls without evidence.
27
+
28
+ ### 2) Derive boundaries, assets, and entry points
29
+ - Enumerate trust boundaries as concrete edges between components, noting protocol, auth, encryption, validation, and rate limiting.
30
+ - List assets that drive risk (data, credentials, models, config, compute resources, audit logs).
31
+ - Identify entry points (endpoints, upload surfaces, parsers/decoders, job triggers, admin tooling, logging/error sinks).
32
+
33
+ ### 3) Calibrate assets and attacker capabilities
34
+ - List the assets that drive risk (credentials, PII, integrity-critical state, availability-critical components, build artifacts).
35
+ - Describe realistic attacker capabilities based on exposure and intended usage.
36
+ - Explicitly note non-capabilities to avoid inflated severity.
37
+
38
+
39
+ ### 4) Enumerate threats as abuse paths
40
+ - Prefer attacker goals that map to assets and boundaries (exfiltration, privilege escalation, integrity compromise, denial of service).
41
+ - Classify each threat and tie it to impacted assets.
42
+ - Keep the number of threats small but high quality.
43
+
44
+ ### 5) Prioritize with explicit likelihood and impact reasoning
45
+ - Use qualitative likelihood and impact (low/medium/high) with short justifications.
46
+ - Set overall priority (critical/high/medium/low) using likelihood x impact, adjusted for existing controls.
47
+ - State which assumptions most influence the ranking.
48
+
49
+ ### 6) Validate service context and assumptions with the user
50
+ - Summarize key assumptions that materially affect threat ranking or scope, then ask the user to confirm or correct them.
51
+ - Ask 1–3 targeted questions to resolve missing context (service owner and environment, scale/users, deployment model, authn/authz, internet exposure, data sensitivity, multi-tenancy).
52
+ - Pause and wait for user feedback before producing the final report.
53
+ - If the user declines or can’t answer, state which assumptions remain and how they influence priority.
54
+
55
+ ### 7) Recommend mitigations and focus paths
56
+ - Distinguish existing mitigations (with evidence) from recommended mitigations.
57
+ - Tie mitigations to concrete locations (component, boundary, or entry point) and control types (authZ checks, input validation, schema enforcement, sandboxing, rate limits, secrets isolation, audit logging).
58
+ - Prefer specific implementation hints over generic advice (e.g., "enforce schema at gateway for upload payloads" vs "validate inputs").
59
+ - Base recommendations on validated user context; if assumptions remain unresolved, mark recommendations as conditional.
60
+
61
+ ### 8) Run a quality check before finalizing
62
+ - Confirm all discovered entrypoints are covered.
63
+ - Confirm each trust boundary is represented in threats.
64
+ - Confirm runtime vs CI/dev separation.
65
+ - Confirm user clarifications (or explicit non-responses) are reflected.
66
+ - Confirm assumptions and open questions are explicit.
67
+ - Confirm that the format of the report matches closely the required output format defined in prompt template: `references/prompt-template.md`
68
+ - Write the final Markdown to a file named `<repo-or-dir-name>-threat-model.md` (use the basename of the repo root, or the in-scope directory if you were asked to model a subpath).
69
+
70
+
71
+ ## Risk prioritization guidance (illustrative, not exhaustive)
72
+ - High: pre-auth RCE, auth bypass, cross-tenant access, sensitive data exfiltration, key or token theft, model or config integrity compromise, sandbox escape.
73
+ - Medium: targeted DoS of critical components, partial data exposure, rate-limit bypass with measurable impact, log/metrics poisoning that affects detection.
74
+ - Low: low-sensitivity info leaks, noisy DoS with easy mitigation, issues requiring unlikely preconditions.
75
+
76
+ ## References
77
+
78
+ - Output contract and full prompt template: `references/prompt-template.md`
79
+ - Optional controls/asset list: `references/security-controls-and-assets.md`
80
+
81
+ Only load the reference files you need. Keep the final result concise, grounded, and reviewable.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Security Threat Model"
3
+ short_description: "Repo-grounded threat modeling and abuse-path analysis"
4
+ default_prompt: "Create a repository-grounded threat model for this codebase with prioritized abuse paths and mitigations."