@openai/codex-security 0.3.0 → 0.5.0

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 (244) hide show
  1. package/README.md +45 -9
  2. package/_bundled_plugin/.codex-plugin/plugin.json +5 -5
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  7. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +13 -20
  8. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  9. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  10. package/_bundled_plugin/references/core-scan.md +2 -0
  11. package/_bundled_plugin/references/final-report.md +5 -1
  12. package/_bundled_plugin/references/investigation-time-budget.md +11 -0
  13. package/_bundled_plugin/references/sarif-adapter.md +1 -0
  14. package/_bundled_plugin/references/scan-prologue.md +2 -6
  15. package/_bundled_plugin/references/scan-runtime.md +15 -0
  16. package/_bundled_plugin/references/threat-model.md +2 -0
  17. package/_bundled_plugin/schemas/coverage.schema.json +45 -126
  18. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
  19. package/_bundled_plugin/schemas/findings.schema.json +140 -427
  20. package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
  21. package/_bundled_plugin/schemas/scan-manifest.schema.json +73 -188
  22. package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
  23. package/_bundled_plugin/scripts/finalize_scan_contract.py +87 -49
  24. package/_bundled_plugin/scripts/finding_preview.py +5 -3
  25. package/_bundled_plugin/scripts/generate_rank_input.py +26 -106
  26. package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
  27. package/_bundled_plugin/scripts/report_projection.py +35 -13
  28. package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
  29. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
  30. package/_bundled_plugin/scripts/workbench_cli.py +9 -9
  31. package/_bundled_plugin/scripts/workbench_constants.py +4 -0
  32. package/_bundled_plugin/scripts/workbench_db.py +103 -45
  33. package/_bundled_plugin/scripts/workbench_progress.py +0 -50
  34. package/_bundled_plugin/scripts/workbench_publication.py +216 -247
  35. package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
  36. package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
  37. package/_bundled_plugin/scripts/workbench_scan_usage.py +360 -37
  38. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  39. package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
  40. package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
  41. package/_bundled_plugin/scripts/workbench_target.py +7 -5
  42. package/_bundled_plugin/scripts/workbench_validation.py +52 -2
  43. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
  44. package/_bundled_plugin/shared/workbench-migrations.json +22 -0
  45. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  46. package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
  47. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
  48. package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
  49. package/_bundled_plugin/skills/security-scan/SKILL.md +4 -2
  50. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
  51. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -3
  52. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +2 -0
  53. package/_bundled_plugin/skills/track-findings/SKILL.md +8 -4
  54. package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
  55. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +1 -1
  56. package/dist/api.d.ts +6 -2
  57. package/dist/api.d.ts.map +1 -1
  58. package/dist/api.js +266 -39
  59. package/dist/api.js.map +1 -1
  60. package/dist/artifact-export.d.ts +2 -1
  61. package/dist/artifact-export.d.ts.map +1 -1
  62. package/dist/artifact-export.js +38 -23
  63. package/dist/artifact-export.js.map +1 -1
  64. package/dist/classify-severity-records.d.ts +76 -0
  65. package/dist/classify-severity-records.d.ts.map +1 -0
  66. package/dist/classify-severity-records.js +141 -0
  67. package/dist/classify-severity-records.js.map +1 -0
  68. package/dist/classify-severity.d.ts +1 -23
  69. package/dist/classify-severity.d.ts.map +1 -1
  70. package/dist/classify-severity.js +3 -24
  71. package/dist/classify-severity.js.map +1 -1
  72. package/dist/cli-help.d.ts.map +1 -1
  73. package/dist/cli-help.js +2 -0
  74. package/dist/cli-help.js.map +1 -1
  75. package/dist/cli.d.ts +4 -2
  76. package/dist/cli.d.ts.map +1 -1
  77. package/dist/cli.js +148 -149
  78. package/dist/cli.js.map +1 -1
  79. package/dist/cloud-publish.js +1 -1
  80. package/dist/cloud-publish.js.map +1 -1
  81. package/dist/codex-sdk-environment.js +1 -1
  82. package/dist/codex-sdk-environment.js.map +1 -1
  83. package/dist/component-plan.js +1 -1
  84. package/dist/component-plan.js.map +1 -1
  85. package/dist/component-scan.d.ts.map +1 -1
  86. package/dist/component-scan.js +5 -4
  87. package/dist/component-scan.js.map +1 -1
  88. package/dist/config.d.ts +12 -0
  89. package/dist/config.d.ts.map +1 -1
  90. package/dist/config.js +10 -4
  91. package/dist/config.js.map +1 -1
  92. package/dist/contract.d.ts +6 -0
  93. package/dist/contract.d.ts.map +1 -1
  94. package/dist/contract.js +69 -20
  95. package/dist/contract.js.map +1 -1
  96. package/dist/cost-model.d.ts.map +1 -1
  97. package/dist/cost-model.js +7 -2
  98. package/dist/cost-model.js.map +1 -1
  99. package/dist/custom-validation-prompt.js +3 -3
  100. package/dist/custom-validation-prompt.js.map +1 -1
  101. package/dist/deduplication/codex-review.d.ts +1 -5
  102. package/dist/deduplication/codex-review.d.ts.map +1 -1
  103. package/dist/deduplication/codex-review.js +2 -2
  104. package/dist/deduplication/codex-review.js.map +1 -1
  105. package/dist/deduplication/deduplication-prompts.d.ts +1 -1
  106. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  107. package/dist/deduplication/deduplication-prompts.js +2 -2
  108. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  109. package/dist/deduplication/deduplication-reviewer.d.ts +1 -1
  110. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  111. package/dist/deduplication/deduplication-reviewer.js +1 -1
  112. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  113. package/dist/deduplication/records-protocol.d.ts +3 -8
  114. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  115. package/dist/deduplication/records-protocol.js +11 -171
  116. package/dist/deduplication/records-protocol.js.map +1 -1
  117. package/dist/deduplication/records.js +1 -1
  118. package/dist/deduplication/records.js.map +1 -1
  119. package/dist/deduplication/scan.d.ts.map +1 -1
  120. package/dist/deduplication/scan.js +10 -9
  121. package/dist/deduplication/scan.js.map +1 -1
  122. package/dist/deep-config.d.ts +4 -1
  123. package/dist/deep-config.d.ts.map +1 -1
  124. package/dist/deep-config.js +21 -1
  125. package/dist/deep-config.js.map +1 -1
  126. package/dist/deep-progress.d.ts +15 -1
  127. package/dist/deep-progress.d.ts.map +1 -1
  128. package/dist/deep-progress.js +15 -16
  129. package/dist/deep-progress.js.map +1 -1
  130. package/dist/executable-path.d.ts +2 -0
  131. package/dist/executable-path.d.ts.map +1 -0
  132. package/dist/executable-path.js +12 -0
  133. package/dist/executable-path.js.map +1 -0
  134. package/dist/feedback.d.ts +1 -4
  135. package/dist/feedback.d.ts.map +1 -1
  136. package/dist/feedback.js +1 -1
  137. package/dist/feedback.js.map +1 -1
  138. package/dist/findings-import.d.ts +1 -1
  139. package/dist/findings-import.d.ts.map +1 -1
  140. package/dist/findings-import.js +3 -3
  141. package/dist/findings-import.js.map +1 -1
  142. package/dist/git-remote.d.ts +10 -0
  143. package/dist/git-remote.d.ts.map +1 -0
  144. package/dist/git-remote.js +24 -0
  145. package/dist/git-remote.js.map +1 -0
  146. package/dist/github.d.ts.map +1 -1
  147. package/dist/github.js +5 -7
  148. package/dist/github.js.map +1 -1
  149. package/dist/host-protocol.d.ts +19 -0
  150. package/dist/host-protocol.d.ts.map +1 -0
  151. package/dist/host-protocol.js +270 -0
  152. package/dist/host-protocol.js.map +1 -0
  153. package/dist/host-records-protocol.d.ts +15 -0
  154. package/dist/host-records-protocol.d.ts.map +1 -0
  155. package/dist/host-records-protocol.js +15 -0
  156. package/dist/host-records-protocol.js.map +1 -0
  157. package/dist/hosted-scan-protocol.d.ts +4 -0
  158. package/dist/hosted-scan-protocol.d.ts.map +1 -0
  159. package/dist/hosted-scan-protocol.js +25 -0
  160. package/dist/hosted-scan-protocol.js.map +1 -0
  161. package/dist/hosted-scan.d.ts +112 -0
  162. package/dist/hosted-scan.d.ts.map +1 -0
  163. package/dist/hosted-scan.js +260 -0
  164. package/dist/hosted-scan.js.map +1 -0
  165. package/dist/index.d.ts +7 -0
  166. package/dist/index.d.ts.map +1 -1
  167. package/dist/index.js +3 -0
  168. package/dist/index.js.map +1 -1
  169. package/dist/knowledge-base.d.ts.map +1 -1
  170. package/dist/knowledge-base.js +87 -7
  171. package/dist/knowledge-base.js.map +1 -1
  172. package/dist/multiscan.d.ts.map +1 -1
  173. package/dist/multiscan.js +108 -36
  174. package/dist/multiscan.js.map +1 -1
  175. package/dist/patch-publication.d.ts +26 -0
  176. package/dist/patch-publication.d.ts.map +1 -0
  177. package/dist/patch-publication.js +105 -0
  178. package/dist/patch-publication.js.map +1 -0
  179. package/dist/patch-tui.d.ts.map +1 -1
  180. package/dist/patch-tui.js +4 -1
  181. package/dist/patch-tui.js.map +1 -1
  182. package/dist/project-config-schema.d.ts +2 -0
  183. package/dist/project-config-schema.d.ts.map +1 -1
  184. package/dist/project-config-schema.js +1 -0
  185. package/dist/project-config-schema.js.map +1 -1
  186. package/dist/project-config.d.ts +1 -0
  187. package/dist/project-config.d.ts.map +1 -1
  188. package/dist/project-config.js +16 -6
  189. package/dist/project-config.js.map +1 -1
  190. package/dist/publication-store.d.ts.map +1 -1
  191. package/dist/publication-store.js +73 -63
  192. package/dist/publication-store.js.map +1 -1
  193. package/dist/publication.d.ts +0 -2
  194. package/dist/publication.d.ts.map +1 -1
  195. package/dist/publication.js +135 -24
  196. package/dist/publication.js.map +1 -1
  197. package/dist/publish.d.ts.map +1 -1
  198. package/dist/publish.js +39 -25
  199. package/dist/publish.js.map +1 -1
  200. package/dist/runtime.d.ts +5 -2
  201. package/dist/runtime.d.ts.map +1 -1
  202. package/dist/runtime.js +86 -58
  203. package/dist/runtime.js.map +1 -1
  204. package/dist/scan-executor.d.ts +104 -0
  205. package/dist/scan-executor.d.ts.map +1 -0
  206. package/dist/scan-executor.js +62 -0
  207. package/dist/scan-executor.js.map +1 -0
  208. package/dist/scan-settings.d.ts +1 -0
  209. package/dist/scan-settings.d.ts.map +1 -1
  210. package/dist/scan-settings.js +7 -1
  211. package/dist/scan-settings.js.map +1 -1
  212. package/dist/scan-time-budget.d.ts +9 -0
  213. package/dist/scan-time-budget.d.ts.map +1 -0
  214. package/dist/scan-time-budget.js +16 -0
  215. package/dist/scan-time-budget.js.map +1 -0
  216. package/dist/severity-review.d.ts +29 -0
  217. package/dist/severity-review.d.ts.map +1 -0
  218. package/dist/severity-review.js +47 -0
  219. package/dist/severity-review.js.map +1 -0
  220. package/dist/targets.d.ts.map +1 -1
  221. package/dist/targets.js +17 -25
  222. package/dist/targets.js.map +1 -1
  223. package/dist/validation-records.d.ts +38 -0
  224. package/dist/validation-records.d.ts.map +1 -0
  225. package/dist/validation-records.js +76 -0
  226. package/dist/validation-records.js.map +1 -0
  227. package/dist/version.d.ts.map +1 -1
  228. package/dist/version.js +4 -2
  229. package/dist/version.js.map +1 -1
  230. package/dist/worker-progress.d.ts +43 -15
  231. package/dist/worker-progress.d.ts.map +1 -1
  232. package/dist/worker-progress.js +22 -80
  233. package/dist/worker-progress.js.map +1 -1
  234. package/docs/classify-severity-records.md +89 -0
  235. package/docs/cli.md +281 -35
  236. package/docs/hosted-scans.md +242 -0
  237. package/docs/validate-records.md +69 -0
  238. package/package.json +18 -14
  239. package/schemas/hosted-scan-v2.fixture.json +145 -0
  240. package/schemas/project-config.schema.json +7 -1
  241. package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
  242. package/_bundled_plugin/references/config-preflight.md +0 -93
  243. package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
  244. package/_bundled_plugin/scripts/config_preflight.py +0 -911
