@openai/codex-security 0.1.31 → 0.2.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.
- package/README.md +295 -32
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +4 -4
- package/_bundled_plugin/references/config-preflight.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -2
- package/_bundled_plugin/references/final-report.md +4 -2
- package/_bundled_plugin/references/scan-artifacts.md +2 -2
- package/_bundled_plugin/references/scan-contract.md +2 -2
- package/_bundled_plugin/references/threat-model.md +2 -2
- package/_bundled_plugin/schemas/coverage.schema.json +22 -0
- package/_bundled_plugin/schemas/scan-manifest.schema.json +100 -85
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +116 -102
- package/_bundled_plugin/scripts/config_preflight.py +4 -8
- package/_bundled_plugin/scripts/deep_scan_workbench.py +83 -217
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
- package/_bundled_plugin/scripts/finalize_scan_contract.py +441 -166
- package/_bundled_plugin/scripts/finding_preview.py +42 -82
- package/_bundled_plugin/scripts/generate_in_scope_files.py +30 -34
- package/_bundled_plugin/scripts/generate_rank_input.py +58 -99
- package/_bundled_plugin/scripts/launch_codex_security_mcp +5 -1
- package/_bundled_plugin/scripts/rank_preview.py +85 -68
- package/_bundled_plugin/scripts/report_projection.py +37 -58
- package/_bundled_plugin/scripts/threat_model_projection.py +164 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +11 -6
- package/_bundled_plugin/scripts/workbench/storage.py +11 -0
- package/_bundled_plugin/scripts/workbench_cli.py +11 -17
- package/_bundled_plugin/scripts/workbench_constants.py +6 -14
- package/_bundled_plugin/scripts/workbench_db.py +116 -228
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -6
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -4
- package/_bundled_plugin/scripts/workbench_progress.py +12 -34
- package/_bundled_plugin/scripts/workbench_publication.py +47 -62
- package/_bundled_plugin/scripts/workbench_remediation.py +2 -20
- package/_bundled_plugin/scripts/workbench_saved_results.py +1246 -230
- package/_bundled_plugin/scripts/workbench_scan_start.py +4 -11
- package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -15
- package/_bundled_plugin/scripts/workbench_schema.py +86 -271
- package/_bundled_plugin/scripts/workbench_severity.py +3 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +5 -6
- package/_bundled_plugin/scripts/workbench_target.py +98 -10
- package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
- package/_bundled_plugin/scripts/workbench_validation.py +6 -20
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-scan/SKILL.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- package/dist/api.d.ts +3 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +201 -207
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +70 -0
- package/dist/artifact-export.d.ts.map +1 -0
- package/dist/artifact-export.js +277 -0
- package/dist/artifact-export.js.map +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +8 -3
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +8 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +2 -5
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts +2 -8
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -5
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +281 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +19 -22
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +631 -714
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +1 -8
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +1 -2
- package/dist/codex-prompt.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +2 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -0
- package/dist/codex-sdk-environment.js +30 -0
- package/dist/codex-sdk-environment.js.map +1 -0
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +2 -6
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +1 -0
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +31 -9
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -33
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +2 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +63 -122
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +65 -34
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +15 -31
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +4 -4
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +17 -16
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +10 -11
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +2 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +3 -3
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +2 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js +40 -62
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +1 -4
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +2 -1
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +24 -6
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/review.d.ts +7 -0
- package/dist/deduplication/review.d.ts.map +1 -1
- package/dist/deduplication/review.js.map +1 -1
- package/dist/deduplication/scan.js +3 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +3 -19
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +0 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +22 -40
- package/dist/deep-progress.js.map +1 -1
- package/dist/errors.d.ts +3 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -7
- package/dist/errors.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +22 -22
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +4 -7
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +7 -17
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +2 -3
- package/dist/github.js.map +1 -1
- package/dist/import-scan.js +2 -2
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.js +2 -2
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +2 -3
- package/dist/linear.js.map +1 -1
- package/dist/models.d.ts +24 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +36 -31
- package/dist/multiscan.js.map +1 -1
- package/dist/owner-evidence.d.ts.map +1 -1
- package/dist/owner-evidence.js +2 -6
- package/dist/owner-evidence.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +2 -4
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +10 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -0
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +0 -1
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +2 -4
- package/dist/prompt-files.js.map +1 -1
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +15 -29
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +9 -13
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +11 -14
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +31 -41
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +4 -0
- package/dist/record.js.map +1 -0
- package/dist/result.d.ts +4 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +10 -13
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +203 -131
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts.map +1 -1
- package/dist/saved-scan.js +10 -20
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +8 -22
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +3 -3
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +38 -73
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +0 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +10 -19
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +1 -2
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +2 -6
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +1 -3
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +5 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.js.map +1 -1
- package/dist/security-policy-cli.d.ts.map +1 -1
- package/dist/security-policy-cli.js +8 -6
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +8 -4
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +98 -84
- package/dist/security-policy.js.map +1 -1
- package/dist/server/dashboard/app.js +5 -5
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +1 -0
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/routes.d.ts +3 -2
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +19 -7
- package/dist/server/routes.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +2 -3
- package/dist/server/server.js.map +1 -1
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +4 -14
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/severity-store.js +8 -15
- package/dist/severity-store.js.map +1 -1
- package/dist/suggest-owners.d.ts +2 -3
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +4 -5
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +24 -21
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts +5 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +22 -5
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.d.ts +2 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +20 -0
- package/dist/value.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -6
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -2
- package/dist/windows-path.js.map +1 -1
- package/dist/worker-progress.d.ts +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +13 -34
- package/dist/worker-progress.js.map +1 -1
- package/docs/dedupe-records.md +24 -0
- package/package.json +11 -10
- package/schemas/project-config.schema.json +5 -0
- package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
- package/dist/server/findings-service.d.ts +0 -20
- package/dist/server/findings-service.d.ts.map +0 -1
- package/dist/server/findings-service.js +0 -31
- package/dist/server/findings-service.js.map +0 -1
|
@@ -22,7 +22,7 @@ from workbench_target import (
|
|
|
22
22
|
git_revision,
|
|
23
23
|
worktree_content_digest,
|
|
24
24
|
)
|
|
25
|
-
from workbench_validation import optional_text
|
|
25
|
+
from workbench_validation import optional_text
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def safe_segment(value: str) -> str:
|
|
@@ -168,7 +168,7 @@ def insert_running_scan(
|
|
|
168
168
|
) -> str:
|
|
169
169
|
revision = target_identity[0]
|
|
170
170
|
native_scan = scan_dir is None
|
|
171
|
-
user_context =
|
|
171
|
+
user_context = optional_text(workspace["user_context"])
|
|
172
172
|
if scan_dir is None:
|
|
173
173
|
scan_dir = Path(
|
|
174
174
|
tempfile.mkdtemp(
|
|
@@ -197,10 +197,7 @@ def insert_running_scan(
|
|
|
197
197
|
workspace["default_mode"],
|
|
198
198
|
user_context,
|
|
199
199
|
workspace["thread_id"] if workspace["default_mode"] == "deep" else None,
|
|
200
|
-
diff_target
|
|
201
|
-
diff_target["baseRevision"] if diff_target else None,
|
|
202
|
-
diff_target["headRevision"] if diff_target else None,
|
|
203
|
-
diff_target.get("contentDigest") if diff_target else None,
|
|
200
|
+
*scan_diff_identity(diff_target or None),
|
|
204
201
|
target_summary,
|
|
205
202
|
str(scan_dir),
|
|
206
203
|
optional_text(model, maximum=200),
|
|
@@ -236,9 +233,5 @@ def insert_running_scan(
|
|
|
236
233
|
return scan_id
|
|
237
234
|
|
|
238
235
|
|
|
239
|
-
def main() -> None:
|
|
240
|
-
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
241
|
-
|
|
242
|
-
|
|
243
236
|
if __name__ == "__main__":
|
|
244
|
-
|
|
237
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
@@ -70,15 +70,11 @@ def reconcile_completed_scan_cost(
|
|
|
70
70
|
allow_nan=False,
|
|
71
71
|
)
|
|
72
72
|
connection.execute("BEGIN IMMEDIATE")
|
|
73
|
-
|
|
73
|
+
with connection:
|
|
74
74
|
connection.execute(
|
|
75
75
|
"UPDATE scans SET cost_json = ? WHERE id = ? AND status = 'complete'",
|
|
76
76
|
(cost_json, scan["id"]),
|
|
77
77
|
)
|
|
78
|
-
connection.commit()
|
|
79
|
-
except BaseException:
|
|
80
|
-
connection.rollback()
|
|
81
|
-
raise
|
|
82
78
|
|
|
83
79
|
|
|
84
80
|
def collect_scan_usage(
|
|
@@ -117,7 +113,6 @@ def collect_scan_usage(
|
|
|
117
113
|
return _unavailable_usage("scan_thread_unavailable", warnings=warnings)
|
|
118
114
|
|
|
119
115
|
total = _empty_token_usage()
|
|
120
|
-
observed_thread_count = 0
|
|
121
116
|
accepted_thread_ids: set[str] = set()
|
|
122
117
|
excluded_thread_ids: set[str] = set()
|
|
123
118
|
for session in sessions:
|
|
@@ -151,17 +146,16 @@ def collect_scan_usage(
|
|
|
151
146
|
missing_thread_ids.add(session.thread_id)
|
|
152
147
|
continue
|
|
153
148
|
accepted_thread_ids.add(session.thread_id)
|
|
154
|
-
observed_thread_count += 1
|
|
155
149
|
_add_token_usage(total, session_usage)
|
|
156
150
|
|
|
157
|
-
if not
|
|
151
|
+
if not accepted_thread_ids:
|
|
158
152
|
return _unavailable_usage("scan_thread_unavailable", warnings=warnings)
|
|
159
153
|
|
|
160
154
|
result: dict[str, Any] = {
|
|
161
155
|
"coverage": "partial" if missing_thread_ids or warnings else "complete",
|
|
162
156
|
"source": "codex_rollout",
|
|
163
157
|
**total,
|
|
164
|
-
"threadCount":
|
|
158
|
+
"threadCount": len(accepted_thread_ids),
|
|
165
159
|
}
|
|
166
160
|
if missing_thread_ids:
|
|
167
161
|
result["missingThreadCount"] = len(missing_thread_ids)
|
|
@@ -202,13 +196,11 @@ def _scan_root_thread_ids(
|
|
|
202
196
|
(scan["id"],),
|
|
203
197
|
)
|
|
204
198
|
)
|
|
205
|
-
roots:
|
|
206
|
-
seen: set[str] = set()
|
|
199
|
+
roots: dict[str, None] = {}
|
|
207
200
|
for candidate in candidates:
|
|
208
|
-
if isinstance(candidate, str) and candidate.strip()
|
|
209
|
-
roots
|
|
210
|
-
|
|
211
|
-
return roots
|
|
201
|
+
if isinstance(candidate, str) and candidate.strip():
|
|
202
|
+
roots[candidate] = None
|
|
203
|
+
return list(roots)
|
|
212
204
|
|
|
213
205
|
|
|
214
206
|
def _scan_execution_thread_ids(connection: sqlite3.Connection, scan: sqlite3.Row) -> list[str]:
|
|
@@ -944,10 +944,12 @@ def apply_migrations(
|
|
|
944
944
|
migrations: tuple[tuple[int, str, str], ...],
|
|
945
945
|
now: Callable[[], str],
|
|
946
946
|
backfill_security_targets: Callable[[sqlite3.Connection], None],
|
|
947
|
+
*,
|
|
948
|
+
immediate: bool = False,
|
|
947
949
|
) -> None:
|
|
948
950
|
connection.commit()
|
|
949
|
-
connection.execute("BEGIN IMMEDIATE")
|
|
950
|
-
|
|
951
|
+
connection.execute("BEGIN IMMEDIATE" if immediate else "BEGIN")
|
|
952
|
+
with connection:
|
|
951
953
|
connection.execute(
|
|
952
954
|
"""
|
|
953
955
|
CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
@@ -963,59 +965,15 @@ def apply_migrations(
|
|
|
963
965
|
}
|
|
964
966
|
should_backfill_targets = False
|
|
965
967
|
for version, name, sql in migrations:
|
|
966
|
-
if version in applied:
|
|
967
|
-
if version == 2:
|
|
968
|
-
add_column_if_missing(
|
|
969
|
-
connection, "workspaces", "capability_preflight_json", "TEXT"
|
|
970
|
-
)
|
|
971
|
-
elif version == 6:
|
|
972
|
-
repair_thread_scoped_workspaces_migration(connection)
|
|
973
|
-
elif version == 11:
|
|
974
|
-
repair_deep_scan_migration(connection)
|
|
975
|
-
elif version == 12:
|
|
976
|
-
add_column_if_missing(connection, "scans", "continuation_thread_id", "TEXT")
|
|
977
|
-
elif version == 13:
|
|
978
|
-
add_column_if_missing(
|
|
979
|
-
connection,
|
|
980
|
-
"scan_progress",
|
|
981
|
-
"scope_file_count",
|
|
982
|
-
"INTEGER CHECK (scope_file_count >= 0)",
|
|
983
|
-
)
|
|
984
|
-
elif version == 16:
|
|
985
|
-
should_backfill_targets = repair_stable_targets_migration(connection)
|
|
986
|
-
elif version == 26:
|
|
987
|
-
add_column_if_missing(
|
|
988
|
-
connection,
|
|
989
|
-
"scans",
|
|
990
|
-
"completion_warnings_json",
|
|
991
|
-
"TEXT NOT NULL DEFAULT '[]'",
|
|
992
|
-
)
|
|
993
|
-
elif version == 28:
|
|
994
|
-
add_column_if_missing(
|
|
995
|
-
connection,
|
|
996
|
-
"deep_scan_runs",
|
|
997
|
-
"max_time_hours",
|
|
998
|
-
"REAL NOT NULL DEFAULT 96",
|
|
999
|
-
)
|
|
1000
|
-
elif version == 31:
|
|
1001
|
-
add_column_if_missing(
|
|
1002
|
-
connection,
|
|
1003
|
-
"scans",
|
|
1004
|
-
"retained_source_digests_json",
|
|
1005
|
-
"TEXT",
|
|
1006
|
-
)
|
|
1007
|
-
elif version == 32:
|
|
1008
|
-
add_column_if_missing(
|
|
1009
|
-
connection,
|
|
1010
|
-
"deep_scan_runs",
|
|
1011
|
-
"publication_error_message",
|
|
1012
|
-
"TEXT",
|
|
1013
|
-
)
|
|
1014
|
-
continue
|
|
1015
968
|
if version == 6:
|
|
1016
969
|
repair_thread_scoped_workspaces_migration(connection)
|
|
1017
970
|
elif version == 16:
|
|
1018
971
|
should_backfill_targets = repair_stable_targets_migration(connection)
|
|
972
|
+
elif version in applied:
|
|
973
|
+
if version in (2, 12, 13, 26, 28, 31, 32):
|
|
974
|
+
repair_additive_migration(connection, version)
|
|
975
|
+
elif version == 11:
|
|
976
|
+
repair_deep_scan_migration(connection)
|
|
1019
977
|
else:
|
|
1020
978
|
for statement in sql_statements(sql):
|
|
1021
979
|
connection.execute(statement)
|
|
@@ -1023,18 +981,15 @@ def apply_migrations(
|
|
|
1023
981
|
migrate_finding_workflow_columns(connection)
|
|
1024
982
|
elif version == 39:
|
|
1025
983
|
migrate_finding_workflow_review_columns(connection)
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
984
|
+
if version not in applied:
|
|
985
|
+
connection.execute(
|
|
986
|
+
"INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
|
|
987
|
+
(version, name, now()),
|
|
988
|
+
)
|
|
1030
989
|
if 27 in applied:
|
|
1031
990
|
repair_deep_scan_failure_counter_migration(connection)
|
|
1032
991
|
if should_backfill_targets:
|
|
1033
992
|
backfill_security_targets(connection)
|
|
1034
|
-
connection.commit()
|
|
1035
|
-
except BaseException:
|
|
1036
|
-
connection.rollback()
|
|
1037
|
-
raise
|
|
1038
993
|
|
|
1039
994
|
|
|
1040
995
|
def normalize_pre_release_execution_profile_migrations(
|
|
@@ -1121,8 +1076,7 @@ def normalize_pre_release_execution_profile_migrations(
|
|
|
1121
1076
|
connection.execute(
|
|
1122
1077
|
f"ALTER TABLE {table} RENAME COLUMN reasoning_effort TO legacy_reasoning_effort"
|
|
1123
1078
|
)
|
|
1124
|
-
|
|
1125
|
-
add_column_if_missing(connection, "scans", "reasoning_effort", "TEXT")
|
|
1079
|
+
repair_additive_migration(connection, 25)
|
|
1126
1080
|
connection.execute(
|
|
1127
1081
|
"""
|
|
1128
1082
|
UPDATE scans
|
|
@@ -1146,196 +1100,68 @@ def normalize_pre_release_execution_profile_migrations(
|
|
|
1146
1100
|
)
|
|
1147
1101
|
|
|
1148
1102
|
|
|
1149
|
-
def
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
)
|
|
1155
|
-
|
|
1156
|
-
completion_warning_migration = connection.execute(
|
|
1157
|
-
"SELECT name FROM schema_migrations WHERE version = 25"
|
|
1103
|
+
def move_pre_release_migration(
|
|
1104
|
+
connection: sqlite3.Connection, old_version: int, new_version: int, name: str
|
|
1105
|
+
) -> None:
|
|
1106
|
+
migration = connection.execute(
|
|
1107
|
+
"SELECT name FROM schema_migrations WHERE version = ?", (old_version,)
|
|
1158
1108
|
).fetchone()
|
|
1109
|
+
if migration is None or migration["name"] != name:
|
|
1110
|
+
return
|
|
1159
1111
|
if (
|
|
1160
|
-
completion_warning_migration is not None
|
|
1161
|
-
and completion_warning_migration["name"] == "persist scan completion warnings"
|
|
1162
|
-
):
|
|
1163
|
-
if (
|
|
1164
|
-
connection.execute("SELECT 1 FROM schema_migrations WHERE version = 26").fetchone()
|
|
1165
|
-
is not None
|
|
1166
|
-
):
|
|
1167
|
-
raise SystemExit(
|
|
1168
|
-
"The Codex Security database has an unsupported pre-release migration history."
|
|
1169
|
-
)
|
|
1170
1112
|
connection.execute(
|
|
1171
|
-
"
|
|
1172
|
-
("persist scan completion warnings",),
|
|
1173
|
-
)
|
|
1174
|
-
|
|
1175
|
-
phase_progress_migration = connection.execute(
|
|
1176
|
-
"SELECT name FROM schema_migrations WHERE version = 12"
|
|
1177
|
-
).fetchone()
|
|
1178
|
-
if (
|
|
1179
|
-
phase_progress_migration is not None
|
|
1180
|
-
and phase_progress_migration["name"] == "phase-specific scan progress"
|
|
1181
|
-
):
|
|
1182
|
-
target_migration = connection.execute(
|
|
1183
|
-
"SELECT name FROM schema_migrations WHERE version = 20"
|
|
1113
|
+
"SELECT 1 FROM schema_migrations WHERE version = ?", (new_version,)
|
|
1184
1114
|
).fetchone()
|
|
1185
|
-
|
|
1186
|
-
raise SystemExit(
|
|
1187
|
-
"The Codex Security database has an unsupported pre-release migration history."
|
|
1188
|
-
)
|
|
1189
|
-
connection.execute(
|
|
1190
|
-
"UPDATE schema_migrations SET version = 20 WHERE version = 12 AND name = ?",
|
|
1191
|
-
("phase-specific scan progress",),
|
|
1192
|
-
)
|
|
1193
|
-
|
|
1194
|
-
normalize_pre_release_execution_profile_migrations(connection, timestamp)
|
|
1195
|
-
|
|
1196
|
-
preflight_progress_migration = connection.execute(
|
|
1197
|
-
"SELECT name FROM schema_migrations WHERE version = 13"
|
|
1198
|
-
).fetchone()
|
|
1199
|
-
if (
|
|
1200
|
-
preflight_progress_migration is not None
|
|
1201
|
-
and preflight_progress_migration["name"] == "current scan preflight state"
|
|
1115
|
+
is not None
|
|
1202
1116
|
):
|
|
1203
|
-
|
|
1204
|
-
"
|
|
1205
|
-
).fetchone()
|
|
1206
|
-
if target_migration is not None:
|
|
1207
|
-
raise SystemExit(
|
|
1208
|
-
"The Codex Security database has an unsupported pre-release migration history."
|
|
1209
|
-
)
|
|
1210
|
-
connection.execute(
|
|
1211
|
-
"UPDATE schema_migrations SET version = 21 WHERE version = 13 AND name = ?",
|
|
1212
|
-
("current scan preflight state",),
|
|
1117
|
+
raise SystemExit(
|
|
1118
|
+
"The Codex Security database has an unsupported pre-release migration history."
|
|
1213
1119
|
)
|
|
1120
|
+
connection.execute(
|
|
1121
|
+
"UPDATE schema_migrations SET version = ? WHERE version = ? AND name = ?",
|
|
1122
|
+
(new_version, old_version, name),
|
|
1123
|
+
)
|
|
1214
1124
|
|
|
1215
|
-
delivered_claim_migration = connection.execute(
|
|
1216
|
-
"SELECT name FROM schema_migrations WHERE version = 18"
|
|
1217
|
-
).fetchone()
|
|
1218
|
-
if (
|
|
1219
|
-
delivered_claim_migration is not None
|
|
1220
|
-
and delivered_claim_migration["name"] == "scan target summaries"
|
|
1221
|
-
):
|
|
1222
|
-
connection.execute(
|
|
1223
|
-
"UPDATE scans SET handoff_claimed_at = NULL, handoff_claim_token = NULL "
|
|
1224
|
-
"WHERE handoff_status = 'delivered'"
|
|
1225
|
-
)
|
|
1226
|
-
connection.execute(
|
|
1227
|
-
"UPDATE schema_migrations SET name = ? WHERE version = 18 AND name = ?",
|
|
1228
|
-
("clear legacy delivered handoff claims", "scan target summaries"),
|
|
1229
|
-
)
|
|
1230
1125
|
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
legacy_setup_preferences_migrations = {
|
|
1235
|
-
"structured scan guidance context",
|
|
1236
|
-
"idempotent scan lifecycle requests",
|
|
1237
|
-
}
|
|
1238
|
-
if (
|
|
1239
|
-
setup_preferences_migration is not None
|
|
1240
|
-
and setup_preferences_migration["name"] in legacy_setup_preferences_migrations
|
|
1241
|
-
):
|
|
1242
|
-
migration_sql = next(sql for version, _, sql in MIGRATIONS if version == 19)
|
|
1243
|
-
for statement in sql_statements(migration_sql):
|
|
1244
|
-
connection.execute(statement.replace("CREATE TABLE ", "CREATE TABLE IF NOT EXISTS ", 1))
|
|
1245
|
-
connection.execute(
|
|
1246
|
-
"UPDATE schema_migrations SET name = ? WHERE version = 19 AND name = ?",
|
|
1247
|
-
("persist setup workspace preference", setup_preferences_migration["name"]),
|
|
1248
|
-
)
|
|
1126
|
+
def normalize_pre_release_migrations(connection: sqlite3.Connection, timestamp: str) -> None:
|
|
1127
|
+
normalize_mirror_lineage_migrations(connection)
|
|
1128
|
+
move_pre_release_migration(connection, 33, 40, "index finding identity and comparison history")
|
|
1249
1129
|
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
).fetchone()
|
|
1253
|
-
legacy_phase_progress_migrations = {
|
|
1254
|
-
"retain superseded scan lifecycle requests",
|
|
1255
|
-
"threat model publication receipts",
|
|
1256
|
-
}
|
|
1257
|
-
if (
|
|
1258
|
-
phase_progress_migration is not None
|
|
1259
|
-
and phase_progress_migration["name"] in legacy_phase_progress_migrations
|
|
1260
|
-
):
|
|
1261
|
-
add_column_if_missing(
|
|
1262
|
-
connection,
|
|
1263
|
-
"scan_progress",
|
|
1264
|
-
"phase_items_total",
|
|
1265
|
-
"INTEGER NOT NULL DEFAULT 0 CHECK (phase_items_total >= 0)",
|
|
1266
|
-
)
|
|
1267
|
-
add_column_if_missing(
|
|
1268
|
-
connection,
|
|
1269
|
-
"scan_progress",
|
|
1270
|
-
"phase_items_completed",
|
|
1271
|
-
"INTEGER NOT NULL DEFAULT 0 "
|
|
1272
|
-
"CHECK (phase_items_completed >= 0 AND phase_items_completed <= phase_items_total)",
|
|
1273
|
-
)
|
|
1274
|
-
add_column_if_missing(
|
|
1275
|
-
connection,
|
|
1276
|
-
"scan_progress",
|
|
1277
|
-
"phase_progress_unit",
|
|
1278
|
-
"TEXT CHECK (phase_progress_unit IS NULL OR phase_progress_unit IN ("
|
|
1279
|
-
"'checks', 'threat_surfaces', 'review_receipts', 'candidate_findings', "
|
|
1280
|
-
"'validated_findings', 'report_artifacts'))",
|
|
1281
|
-
)
|
|
1282
|
-
connection.execute(
|
|
1283
|
-
"UPDATE schema_migrations SET name = ? WHERE version = 20 AND name = ?",
|
|
1284
|
-
("phase-specific scan progress", phase_progress_migration["name"]),
|
|
1285
|
-
)
|
|
1130
|
+
move_pre_release_migration(connection, 25, 26, "persist scan completion warnings")
|
|
1131
|
+
move_pre_release_migration(connection, 12, 20, "phase-specific scan progress")
|
|
1286
1132
|
|
|
1287
|
-
|
|
1288
|
-
"SELECT name FROM schema_migrations WHERE version = 21"
|
|
1289
|
-
).fetchone()
|
|
1290
|
-
legacy_preflight_progress_migrations = {
|
|
1291
|
-
"scan progress projection and activity",
|
|
1292
|
-
"deep coordinator manifest receipts",
|
|
1293
|
-
}
|
|
1294
|
-
if (
|
|
1295
|
-
preflight_progress_migration is not None
|
|
1296
|
-
and preflight_progress_migration["name"] in legacy_preflight_progress_migrations
|
|
1297
|
-
):
|
|
1298
|
-
add_column_if_missing(
|
|
1299
|
-
connection,
|
|
1300
|
-
"scan_progress",
|
|
1301
|
-
"preflight_issues_json",
|
|
1302
|
-
"TEXT NOT NULL DEFAULT '[]'",
|
|
1303
|
-
)
|
|
1304
|
-
add_column_if_missing(
|
|
1305
|
-
connection,
|
|
1306
|
-
"scan_progress",
|
|
1307
|
-
"preflight_checks_total",
|
|
1308
|
-
"INTEGER NOT NULL DEFAULT 0 CHECK (preflight_checks_total >= 0)",
|
|
1309
|
-
)
|
|
1310
|
-
add_column_if_missing(
|
|
1311
|
-
connection,
|
|
1312
|
-
"scan_progress",
|
|
1313
|
-
"preflight_checks_completed",
|
|
1314
|
-
"INTEGER NOT NULL DEFAULT 0 CHECK (preflight_checks_completed >= 0 "
|
|
1315
|
-
"AND preflight_checks_completed <= preflight_checks_total)",
|
|
1316
|
-
)
|
|
1317
|
-
connection.execute(
|
|
1318
|
-
"UPDATE schema_migrations SET name = ? WHERE version = 21 AND name = ?",
|
|
1319
|
-
("current scan preflight state", preflight_progress_migration["name"]),
|
|
1320
|
-
)
|
|
1133
|
+
normalize_pre_release_execution_profile_migrations(connection, timestamp)
|
|
1321
1134
|
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1135
|
+
move_pre_release_migration(connection, 13, 21, "current scan preflight state")
|
|
1136
|
+
|
|
1137
|
+
for version, legacy_names in (
|
|
1138
|
+
(18, {"scan target summaries"}),
|
|
1139
|
+
(19, {"structured scan guidance context", "idempotent scan lifecycle requests"}),
|
|
1140
|
+
(20, {"retain superseded scan lifecycle requests", "threat model publication receipts"}),
|
|
1141
|
+
(21, {"scan progress projection and activity", "deep coordinator manifest receipts"}),
|
|
1142
|
+
(22, {"dynamic scan execution profiles"}),
|
|
1328
1143
|
):
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1144
|
+
migration = connection.execute(
|
|
1145
|
+
"SELECT name FROM schema_migrations WHERE version = ?", (version,)
|
|
1146
|
+
).fetchone()
|
|
1147
|
+
if migration is None or migration["name"] not in legacy_names:
|
|
1148
|
+
continue
|
|
1149
|
+
_, name, sql = next(migration for migration in MIGRATIONS if migration[0] == version)
|
|
1150
|
+
if version == 18:
|
|
1151
|
+
connection.execute(
|
|
1152
|
+
"UPDATE scans SET handoff_claimed_at = NULL, handoff_claim_token = NULL "
|
|
1153
|
+
"WHERE handoff_status = 'delivered'"
|
|
1154
|
+
)
|
|
1155
|
+
elif version == 19:
|
|
1156
|
+
for statement in sql_statements(sql):
|
|
1157
|
+
connection.execute(
|
|
1158
|
+
statement.replace("CREATE TABLE ", "CREATE TABLE IF NOT EXISTS ", 1)
|
|
1159
|
+
)
|
|
1160
|
+
else:
|
|
1161
|
+
repair_additive_migration(connection, version)
|
|
1336
1162
|
connection.execute(
|
|
1337
|
-
"UPDATE schema_migrations SET name = ? WHERE version =
|
|
1338
|
-
(
|
|
1163
|
+
"UPDATE schema_migrations SET name = ? WHERE version = ? AND name = ?",
|
|
1164
|
+
(name, version, migration["name"]),
|
|
1339
1165
|
)
|
|
1340
1166
|
|
|
1341
1167
|
migration = connection.execute(
|
|
@@ -1371,7 +1197,7 @@ def normalize_pre_release_migrations(connection: sqlite3.Connection, timestamp:
|
|
|
1371
1197
|
"UPDATE schema_migrations SET version = ? WHERE version = ? AND name = ?",
|
|
1372
1198
|
(new_version, old_version, expected[old_version]),
|
|
1373
1199
|
)
|
|
1374
|
-
|
|
1200
|
+
repair_additive_migration(connection, 2)
|
|
1375
1201
|
add_column_if_missing(connection, "scans", "target_snapshot_digest", "TEXT")
|
|
1376
1202
|
connection.execute(
|
|
1377
1203
|
"INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
|
|
@@ -1444,24 +1270,17 @@ def repair_deep_scan_migration(connection: sqlite3.Connection) -> None:
|
|
|
1444
1270
|
|
|
1445
1271
|
|
|
1446
1272
|
def repair_deep_scan_failure_counter_migration(connection: sqlite3.Connection) -> None:
|
|
1273
|
+
threshold_column, count_column, _backfill = sql_statements(
|
|
1274
|
+
next(sql for version, _, sql in MIGRATIONS if version == 27)
|
|
1275
|
+
)
|
|
1447
1276
|
columns = {row["name"] for row in connection.execute("PRAGMA table_info(deep_scan_runs)")}
|
|
1448
1277
|
threshold_missing = "stop_after_consecutive_errors" not in columns
|
|
1449
|
-
|
|
1450
|
-
connection,
|
|
1451
|
-
"deep_scan_runs",
|
|
1452
|
-
"stop_after_consecutive_errors",
|
|
1453
|
-
"INTEGER NOT NULL DEFAULT 1 CHECK (stop_after_consecutive_errors >= 1)",
|
|
1454
|
-
)
|
|
1278
|
+
add_migration_column(connection, threshold_column)
|
|
1455
1279
|
if threshold_missing:
|
|
1456
1280
|
connection.execute(
|
|
1457
1281
|
"UPDATE deep_scan_runs SET stop_after_consecutive_errors = stop_after_no_new"
|
|
1458
1282
|
)
|
|
1459
|
-
|
|
1460
|
-
connection,
|
|
1461
|
-
"deep_scan_runs",
|
|
1462
|
-
"consecutive_errors",
|
|
1463
|
-
"INTEGER NOT NULL DEFAULT 0 CHECK (consecutive_errors >= 0)",
|
|
1464
|
-
)
|
|
1283
|
+
add_migration_column(connection, count_column)
|
|
1465
1284
|
|
|
1466
1285
|
|
|
1467
1286
|
def repair_thread_scoped_workspaces_migration(connection: sqlite3.Connection) -> None:
|
|
@@ -1490,21 +1309,8 @@ def repair_stable_targets_migration(connection: sqlite3.Connection) -> bool:
|
|
|
1490
1309
|
|
|
1491
1310
|
migration_sql = next(sql for version, _, sql in MIGRATIONS if version == 16)
|
|
1492
1311
|
for statement in sql_statements(migration_sql):
|
|
1493
|
-
if statement.startswith("ALTER TABLE workspaces"):
|
|
1494
|
-
|
|
1495
|
-
connection,
|
|
1496
|
-
"workspaces",
|
|
1497
|
-
"target_id",
|
|
1498
|
-
"TEXT REFERENCES security_targets(id)",
|
|
1499
|
-
)
|
|
1500
|
-
continue
|
|
1501
|
-
if statement.startswith("ALTER TABLE scans"):
|
|
1502
|
-
add_column_if_missing(
|
|
1503
|
-
connection,
|
|
1504
|
-
"scans",
|
|
1505
|
-
"target_id",
|
|
1506
|
-
"TEXT REFERENCES security_targets(id)",
|
|
1507
|
-
)
|
|
1312
|
+
if statement.startswith(("ALTER TABLE workspaces", "ALTER TABLE scans")):
|
|
1313
|
+
add_migration_column(connection, statement)
|
|
1508
1314
|
continue
|
|
1509
1315
|
statement = statement.replace("CREATE TABLE ", "CREATE TABLE IF NOT EXISTS ", 1)
|
|
1510
1316
|
statement = statement.replace("CREATE INDEX ", "CREATE INDEX IF NOT EXISTS ", 1)
|
|
@@ -1522,6 +1328,19 @@ def repair_stable_targets_migration(connection: sqlite3.Connection) -> bool:
|
|
|
1522
1328
|
return True
|
|
1523
1329
|
|
|
1524
1330
|
|
|
1331
|
+
def repair_additive_migration(connection: sqlite3.Connection, version: int) -> None:
|
|
1332
|
+
sql = next(sql for migration_version, _, sql in MIGRATIONS if migration_version == version)
|
|
1333
|
+
for statement in sql_statements(sql):
|
|
1334
|
+
add_migration_column(connection, statement)
|
|
1335
|
+
|
|
1336
|
+
|
|
1337
|
+
def add_migration_column(connection: sqlite3.Connection, statement: str) -> None:
|
|
1338
|
+
_, _, table, _, _, column, definition = statement.removesuffix(";").split(None, 6)
|
|
1339
|
+
# Preserve the compact declarations used by historical repairs, including CHECK errors.
|
|
1340
|
+
definition = " ".join(definition.split()).replace("( ", "(").replace(" )", ")")
|
|
1341
|
+
add_column_if_missing(connection, table, column, definition)
|
|
1342
|
+
|
|
1343
|
+
|
|
1525
1344
|
def add_column_if_missing(
|
|
1526
1345
|
connection: sqlite3.Connection, table: str, column: str, definition: str
|
|
1527
1346
|
) -> None:
|
|
@@ -1543,9 +1362,5 @@ def sql_statements(script: str) -> list[str]:
|
|
|
1543
1362
|
return statements
|
|
1544
1363
|
|
|
1545
1364
|
|
|
1546
|
-
def main() -> None:
|
|
1547
|
-
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
1365
|
if __name__ == "__main__":
|
|
1551
|
-
|
|
1366
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
import argparse
|
|
4
4
|
import json
|
|
5
5
|
import sqlite3
|
|
6
|
+
import sys
|
|
6
7
|
from contextlib import closing
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
from typing import Any
|
|
9
10
|
from urllib.parse import quote
|
|
10
11
|
|
|
12
|
+
# Some plugin hosts launch Python with safe-path isolation enabled.
|
|
13
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
11
14
|
from workbench_finding_index import upsert_finding
|
|
12
15
|
|
|
13
16
|
FIELDS = {
|
|
@@ -40,7 +40,10 @@ def finding_source_excerpt(
|
|
|
40
40
|
source = scanned_source_text(scan, target, path)
|
|
41
41
|
if not source or "\0" in source:
|
|
42
42
|
return None
|
|
43
|
-
|
|
43
|
+
# Match location validation and SARIF hashing: CR, LF, and CRLF are line breaks.
|
|
44
|
+
# Keep form feeds and Unicode separators within their original source lines.
|
|
45
|
+
normalized = source.replace("\r\n", "\n").replace("\r", "\n")
|
|
46
|
+
lines = normalized.removesuffix("\n").split("\n")
|
|
44
47
|
if start_line < 1 or start_line > len(lines):
|
|
45
48
|
return None
|
|
46
49
|
last_affected_line = end_line if isinstance(end_line, int) else start_line
|
|
@@ -87,9 +90,5 @@ def safe_source_path(target: Path, relative_path: str) -> Path | None:
|
|
|
87
90
|
return path
|
|
88
91
|
|
|
89
92
|
|
|
90
|
-
def main() -> None:
|
|
91
|
-
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
92
|
-
|
|
93
|
-
|
|
94
93
|
if __name__ == "__main__":
|
|
95
|
-
|
|
94
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|