@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,261 @@
1
+ # Create Data Extensions Workflow
2
+
3
+ Generate data extension YAML files to improve CodeQL's data flow coverage for project-specific APIs. Runs after database build and before analysis.
4
+
5
+ ## Task System
6
+
7
+ Create these tasks on workflow start:
8
+
9
+ ```
10
+ TaskCreate: "Check for existing data extensions" (Step 1)
11
+ TaskCreate: "Query known sources and sinks" (Step 2) - blockedBy: Step 1
12
+ TaskCreate: "Identify missing sources and sinks" (Step 3) - blockedBy: Step 2
13
+ TaskCreate: "Create data extension files" (Step 4) - blockedBy: Step 3
14
+ TaskCreate: "Validate with re-analysis" (Step 5) - blockedBy: Step 4
15
+ ```
16
+
17
+ ### Early Exit Points
18
+
19
+ | After Step | Condition | Action |
20
+ |------------|-----------|--------|
21
+ | Step 1 | Extensions already exist | Return found packs/files to run-analysis workflow, finish |
22
+ | Step 3 | No missing models identified | Report coverage is adequate, finish |
23
+
24
+ ---
25
+
26
+ ## Steps
27
+
28
+ ### Step 1: Check for Existing Data Extensions
29
+
30
+ **Entry:** CodeQL database exists (`codeql resolve database` succeeds)
31
+ **Exit:** Either existing extensions found (report and finish) OR no extensions found (proceed to Step 2)
32
+
33
+ Search the project for existing data extensions and model packs.
34
+
35
+ ```bash
36
+ # 1. In-repo model packs (exclude output dirs and legacy database dirs)
37
+ fd '(qlpack|codeql-pack)\.yml$' . --exclude 'static_analysis_codeql_*' --exclude 'codeql_*.db' | while read -r f; do
38
+ if grep -q 'dataExtensions' "$f"; then
39
+ echo "MODEL PACK: $(dirname "$f") - $(grep '^name:' "$f")"
40
+ fi
41
+ done
42
+
43
+ # 2. Standalone data extension files
44
+ rg -l '^extensions:' --glob '*.yml' --glob '!static_analysis_codeql_*/**' --glob '!codeql_*.db/**' | head -20
45
+
46
+ # 3. Installed model packs
47
+ codeql resolve qlpacks 2>/dev/null | grep -iE 'model|extension'
48
+ ```
49
+
50
+ **If any found:** Report to user and finish. These will be picked up by the run-analysis workflow.
51
+
52
+ **If none found:** Proceed to Step 2.
53
+
54
+ ---
55
+
56
+ ### Step 2: Query Known Sources and Sinks
57
+
58
+ **Entry:** Step 1 found no existing extensions; database and language identified
59
+ **Exit:** `sources.csv` and `sinks.csv` exist in `$DIAG_DIR` with enumerated source/sink locations
60
+
61
+ Run custom QL queries against the database to enumerate all sources and sinks CodeQL currently recognizes.
62
+
63
+ #### 2a: Select Database and Language
64
+
65
+ A CodeQL database is a directory containing a `codeql-database.yml` marker file. `$DB_NAME` may already be set by the parent skill. If not, discover inside `$OUTPUT_DIR`.
66
+
67
+ ```bash
68
+ if [ -z "$DB_NAME" ]; then
69
+ FOUND_DBS=()
70
+ while IFS= read -r yml; do
71
+ FOUND_DBS+=("$(dirname "$yml")")
72
+ done < <(find "$OUTPUT_DIR" -maxdepth 2 -name "codeql-database.yml" 2>/dev/null)
73
+
74
+ if [ ${#FOUND_DBS[@]} -eq 0 ]; then
75
+ echo "ERROR: No CodeQL database found in $OUTPUT_DIR"; exit 1
76
+ elif [ ${#FOUND_DBS[@]} -eq 1 ]; then
77
+ DB_NAME="${FOUND_DBS[0]}"
78
+ else
79
+ # Multiple databases — use AskUserQuestion to select
80
+ # SKIP if user already specified which database in their prompt
81
+ fi
82
+ fi
83
+
84
+ CODEQL_LANG=$(codeql resolve database --format=json -- "$DB_NAME" | jq -r '.languages[0]')
85
+ DIAG_DIR="$OUTPUT_DIR/diagnostics"
86
+ mkdir -p "$DIAG_DIR"
87
+ ```
88
+
89
+ #### 2b: Write Source Enumeration Query
90
+
91
+ Use the `Write` tool to create `$DIAG_DIR/list-sources.ql` using the source template from [diagnostic-query-templates.md](../references/diagnostic-query-templates.md#source-enumeration-query). Pick the correct import block for `$CODEQL_LANG`.
92
+
93
+ #### 2c: Write Sink Enumeration Query
94
+
95
+ Use the `Write` tool to create `$DIAG_DIR/list-sinks.ql` using the language-specific sink template from [diagnostic-query-templates.md](../references/diagnostic-query-templates.md#sink-enumeration-queries).
96
+
97
+ **For Java:** Also create `$DIAG_DIR/qlpack.yml` with a `codeql/java-all` dependency and run `codeql pack install` before executing queries.
98
+
99
+ #### 2d: Run Queries
100
+
101
+ ```bash
102
+ codeql query run --database="$DB_NAME" --output="$DIAG_DIR/sources.bqrs" -- "$DIAG_DIR/list-sources.ql"
103
+ codeql bqrs decode --format=csv --output="$DIAG_DIR/sources.csv" -- "$DIAG_DIR/sources.bqrs"
104
+
105
+ codeql query run --database="$DB_NAME" --output="$DIAG_DIR/sinks.bqrs" -- "$DIAG_DIR/list-sinks.ql"
106
+ codeql bqrs decode --format=csv --output="$DIAG_DIR/sinks.csv" -- "$DIAG_DIR/sinks.bqrs"
107
+ ```
108
+
109
+ #### 2e: Summarize Results
110
+
111
+ Read both CSV files and present a summary showing source types and sink kinds with counts.
112
+
113
+ ---
114
+
115
+ ### Step 3: Identify Missing Sources and Sinks
116
+
117
+ **Entry:** Step 2 complete (`sources.csv` and `sinks.csv` available)
118
+ **Exit:** Either no gaps found (report adequate coverage and finish) OR user confirms which gaps to model (proceed to Step 4)
119
+
120
+ Cross-reference the project's API surface against CodeQL's known models.
121
+
122
+ #### 3a: Map the Project's API Surface
123
+
124
+ Read source code to identify security-relevant patterns:
125
+
126
+ | Pattern | What To Find | Likely Model Type |
127
+ |---------|-------------|-------------------|
128
+ | HTTP/request handlers | Custom request parsing | `sourceModel` (kind: `remote`) |
129
+ | Database layers | Custom ORM, raw query wrappers | `sinkModel` (kind: `sql-injection`) |
130
+ | Command execution | Shell wrappers, process spawners | `sinkModel` (kind: `command-injection`) |
131
+ | File operations | Custom file read/write | `sinkModel` (kind: `path-injection`) |
132
+ | Template rendering | HTML output, response builders | `sinkModel` (kind: `xss`) |
133
+ | Deserialization | Custom deserializers | `sinkModel` (kind: `unsafe-deserialization`) |
134
+ | HTTP clients | URL construction | `sinkModel` (kind: `ssrf`) |
135
+ | Sanitizers | Input validation, escaping | `neutralModel` |
136
+ | Pass-through wrappers | Logging, caching, encoding | `summaryModel` (kind: `taint`) |
137
+
138
+ Use `Grep` to search for these patterns in source code (adapt per language).
139
+
140
+ #### 3b: Cross-Reference Against Known Sources and Sinks
141
+
142
+ For each API pattern found, check if it appears in `sources.csv` or `sinks.csv` from Step 2.
143
+
144
+ **An API is "missing" if:**
145
+ - It handles user input but does not appear in `sources.csv`
146
+ - It performs a dangerous operation but does not appear in `sinks.csv`
147
+ - It wraps tainted data but has no summary model
148
+
149
+ #### 3c: Report Gaps
150
+
151
+ Present findings and use `AskUserQuestion`:
152
+
153
+ ```
154
+ header: "Extensions"
155
+ question: "Create data extension files for the identified gaps?"
156
+ options:
157
+ - label: "Create all (Recommended)"
158
+ description: "Generate extensions for all identified gaps"
159
+ - label: "Select individually"
160
+ description: "Choose which gaps to model"
161
+ - label: "Skip"
162
+ description: "No extensions needed, proceed to analysis"
163
+ ```
164
+
165
+ ---
166
+
167
+ ### Step 4: Create Data Extension Files
168
+
169
+ **Entry:** Step 3 identified gaps and user confirmed which to model
170
+ **Exit:** YAML extension files created in `$OUTPUT_DIR/extensions/` and deployed to `<lang>-all` ext/ directory
171
+
172
+ Generate YAML data extension files for the gaps confirmed by the user.
173
+
174
+ #### File Structure
175
+
176
+ Create files in `$OUTPUT_DIR/extensions/`:
177
+
178
+ ```
179
+ $OUTPUT_DIR/extensions/
180
+ sources.yml # sourceModel entries
181
+ sinks.yml # sinkModel entries
182
+ summaries.yml # summaryModel and neutralModel entries
183
+ ```
184
+
185
+ #### YAML Format and Deployment
186
+
187
+ See [extension-yaml-format.md](../references/extension-yaml-format.md) for column definitions, per-language examples (Python, Java, JS, Go, C/C++), and the deployment workaround for pre-compiled query packs.
188
+
189
+ Use the `Write` tool to create each file. Only create files that have entries — skip empty categories.
190
+
191
+ ---
192
+
193
+ ### Step 5: Validate with Re-Analysis
194
+
195
+ **Entry:** Step 4 complete (extension files deployed)
196
+ **Exit:** Finding delta measured (with-extensions count >= baseline count); extensions validated as loading correctly
197
+
198
+ Run a full security analysis with and without extensions to measure the finding delta.
199
+
200
+ #### 5a: Run Baseline Analysis (without extensions)
201
+
202
+ Validation artifacts go in `$DIAG_DIR` (not `results/`) since these are intermediate comparisons, not the final analysis output.
203
+
204
+ ```bash
205
+ codeql database analyze "$DB_NAME" \
206
+ --format=sarif-latest --output="$DIAG_DIR/baseline.sarif" --threads=0 \
207
+ -- codeql/<lang>-queries:codeql-suites/<lang>-security-extended.qls
208
+ ```
209
+
210
+ #### 5b: Run Analysis with Extensions
211
+
212
+ ```bash
213
+ codeql database cleanup "$DB_NAME"
214
+ codeql database analyze "$DB_NAME" \
215
+ --format=sarif-latest --output="$DIAG_DIR/with-extensions.sarif" --threads=0 --rerun \
216
+ -- codeql/<lang>-queries:codeql-suites/<lang>-security-extended.qls
217
+ ```
218
+
219
+ Use `-vvv` flag to verify extensions are being loaded.
220
+
221
+ #### 5c: Compare Findings
222
+
223
+ ```bash
224
+ BASELINE=$(python3 -c "import json; print(sum(len(r.get('results',[])) for r in json.load(open('$DIAG_DIR/baseline.sarif')).get('runs',[])))")
225
+ WITH_EXT=$(python3 -c "import json; print(sum(len(r.get('results',[])) for r in json.load(open('$DIAG_DIR/with-extensions.sarif')).get('runs',[])))")
226
+ echo "Findings: $BASELINE → $WITH_EXT (+$((WITH_EXT - BASELINE)))"
227
+ ```
228
+
229
+ **If counts did not increase:** Check extension loading (`-vvv`), pre-compiled pack workaround, Java `True`/`False` capitalization, column value accuracy.
230
+
231
+ ---
232
+
233
+ ## Final Output
234
+
235
+ ```
236
+ ## Data Extensions Created
237
+
238
+ **Output directory:** $OUTPUT_DIR
239
+ **Database:** $DB_NAME
240
+ **Language:** <LANG>
241
+
242
+ ### Files Created:
243
+ - $OUTPUT_DIR/extensions/sources.yml — <N> source models
244
+ - $OUTPUT_DIR/extensions/sinks.yml — <N> sink models
245
+ - $OUTPUT_DIR/extensions/summaries.yml — <N> summary/neutral models
246
+
247
+ ### Model Coverage:
248
+ - Sources: <BEFORE> → <AFTER> (+<DELTA>)
249
+ - Sinks: <BEFORE> → <AFTER> (+<DELTA>)
250
+
251
+ ### Usage:
252
+ Extensions deployed to `<lang>-all` ext/ directory (auto-loaded).
253
+ Source files in `$OUTPUT_DIR/extensions/` for version control.
254
+ Run the run-analysis workflow to use them.
255
+ ```
256
+
257
+ ## References
258
+
259
+ - [Threat models reference](../references/threat-models.md) — control which source categories are active during analysis
260
+ - [CodeQL data extensions](https://codeql.github.com/docs/codeql-cli/using-custom-queries-with-the-codeql-cli/#using-extension-packs)
261
+ - [Customizing library models](https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-python/)
@@ -0,0 +1,301 @@
1
+ # Run Analysis Workflow
2
+
3
+ Execute CodeQL security queries on an existing database with ruleset selection and result formatting.
4
+
5
+ ## Scan Modes
6
+
7
+ Two modes control analysis scope. Both use all installed packs — the difference is filtering.
8
+
9
+ | Mode | Description | Suite Reference |
10
+ |------|-------------|-----------------|
11
+ | **Run all** | All queries from all installed packs via `security-and-quality` suite | [run-all-suite.md](../references/run-all-suite.md) |
12
+ | **Important only** | Security queries filtered by precision and security-severity threshold | [important-only-suite.md](../references/important-only-suite.md) |
13
+
14
+ > **WARNING:** Do NOT pass pack names directly to `codeql database analyze` (e.g., `-- codeql/cpp-queries`). Each pack's `defaultSuiteFile` silently applies strict filters and can produce zero results. Always use an explicit suite reference.
15
+
16
+ ---
17
+
18
+ ## Task System
19
+
20
+ Create these tasks on workflow start:
21
+
22
+ ```
23
+ TaskCreate: "Select database and detect language" (Step 1)
24
+ TaskCreate: "Select scan mode, check additional packs" (Step 2) - blockedBy: Step 1
25
+ TaskCreate: "Select query packs, model packs, and threat models" (Step 3) - blockedBy: Step 2
26
+ TaskCreate: "Execute analysis" (Step 4) - blockedBy: Step 3
27
+ TaskCreate: "Process and report results" (Step 5) - blockedBy: Step 4
28
+ ```
29
+
30
+ ### Gates
31
+
32
+ | Task | Gate Type | Cannot Proceed Until |
33
+ |------|-----------|---------------------|
34
+ | Step 2 | **SOFT GATE** | User selects mode; confirms installed/ignored for each missing pack |
35
+ | Step 3 | **SOFT GATE** | User approves query packs, model packs, and threat model selection |
36
+
37
+ **Auto-skip rule:** If the user already specified a choice in the invocation, skip the corresponding `AskUserQuestion` and use the provided value directly.
38
+
39
+ ---
40
+
41
+ ## Steps
42
+
43
+ ### Step 1: Select Database and Detect Language
44
+
45
+ **Entry:** `$OUTPUT_DIR` is set (from parent skill). `$DB_NAME` may already be set if the parent skill resolved database selection.
46
+ **Exit:** `DB_NAME` and `CODEQL_LANG` variables set; database resolves successfully.
47
+
48
+ **If `$DB_NAME` is already set** (parent skill handled database selection): validate it and proceed.
49
+
50
+ **If `$DB_NAME` is not set:** discover databases by looking for `codeql-database.yml` marker files. Search inside `$OUTPUT_DIR` first, then fall back to the project root (top-level and one subdirectory deep).
51
+
52
+ ```bash
53
+ # Skip discovery if DB_NAME was already resolved by parent skill
54
+ if [ -z "$DB_NAME" ]; then
55
+ # Discover databases inside OUTPUT_DIR
56
+ FOUND_DBS=()
57
+ while IFS= read -r yml; do
58
+ FOUND_DBS+=("$(dirname "$yml")")
59
+ done < <(find "$OUTPUT_DIR" -maxdepth 2 -name "codeql-database.yml" 2>/dev/null)
60
+
61
+ # Fallback: search project root (top-level and one subdir deep)
62
+ if [ ${#FOUND_DBS[@]} -eq 0 ]; then
63
+ while IFS= read -r yml; do
64
+ FOUND_DBS+=("$(dirname "$yml")")
65
+ done < <(find . -maxdepth 3 -name "codeql-database.yml" -not -path "*/\.*" 2>/dev/null)
66
+ fi
67
+
68
+ if [ ${#FOUND_DBS[@]} -eq 0 ]; then
69
+ echo "ERROR: No CodeQL database found in $OUTPUT_DIR or project root"
70
+ exit 1
71
+ elif [ ${#FOUND_DBS[@]} -eq 1 ]; then
72
+ DB_NAME="${FOUND_DBS[0]}"
73
+ else
74
+ # Multiple databases found — present to user
75
+ # Use AskUserQuestion with each DB's path and language
76
+ # SKIP if user already specified which database in their prompt
77
+ fi
78
+ fi
79
+
80
+ CODEQL_LANG=$(codeql resolve database --format=json -- "$DB_NAME" | jq -r '.languages[0]')
81
+ echo "Using: $DB_NAME (language: $CODEQL_LANG)"
82
+ ```
83
+
84
+ **When multiple databases are found**, use `AskUserQuestion` to let user select — list each database with its path and language. **Skip `AskUserQuestion` if the user already specified which database to use in their prompt.**
85
+
86
+ If multi-language database, ask which language to analyze.
87
+
88
+ ---
89
+
90
+ ### Step 2: Select Scan Mode, Check Additional Packs
91
+
92
+ **Entry:** Step 1 complete (`DB_NAME` and `CODEQL_LANG` set)
93
+ **Exit:** Scan mode selected; all available packs (official, ToB, community) checked for installation status; model packs detected
94
+
95
+ #### 2a: Select Scan Mode
96
+
97
+ **Skip if user already specified.** Otherwise use `AskUserQuestion`:
98
+
99
+ ```
100
+ header: "Scan Mode"
101
+ question: "Which scan mode should be used?"
102
+ options:
103
+ - label: "Run all (Recommended)"
104
+ description: "Maximum coverage — all queries from all installed packs"
105
+ - label: "Important only"
106
+ description: "Security vulnerabilities only — medium-high precision, security-severity threshold"
107
+ ```
108
+
109
+ #### 2b: Query Packs
110
+
111
+ For each pack available for the detected language (see [ruleset-catalog.md](../references/ruleset-catalog.md)):
112
+
113
+ | Language | Trail of Bits | Community Pack |
114
+ |----------|---------------|----------------|
115
+ | C/C++ | `trailofbits/cpp-queries` | `GitHubSecurityLab/CodeQL-Community-Packs-CPP` |
116
+ | Go | `trailofbits/go-queries` | `GitHubSecurityLab/CodeQL-Community-Packs-Go` |
117
+ | Java | `trailofbits/java-queries` | `GitHubSecurityLab/CodeQL-Community-Packs-Java` |
118
+ | JavaScript | — | `GitHubSecurityLab/CodeQL-Community-Packs-JavaScript` |
119
+ | Python | — | `GitHubSecurityLab/CodeQL-Community-Packs-Python` |
120
+ | C# | — | `GitHubSecurityLab/CodeQL-Community-Packs-CSharp` |
121
+ | Ruby | — | `GitHubSecurityLab/CodeQL-Community-Packs-Ruby` |
122
+
123
+ Check if installed (`codeql resolve qlpacks | grep -i "<PACK_NAME>"`). If not, ask user to install or ignore.
124
+
125
+ #### 2c: Detect Model Packs
126
+
127
+ Search three locations for data extension model packs:
128
+ 1. **In-repo model packs** — `qlpack.yml`/`codeql-pack.yml` with `dataExtensions`
129
+ 2. **In-repo standalone data extensions** — `.yml` files with `extensions:` key
130
+ 3. **Installed model packs** — resolved by CodeQL
131
+
132
+ Record all detected packs for Step 3.
133
+
134
+ ---
135
+
136
+ ### Step 3: Select Query Packs and Model Packs
137
+
138
+ **Entry:** Step 2 complete (scan mode, pack availability, and model packs all determined)
139
+ **Exit:** User confirmed query packs, model packs, and threat model selection; all flags built (`THREAT_MODEL_FLAG`, `MODEL_PACK_FLAGS`, `ADDITIONAL_PACK_FLAGS`)
140
+
141
+ > **CHECKPOINT** — Present available packs to user for confirmation.
142
+ > **Skip if user already specified pack preferences.**
143
+
144
+ #### 3a: Confirm Query Packs
145
+
146
+ **Important-only mode:** Inform user all installed packs included with filtering. Proceed to 3b.
147
+
148
+ **Run-all mode:** Use `AskUserQuestion` to confirm "Use all" or "Select individually".
149
+
150
+ #### 3b: Select Model Packs (if any detected)
151
+
152
+ **Skip if no model packs detected in Step 2c.**
153
+
154
+ Use `AskUserQuestion`: "Use all (Recommended)" / "Select individually" / "Skip".
155
+
156
+ **Notes:**
157
+ - In-repo standalone extensions (`.yml`) are auto-discovered — pass source directory via `--additional-packs`
158
+ - In-repo model packs (with `qlpack.yml`) need parent directory via `--additional-packs`
159
+ - Installed model packs use `--model-packs`
160
+
161
+ #### 3c: Select Threat Models
162
+
163
+ Threat models control which input sources CodeQL treats as tainted. See [threat-models.md](../references/threat-models.md).
164
+
165
+ Use `AskUserQuestion`:
166
+
167
+ ```
168
+ header: "Threat Models"
169
+ question: "Which input sources should CodeQL treat as tainted?"
170
+ options:
171
+ - label: "Remote only (Recommended)"
172
+ description: "Default — HTTP requests, network input"
173
+ - label: "Remote + Local"
174
+ description: "Add CLI args, local files"
175
+ - label: "All sources"
176
+ description: "Remote, local, environment, database, file"
177
+ - label: "Custom"
178
+ description: "Select specific threat models individually"
179
+ ```
180
+
181
+ Build the flag: `THREAT_MODEL_FLAG=""` (remote only needs no flag), `--threat-model local`, etc.
182
+
183
+ ---
184
+
185
+ ### Step 4: Execute Analysis
186
+
187
+ **Entry:** Step 3 complete (all flags and pack selections finalized)
188
+ **Exit:** `$RAW_DIR/results.sarif` exists and contains valid SARIF output
189
+
190
+ #### Log selected query packs
191
+
192
+ Write the selected query packs, model packs, and threat models to `$OUTPUT_DIR/rulesets.txt`:
193
+
194
+ ```bash
195
+ cat > "$OUTPUT_DIR/rulesets.txt" << RULESETS
196
+ # CodeQL Analysis — Selected Query Packs
197
+ # Generated: $(date -Iseconds)
198
+ # Scan mode: <run-all|important-only>
199
+ # Database: $DB_NAME
200
+ # Language: $CODEQL_LANG
201
+
202
+ ## Query packs:
203
+ <one pack per line>
204
+
205
+ ## Model packs:
206
+ <one pack per line, or "None">
207
+
208
+ ## Threat models:
209
+ <threat model selection, or "default (remote)">
210
+ RULESETS
211
+ ```
212
+
213
+ #### Generate custom suite
214
+
215
+ **Important-only mode:** Generate the custom `.qls` suite using the template and script in [important-only-suite.md](../references/important-only-suite.md).
216
+
217
+ **Run-all mode:** Generate the custom `.qls` suite using the template in [run-all-suite.md](../references/run-all-suite.md).
218
+
219
+ ```bash
220
+ RAW_DIR="$OUTPUT_DIR/raw"
221
+ RESULTS_DIR="$OUTPUT_DIR/results"
222
+ mkdir -p "$RAW_DIR" "$RESULTS_DIR"
223
+ SUITE_FILE="$RAW_DIR/<mode>.qls"
224
+
225
+ # Verify suite resolves correctly before running
226
+ codeql resolve queries "$SUITE_FILE" | wc -l
227
+ ```
228
+
229
+ #### Run analysis
230
+
231
+ Output goes to `$RAW_DIR/results.sarif` (unfiltered). The final results are produced in Step 5.
232
+
233
+ ```bash
234
+ codeql database analyze $DB_NAME \
235
+ --format=sarif-latest \
236
+ --output="$RAW_DIR/results.sarif" \
237
+ --threads=0 \
238
+ $THREAT_MODEL_FLAG \
239
+ $MODEL_PACK_FLAGS \
240
+ $ADDITIONAL_PACK_FLAGS \
241
+ -- "$SUITE_FILE"
242
+ ```
243
+
244
+ **Flag reference for model packs:**
245
+
246
+ | Source | Flag | Example |
247
+ |--------|------|---------|
248
+ | Installed model packs | `--model-packs` | `--model-packs=myorg/java-models` |
249
+ | In-repo model packs | `--additional-packs` | `--additional-packs=./lib/codeql-models` |
250
+ | In-repo standalone extensions | `--additional-packs` | `--additional-packs=.` |
251
+
252
+ ### Performance
253
+
254
+ If codebase is large, read [performance-tuning.md](../references/performance-tuning.md) and apply relevant optimizations.
255
+
256
+ ---
257
+
258
+ ### Step 5: Process and Report Results
259
+
260
+ **Entry:** Step 4 complete (`$RAW_DIR/results.sarif` exists)
261
+ **Exit:** `$RESULTS_DIR/results.sarif` contains final results; findings summarized by severity, rule, and location; zero-finding results investigated; final report presented to user
262
+
263
+ #### Produce final results
264
+
265
+ - **Run-all mode:** Copy unfiltered results to the final location:
266
+ ```bash
267
+ cp "$RAW_DIR/results.sarif" "$RESULTS_DIR/results.sarif"
268
+ ```
269
+
270
+ - **Important-only mode:** Apply the post-analysis filter from [sarif-processing.md](../references/sarif-processing.md#important-only-post-filter) to remove medium-precision results with `security-severity` < 6.0. The filter reads from `$RAW_DIR/results.sarif` and writes to `$RESULTS_DIR/results.sarif`, preserving the unfiltered original.
271
+
272
+ Process the final SARIF output (`$RESULTS_DIR/results.sarif`) using the jq commands in [sarif-processing.md](../references/sarif-processing.md): count findings, summarize by level, summarize by security severity, summarize by rule.
273
+
274
+ ---
275
+
276
+ ## Final Output
277
+
278
+ Report to user:
279
+
280
+ ```
281
+ ## CodeQL Analysis Complete
282
+
283
+ **Output directory:** $OUTPUT_DIR
284
+ **Database:** $DB_NAME
285
+ **Language:** <LANG>
286
+ **Scan mode:** Run all | Important only
287
+ **Query packs:** <list of query packs used>
288
+ **Model packs:** <list of model packs used, or "None">
289
+ **Threat models:** <list of threat models, or "default (remote)">
290
+
291
+ ### Results Summary:
292
+ - Total findings: <N>
293
+ - Error: <N>
294
+ - Warning: <N>
295
+ - Note: <N>
296
+
297
+ ### Output Files:
298
+ - SARIF (final): $OUTPUT_DIR/results/results.sarif
299
+ - SARIF (unfiltered): $OUTPUT_DIR/raw/results.sarif
300
+ - Rulesets: $OUTPUT_DIR/rulesets.txt
301
+ ```