@@ -1,68 +1,31 @@
1
1
  {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
2
  "$id": "https://openai.com/codex-security/schemas/scan-manifest.schema.json",
4
3
  "title": "Codex Security sealed scan manifest",
4
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
5
5
  "type": "object",
6
- "required": ["documentType", "schemaVersion", "scan"],
7
6
  "properties": {
8
- "documentType": {
9
- "const": "codex-security.scan-manifest"
10
- },
11
- "schemaVersion": {
12
- "const": "1.0"
13
- },
7
+ "documentType": { "const": "codex-security.scan-manifest" },
8
+ "schemaVersion": { "const": "1.0" },
14
9
  "scan": {
15
10
  "type": "object",
16
- "required": [
17
- "id",
18
- "producer",
19
- "status",
20
- "startedAt",
21
- "completedAt",
22
- "sealedAt",
23
- "target",
24
- "scope",
25
- "coverageRef",
26
- "findingsRef",
27
- "artifacts"
28
- ],
29
11
  "properties": {
30
- "id": {
31
- "type": "string",
32
- "minLength": 1
33
- },
12
+ "id": { "type": "string", "minLength": 1 },
34
13
  "producer": {
35
14
  "type": "object",
36
- "required": ["name", "version"],
37
15
  "properties": {
38
- "name": {
39
- "type": "string",
40
- "minLength": 1
41
- },
42
- "version": {
43
- "type": "string",
44
- "minLength": 1
45
- }
46
- }
16
+ "name": { "type": "string", "minLength": 1 },
17
+ "version": { "type": "string", "minLength": 1 }
18
+ },
19
+ "required": ["name", "version"]
47
20
  },
48
21
  "status": {
49
22
  "enum": ["completed", "failed", "canceled", "interrupted"]
50
23
  },
51
- "startedAt": {
52
- "type": "string",
53
- "format": "date-time"
54
- },
55
- "completedAt": {
56
- "type": "string",
57
- "format": "date-time"
58
- },
59
- "sealedAt": {
60
- "type": "string",
61
- "format": "date-time"
62
- },
24
+ "startedAt": { "type": "string", "format": "date-time" },
25
+ "completedAt": { "type": "string", "format": "date-time" },
26
+ "sealedAt": { "type": "string", "format": "date-time" },
63
27
  "target": {
64
28
  "type": "object",
65
- "required": ["kind", "targetId", "displayName"],
66
29
  "properties": {
67
30
  "kind": {
68
31
  "enum": [
@@ -72,44 +35,25 @@
72
35
  "directory_snapshot"
73
36
  ]
74
37
  },
75
- "targetId": {
76
- "type": "string",
77
- "minLength": 1
78
- },
79
- "displayName": {
80
- "type": "string",
81
- "minLength": 1
82
- },
38
+ "targetId": { "type": "string", "minLength": 1 },
39
+ "displayName": { "type": "string", "minLength": 1 },
83
40
  "remote": {
84
41
  "type": "string",
85
42
  "pattern": "^(?![^:/?#]+://[^/?#]*@)[^?#]+$"
86
43
  },
87
- "revision": {
88
- "type": "string"
89
- },
90
- "baseRevision": {
91
- "type": "string"
92
- },
93
- "headRevision": {
94
- "type": "string"
95
- },
44
+ "revision": { "type": "string" },
45
+ "baseRevision": { "type": "string" },
46
+ "headRevision": { "type": "string" },
96
47
  "snapshotDigest": {
97
48
  "type": "string",
98
49
  "pattern": "^codex-security-snapshot/v1:sha256:[a-f0-9]{64}$"
99
50
  }
100
51
  },
52
+ "required": ["kind", "targetId", "displayName"],
101
53
  "allOf": [
102
54
  {
103
- "if": {
104
- "properties": {
105
- "kind": {
106
- "const": "git_revision"
107
- }
108
- }
109
- },
110
- "then": {
111
- "required": ["revision"]
112
- }
55
+ "if": { "properties": { "kind": { "const": "git_revision" } } },
56
+ "then": { "required": ["revision"] }
113
57
  },
114
58
  {
115
59
  "if": {
@@ -119,86 +63,42 @@
119
63
  }
120
64
  }
121
65
  },
122
- "then": {
123
- "required": ["snapshotDigest"]
124
- }
66
+ "then": { "required": ["snapshotDigest"] }
125
67
  }
126
68
  ]
127
69
  },
128
70
  "scope": {
129
71
  "type": "object",
130
- "required": ["includePaths", "excludePaths"],
131
72
  "properties": {
132
- "includePaths": {
133
- "type": "array",
134
- "items": {
135
- "type": "string"
136
- }
137
- },
138
- "excludePaths": {
139
- "type": "array",
140
- "items": {
141
- "type": "string"
142
- }
143
- },
144
- "summary": {
145
- "type": "string",
146
- "minLength": 1
147
- },
148
- "artifactsReviewed": {
149
- "$ref": "#/$defs/stringList"
150
- },
151
- "runtimeStatus": {
152
- "type": "string",
153
- "minLength": 1
154
- },
155
- "validationMode": {
156
- "type": "string",
157
- "minLength": 1
158
- },
159
- "context": {
160
- "type": "string",
161
- "minLength": 1
162
- },
163
- "limitations": {
164
- "$ref": "#/$defs/stringList"
165
- }
166
- }
73
+ "includePaths": { "type": "array", "items": { "type": "string" } },
74
+ "excludePaths": { "type": "array", "items": { "type": "string" } },
75
+ "summary": { "type": "string", "minLength": 1 },
76
+ "artifactsReviewed": { "$ref": "#/$defs/stringList" },
77
+ "runtimeStatus": { "type": "string", "minLength": 1 },
78
+ "validationMode": { "type": "string", "minLength": 1 },
79
+ "context": { "type": "string", "minLength": 1 },
80
+ "limitations": { "$ref": "#/$defs/stringList" }
81
+ },
82
+ "required": ["includePaths", "excludePaths"]
167
83
  },
168
84
  "threatModel": {
169
- "description": "Retained threat-model content. Existing structured models remain supported; Markdown documents preserve their complete original body.",
170
85
  "anyOf": [
171
86
  {
172
87
  "type": "object",
173
- "required": ["summary"],
174
88
  "properties": {
175
- "summary": {
176
- "type": "string",
177
- "minLength": 1
178
- },
179
- "assets": {
180
- "$ref": "#/$defs/stringList"
181
- },
182
- "trustBoundaries": {
183
- "$ref": "#/$defs/stringList"
184
- },
185
- "attackerCapabilities": {
186
- "$ref": "#/$defs/stringList"
187
- },
188
- "securityObjectives": {
189
- "$ref": "#/$defs/stringList"
190
- },
191
- "assumptions": {
192
- "$ref": "#/$defs/stringList"
193
- }
194
- }
89
+ "summary": { "type": "string", "minLength": 1 },
90
+ "assets": { "$ref": "#/$defs/stringList" },
91
+ "trustBoundaries": { "$ref": "#/$defs/stringList" },
92
+ "attackerCapabilities": { "$ref": "#/$defs/stringList" },
93
+ "securityObjectives": { "$ref": "#/$defs/stringList" },
94
+ "assumptions": { "$ref": "#/$defs/stringList" }
95
+ },
96
+ "required": ["summary"]
195
97
  },
196
98
  {
197
99
  "type": "object",
198
100
  "properties": {
199
- "format": {
200
- "const": "markdown"
201
- },
101
+ "format": { "const": "markdown" },
202
102
  "content": {
203
103
  "type": "string",
204
104
  "minLength": 1,
@@ -206,21 +106,14 @@
206
106
  },
207
107
  "scope": {
208
108
  "type": "object",
209
- "description": "The modeled source scope, which may differ from the scan scope. Omit when unknown.",
210
109
  "properties": {
211
- "includePaths": {
212
- "$ref": "#/$defs/stringList"
213
- },
214
- "excludePaths": {
215
- "$ref": "#/$defs/stringList"
216
- },
217
- "summary": {
218
- "type": "string",
219
- "minLength": 1
220
- }
110
+ "includePaths": { "$ref": "#/$defs/stringList" },
111
+ "excludePaths": { "$ref": "#/$defs/stringList" },
112
+ "summary": { "type": "string", "minLength": 1 }
221
113
  },
222
114
  "required": ["includePaths"],
223
- "additionalProperties": true
115
+ "additionalProperties": true,
116
+ "description": "The modeled source scope, which may differ from the scan scope. Omit when unknown."
224
117
  },
225
118
  "origin": {
226
119
  "enum": ["generated", "provided", "reconciled", "recovered"]
@@ -229,47 +122,49 @@
229
122
  "required": ["format", "content"],
230
123
  "additionalProperties": true
231
124
  }
232
- ]
125
+ ],
126
+ "description": "Retained threat-model content. Existing structured models remain supported; Markdown documents preserve their complete original body."
233
127
  },
234
128
  "hardening": {
235
129
  "type": "object",
236
- "required": ["portfolioPath"],
237
130
  "properties": {
238
- "portfolioPath": {
239
- "const": "hardening/hardening.md"
240
- }
241
- }
242
- },
243
- "coverageRef": {
244
- "const": "coverage.json"
245
- },
246
- "findingsRef": {
247
- "const": "findings.json"
131
+ "portfolioPath": { "const": "hardening/hardening.md" }
132
+ },
133
+ "required": ["portfolioPath"]
248
134
  },
135
+ "coverageRef": { "const": "coverage.json" },
136
+ "findingsRef": { "const": "findings.json" },
249
137
  "artifacts": {
250
- "type": "array",
251
138
  "minItems": 1,
139
+ "type": "array",
252
140
  "items": {
253
141
  "type": "object",
254
- "required": ["path", "sha256", "mediaType"],
255
142
  "properties": {
256
143
  "path": {
257
144
  "type": "string",
258
145
  "minLength": 1,
259
146
  "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+$"
260
147
  },
261
- "sha256": {
262
- "type": "string",
263
- "pattern": "^[a-f0-9]{64}$"
264
- },
265
- "mediaType": {
266
- "type": "string",
267
- "minLength": 1
268
- }
269
- }
148
+ "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
149
+ "mediaType": { "type": "string", "minLength": 1 }
150
+ },
151
+ "required": ["path", "sha256", "mediaType"]
270
152
  }
271
153
  }
272
154
  },
155
+ "required": [
156
+ "id",
157
+ "producer",
158
+ "status",
159
+ "startedAt",
160
+ "completedAt",
161
+ "sealedAt",
162
+ "target",
163
+ "scope",
164
+ "coverageRef",
165
+ "findingsRef",
166
+ "artifacts"
167
+ ],
273
168
  "allOf": [
274
169
  {
275
170
  "properties": {
@@ -277,11 +172,7 @@
277
172
  "contains": {
278
173
  "type": "object",
279
174
  "required": ["path"],
280
- "properties": {
281
- "path": {
282
- "const": "findings.json"
283
- }
284
- }
175
+ "properties": { "path": { "const": "findings.json" } }
285
176
  },
286
177
  "minContains": 1,
287
178
  "maxContains": 1
@@ -294,11 +185,7 @@
294
185
  "contains": {
295
186
  "type": "object",
296
187
  "required": ["path"],
297
- "properties": {
298
- "path": {
299
- "const": "coverage.json"
300
- }
301
- }
188
+ "properties": { "path": { "const": "coverage.json" } }
302
189
  },
303
190
  "minContains": 1,
304
191
  "maxContains": 1
@@ -308,13 +195,11 @@
308
195
  ]
309
196
  }
310
197
  },
198
+ "required": ["documentType", "schemaVersion", "scan"],
311
199
  "$defs": {
312
200
  "stringList": {
313
201
  "type": "array",
314
- "items": {
315
- "type": "string",
316
- "minLength": 1
317
- }
202
+ "items": { "type": "string", "minLength": 1 }
318
203
  }
319
204
  }
320
205
  }
@@ -20,6 +20,7 @@ import workbench_saved_results as saved_results
20
20
  from deep_scan_config import resolve_deep_scan_config
21
21
  from workbench.handoff import require_current_continuation
22
22
  from workbench.storage import create_private_directory
23
+ from workbench_source_scopes import capture_source_scopes
23
24
  from workbench_target import directory_snapshot_regular_file_count
24
25
  from workbench_validation import optional_text, require_uuid, user_context_argument
25
26
 
@@ -830,6 +831,11 @@ def begin_deep_scan_for_target(
830
831
  terminal["id"],
831
832
  start_disposition="joined",
832
833
  )
834
+ source_scopes = capture_source_scopes(
835
+ target,
836
+ (revision, target_snapshot_digest, target_device, target_inode),
837
+ [scope],
838
+ )
833
839
  config = effective_deep_scan_config(args)
834
840
  workflow_version = optional_text(args.workflow_version, maximum=256)
835
841
  if workflow_version is None:
@@ -875,6 +881,7 @@ def begin_deep_scan_for_target(
875
881
  scope=scope,
876
882
  diff_target=None,
877
883
  target_identity=target_identity,
884
+ source_scopes=source_scopes,
878
885
  target_root=target_root,
879
886
  target_summary=None,
880
887
  scope_file_count=scope_file_count,
@@ -9,6 +9,7 @@ import csv
9
9
  import errno
10
10
  import hashlib
11
11
  import io
12
+ import ipaddress
12
13
  import json
13
14
  import math
14
15
  import os
@@ -67,6 +68,7 @@ RFC3339_RE = re.compile(
67
68
  re.ASCII,
68
69
  )
69
70
  REMOTE_CONTROL_RE = re.compile(r"[\x00-\x1f\x7f-\x9f\u2028\u2029]")
71
+ REMOTE_UNSAFE_HOST_RE = re.compile(r"[\s<>^|]")
70
72
  GITHUB_HASH_BLOCK_SIZE = 100
71
73
  GITHUB_HASH_MOD = 37
72
74
  GITHUB_HASH_MASK = (1 << 64) - 1
@@ -415,7 +417,9 @@ def _require_str(payload: dict[str, Any], key: str, context: str) -> str:
415
417
  return value
416
418
 
417
419
 
418
- def _require_safe_relative_path(value: str, context: str, *, allow_dot: bool = False) -> str:
420
+ def _require_safe_relative_path(value: object, context: str, *, allow_dot: bool = False) -> str:
421
+ if not isinstance(value, str) or not value:
422
+ raise ContractError(f"{context}: expected a safe repository-relative POSIX path")
419
423
  try:
420
424
  value.encode("utf-8")
421
425
  except UnicodeEncodeError as exc:
@@ -423,8 +427,7 @@ def _require_safe_relative_path(value: str, context: str, *, allow_dot: bool = F
423
427
  path = PurePosixPath(value)
424
428
  normalized = path.as_posix()
425
429
  if (
426
- not value.strip()
427
- or (normalized == "." and not allow_dot)
430
+ (normalized == "." and not allow_dot)
428
431
  or (len(value) >= 2 and value[0].isalpha() and value[1] == ":")
429
432
  or "\\" in value
430
433
  or "\0" in value
@@ -438,7 +441,7 @@ def _require_safe_relative_path(value: str, context: str, *, allow_dot: bool = F
438
441
 
439
442
  def _require_portable_relative_path(value: str, context: str, *, allow_dot: bool = False) -> str:
440
443
  normalized = _require_safe_relative_path(value, context, allow_dot=allow_dot)
441
- if any(_windows_unsafe_path_component(part) for part in value.split("/")):
444
+ if not value.strip() or any(_windows_unsafe_path_component(part) for part in value.split("/")):
442
445
  raise ContractError(f"{context}: expected a safe scan-relative POSIX path")
443
446
  return normalized
444
447
 
@@ -844,16 +847,20 @@ def write_scan_local_bytes(
844
847
  os.replace(temp_name, parts[-1], src_dir_fd=parent_fd, dst_dir_fd=parent_fd)
845
848
  temp_name = None
846
849
  finally:
847
- if temp_name is not None and parent_fd is not None:
850
+ try:
851
+ if temp_name is not None and parent_fd is not None:
852
+ try:
853
+ os.unlink(temp_name, dir_fd=parent_fd)
854
+ except FileNotFoundError:
855
+ # The temporary file is already gone, so cleanup is complete.
856
+ pass
857
+ finally:
848
858
  try:
849
- os.unlink(temp_name, dir_fd=parent_fd)
850
- except FileNotFoundError:
851
- # The temporary file is already gone, so cleanup is complete.
852
- pass
853
- if parent_fd is not None:
854
- os.close(parent_fd)
855
- if root_fd is not None:
856
- os.close(root_fd)
859
+ if parent_fd is not None:
860
+ os.close(parent_fd)
861
+ finally:
862
+ if root_fd is not None:
863
+ os.close(root_fd)
857
864
 
858
865
 
859
866
  def _remove_scan_local_file_if_exists(scan_dir: Path, relative_path: str) -> None:
@@ -894,13 +901,35 @@ def _write_scan_local_json(scan_dir: Path, relative_path: str, payload: Any) ->
894
901
  def _validate_remote(remote: str, context: str) -> None:
895
902
  if REMOTE_CONTROL_RE.search(remote):
896
903
  raise ContractError(f"{context}: expected a sanitized canonical absolute URL")
897
- parsed = urlsplit(remote)
904
+ try:
905
+ parsed = urlsplit(remote)
906
+ except ValueError as exc:
907
+ # urlsplit rejects authorities with unbalanced brackets.
908
+ raise ContractError(f"{context}: expected a sanitized canonical absolute URL") from exc
898
909
  if "\\" in remote or not parsed.scheme or not parsed.netloc:
899
910
  raise ContractError(f"{context}: expected a sanitized canonical absolute URL")
900
- if parsed.username or parsed.password or parsed.query or parsed.fragment:
911
+ if "@" in parsed.netloc or parsed.query or parsed.fragment:
901
912
  raise ContractError(
902
913
  f"{context}: remote URL must not contain credentials, query, or fragment"
903
914
  )
915
+ # Mirrors the authority rules of the WHATWG URL parser the SDK reader applies.
916
+ authority = parsed.netloc
917
+ if authority.startswith("["):
918
+ try:
919
+ ipaddress.IPv6Address(authority.partition("]")[0][1:])
920
+ except ValueError as exc:
921
+ raise ContractError(f"{context}: expected a sanitized canonical absolute URL") from exc
922
+ authority = authority.partition("]")[2]
923
+ if authority and not authority.startswith(":"):
924
+ raise ContractError(f"{context}: expected a sanitized canonical absolute URL")
925
+ port = authority.partition(":")[2]
926
+ hostname = parsed.hostname
927
+ if (
928
+ not hostname
929
+ or REMOTE_UNSAFE_HOST_RE.search(hostname)
930
+ or (port and (not port.isascii() or not port.isdigit() or int(port) > 65535))
931
+ ):
932
+ raise ContractError(f"{context}: expected a sanitized canonical absolute URL")
904
933
 
905
934
 
906
935
  def parse_timestamp(value: str) -> datetime:
@@ -961,7 +990,7 @@ def _stable_id(prefix: str, *parts: str) -> str:
961
990
 
962
991
 
963
992
  def _validate_location(location: dict[str, Any], context: str) -> None:
964
- _require_safe_relative_path(_require_str(location, "path", context), f"{context}.path")
993
+ _require_safe_relative_path(location.get("path"), f"{context}.path")
965
994
  start = location.get("startLine")
966
995
  end = location.get("endLine", start)
967
996
  if not isinstance(start, int) or start < 1:
@@ -1400,19 +1429,53 @@ def _populate_unsealed_manifest_envelope(
1400
1429
  allowed_kinds = completion_binding["allowedTargetKinds"]
1401
1430
  if len(allowed_kinds) == 1:
1402
1431
  target.setdefault("kind", allowed_kinds[0])
1403
- _populate_unsealed_target_binding(target, completion_binding["target"])
1432
+ _populate_unsealed_target_binding(target, completion_binding["target"], allowed_kinds)
1404
1433
 
1405
1434
  scope = scan.setdefault("scope", {})
1406
1435
  if isinstance(scope, dict):
1407
1436
  scope.update(copy.deepcopy(completion_binding["scope"]))
1408
1437
 
1409
1438
 
1439
+ def _populate_unsealed_target_kind(
1440
+ target: dict[str, Any],
1441
+ target_binding: dict[str, Any],
1442
+ allowed_kinds: Any,
1443
+ ) -> None:
1444
+ """Adopt the registered target kind when the binding owns every coordinate it needs.
1445
+
1446
+ The workbench, not the draft, knows how the target was registered: a scan agent
1447
+ that infers the kind from the checkout (a clean worktree registered as
1448
+ git_revision is the common case) used to discard the whole completed scan at the
1449
+ seal step. The kind carries no draft-owned information when the registration
1450
+ allows a single value, so take that value instead of failing.
1451
+
1452
+ Rewriting the kind also reinterprets the coordinates that kind requires, and a
1453
+ coordinate the binding does not own survives the replacement below with whatever
1454
+ the draft computed under its own reading of the target. Adopting git_diff without
1455
+ a bound snapshotDigest, for example, would seal a whole-worktree digest as the
1456
+ diff digest. Leave the kind alone whenever the binding cannot restate every
1457
+ coordinate the registered kind requires, and let the binding check reject the
1458
+ draft instead.
1459
+ """
1460
+
1461
+ if not isinstance(allowed_kinds, list) or len(allowed_kinds) != 1:
1462
+ return
1463
+ registered_kind = allowed_kinds[0]
1464
+ if not isinstance(registered_kind, str) or target.get("kind") == registered_kind:
1465
+ return
1466
+ if not TARGET_REQUIRED_COORDINATE_FIELDS.get(registered_kind, set()) <= target_binding.keys():
1467
+ return
1468
+ target["kind"] = registered_kind
1469
+
1470
+
1410
1471
  def _populate_unsealed_target_binding(
1411
1472
  target: dict[str, Any],
1412
1473
  target_binding: dict[str, Any],
1474
+ allowed_kinds: Any = None,
1413
1475
  ) -> None:
1414
1476
  """Replace workbench-owned target coordinates without retaining incompatible drafts."""
1415
1477
 
1478
+ _populate_unsealed_target_kind(target, target_binding, allowed_kinds)
1416
1479
  target_kind = target.get("kind")
1417
1480
  required_coordinates = (
1418
1481
  TARGET_REQUIRED_COORDINATE_FIELDS.get(target_kind, set())
@@ -1593,7 +1656,7 @@ def _validate_finding(finding: dict[str, Any], context: str) -> None:
1593
1656
  _require_str(evidence, "code", evidence_context)
1594
1657
  if evidence_key == "codeEvidence":
1595
1658
  _require_safe_relative_path(
1596
- _require_str(evidence, "path", evidence_context),
1659
+ evidence.get("path"),
1597
1660
  f"{evidence_context}.path",
1598
1661
  )
1599
1662
 
@@ -2196,8 +2259,8 @@ def _sarif_rule(rule_id: str, findings: list[dict[str, Any]]) -> dict[str, Any]:
2196
2259
  tags = {"security", *categories}
2197
2260
  for cwe in cwes:
2198
2261
  match = re.fullmatch(r"CWE-([0-9]+)", cwe, re.IGNORECASE)
2199
- if match and int(match[1]) > 0:
2200
- tags.add(f"external/cwe/cwe-{int(match[1]):03d}")
2262
+ if match and (digits := match[1].lstrip("0")):
2263
+ tags.add(f"external/cwe/cwe-{digits.zfill(3)}")
2201
2264
  description = f"{name}. Categories: {', '.join(map(_sarif_label, categories))}."
2202
2265
  if cwes:
2203
2266
  description += f" Weaknesses: {', '.join(cwes)}."
@@ -2442,31 +2505,6 @@ def _sarif_locations(finding: dict[str, Any]) -> list[dict[str, Any]]:
2442
2505
  return list(unique.values())
2443
2506
 
2444
2507
 
2445
- def _github_primary_location_line_hash(
2446
- finding: dict[str, Any],
2447
- source_root: Path | None,
2448
- line_hash_cache: dict[tuple[Path, int], str | None] | None = None,
2449
- ) -> str | None:
2450
- if source_root is None:
2451
- return None
2452
- primary_location = _sarif_primary_location(finding)
2453
- try:
2454
- source_root = source_root.resolve(strict=True)
2455
- except (OSError, RuntimeError):
2456
- return None
2457
- relative_path = _require_safe_relative_path(primary_location["path"], "SARIF source location")
2458
- source_path = source_root / relative_path
2459
- start_line = primary_location["startLine"]
2460
- cache_key = (source_path, start_line)
2461
- if line_hash_cache is not None and cache_key in line_hash_cache:
2462
- return line_hash_cache[cache_key]
2463
- line_hashes = _github_line_hashes_for_source(source_root, relative_path, {start_line})
2464
- line_hash = None if line_hashes is None else line_hashes.get(start_line)
2465
- if line_hash_cache is not None:
2466
- line_hash_cache[cache_key] = line_hash
2467
- return line_hash
2468
-
2469
-
2470
2508
  def _github_line_hash_cache(
2471
2509
  findings: list[dict[str, Any]], source_root: Path | None
2472
2510
  ) -> dict[tuple[Path, int], str | None]:
@@ -2486,7 +2524,7 @@ def _github_line_hash_cache(
2486
2524
  line_hash_cache: dict[tuple[Path, int], str | None] = {}
2487
2525
  for relative_path, requested_lines in requested_lines_by_path.items():
2488
2526
  line_hashes = _github_line_hashes_for_source(source_root, relative_path, requested_lines)
2489
- source_path = source_root / relative_path
2527
+ source_path = Path(relative_path)
2490
2528
  for line_number in requested_lines:
2491
2529
  line_hash_cache[(source_path, line_number)] = (
2492
2530
  None if line_hashes is None else line_hashes.get(line_number)
@@ -2514,7 +2552,6 @@ def _sarif_location(location: dict[str, Any]) -> dict[str, Any]:
2514
2552
  def _sarif_result(
2515
2553
  finding: dict[str, Any],
2516
2554
  rule_index: int,
2517
- source_root: Path | None = None,
2518
2555
  line_hash_cache: dict[tuple[Path, int], str | None] | None = None,
2519
2556
  ) -> dict[str, Any]:
2520
2557
  properties = {
@@ -2531,7 +2568,8 @@ def _sarif_result(
2531
2568
  partial_fingerprints = {
2532
2569
  "codexSecurity/v1": finding["fingerprints"]["primary"],
2533
2570
  }
2534
- line_hash = _github_primary_location_line_hash(finding, source_root, line_hash_cache)
2571
+ primary = _sarif_primary_location(finding)
2572
+ line_hash = (line_hash_cache or {}).get((Path(primary["path"]), primary["startLine"]))
2535
2573
  if line_hash is not None:
2536
2574
  partial_fingerprints["primaryLocationLineHash"] = line_hash
2537
2575
  return {
@@ -2569,7 +2607,7 @@ def build_sarif(
2569
2607
  },
2570
2608
  "automationDetails": {"id": scan["id"]},
2571
2609
  "results": [
2572
- _sarif_result(finding, rule_index[finding["ruleId"]], source_root, line_hash_cache)
2610
+ _sarif_result(finding, rule_index[finding["ruleId"]], line_hash_cache)
2573
2611
  for finding in ordered_findings
2574
2612
  ],
2575
2613
  "properties": {