@openai/codex-security 0.8.2 → 0.8.3
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 +43 -61
- package/_bundled_plugin/.app.json +4 -0
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- 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/permission-profile-preflight.mjs +46 -12
- 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/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +28 -0
- package/_bundled_plugin/references/finding-detail-fields.md +1 -0
- package/_bundled_plugin/references/threat-model.md +1 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
- package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
- package/_bundled_plugin/scripts/finding_preview.py +5 -29
- package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
- package/_bundled_plugin/scripts/report_projection.py +87 -136
- package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
- package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
- package/_bundled_plugin/scripts/workbench_cli.py +102 -13
- package/_bundled_plugin/scripts/workbench_constants.py +9 -0
- package/_bundled_plugin/scripts/workbench_db.py +186 -360
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
- package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
- package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
- package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
- package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_setup.py +239 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
- package/_bundled_plugin/scripts/workbench_target.py +213 -20
- package/_bundled_plugin/scripts/workbench_validation.py +1 -9
- package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
- package/_bundled_plugin/shared/workbench-migrations.json +19 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +64 -35
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +14 -8
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
- package/dist/api.d.ts +6 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +411 -160
- package/dist/api.js.map +1 -1
- package/dist/auth.js +6 -1
- package/dist/auth.js.map +1 -1
- package/dist/blackduck-findings.d.ts +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +305 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity-records.d.ts +5 -0
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +6 -8
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +28 -9
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +608 -258
- package/dist/cli.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +6 -5
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +162 -40
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +157 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +28 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +75 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +1 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +19 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2120 -39
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +4 -0
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +11 -4
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +3 -8
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +8 -2
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +36 -8
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deep-scan.d.ts +11 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +235 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +7 -37
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +5 -11
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +9 -0
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +325 -179
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +12 -0
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1202 -214
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +8 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +65 -54
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +2 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +111 -0
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +29 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +314 -44
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-normalization.d.ts +1 -1
- package/dist/finding-normalization.d.ts.map +1 -1
- package/dist/finding-normalization.js +46 -11
- package/dist/finding-normalization.js.map +1 -1
- package/dist/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- package/dist/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -29
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +7 -16
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +344 -56
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +2 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +55 -33
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +13 -18
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.js +18 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +131 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +22 -12
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +34 -20
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +90 -35
- package/dist/patch-tui.js.map +1 -1
- package/dist/private-finding-import.d.ts +246 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +387 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +10 -2
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +72 -10
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.js +7 -1
- package/dist/publication.js.map +1 -1
- package/dist/reader-selection.d.ts +13 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +81 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +5 -0
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +30 -0
- package/dist/remediation.js.map +1 -1
- package/dist/result.d.ts +2 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -1
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +95 -52
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.js +40 -17
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +1 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +11 -13
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +16 -37
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +2 -0
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +22 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/scanner-import.d.ts +46 -6
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +208 -42
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +14 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +67 -0
- package/dist/scanner-repository-url.js.map +1 -0
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +20 -48
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +12 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +198 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- package/dist/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +21 -20
- package/dist/snyk-findings.js.map +1 -1
- package/dist/sonar-collector.d.ts +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +383 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +279 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +3 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +18 -12
- package/dist/targets.js.map +1 -1
- package/dist/terminal-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.js.map +1 -0
- package/dist/validation-records.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +0 -16
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +7 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +371 -0
- package/dist/veracode-findings.js.map +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -0
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +10 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +88 -49
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +1 -1
- package/docs/cli.md +310 -477
- package/docs/dedupe-records.md +10 -0
- package/docs/findings-service.md +21 -8
- package/docs/hosted-scans.md +16 -1
- package/package.json +8 -9
- package/schemas/external-findings.schema.json +12 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -1
- package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -49
- package/dist/deduplication/records-protocol.js.map +0 -1
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { cloudRepositoryUrlKey, repositoryUrlKey, validateExternalEvidence, } from "./external-import-contract.js";
|
|
3
|
+
import { isRecord } from "./record.js";
|
|
4
|
+
import { array, normalizeRecords, readScannerJson, record, relativePath, requiredText, text, } from "./scanner-import.js";
|
|
5
|
+
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
6
|
+
const sonarFormat = "sonar-issues/v1";
|
|
7
|
+
const captureText = z.string().refine((value) => Boolean(value.trim()));
|
|
8
|
+
const captureSchema = z.object({
|
|
9
|
+
format: z.literal(sonarFormat),
|
|
10
|
+
server: captureText,
|
|
11
|
+
organization: captureText,
|
|
12
|
+
project: captureText,
|
|
13
|
+
branch: captureText.optional(),
|
|
14
|
+
pullRequest: captureText.optional(),
|
|
15
|
+
repositoryUrl: captureText.optional(),
|
|
16
|
+
projectBase: z
|
|
17
|
+
.string()
|
|
18
|
+
.refine((path) => path === "" || relativePath(path) === path)
|
|
19
|
+
.optional(),
|
|
20
|
+
pages: z.array(z.unknown()).min(1),
|
|
21
|
+
queryPageCounts: z.array(z.int().positive()).min(1).optional(),
|
|
22
|
+
});
|
|
23
|
+
export function parseSonarCapture(value) {
|
|
24
|
+
const capture = captureSchema.parse(value);
|
|
25
|
+
if (capture.branch && capture.pullRequest)
|
|
26
|
+
throw new Error("A Sonar capture must select a branch or a pull request, not both.");
|
|
27
|
+
const url = URL.parse(capture.server);
|
|
28
|
+
if (!url ||
|
|
29
|
+
!["https:", "http:"].includes(url.protocol) ||
|
|
30
|
+
url.username ||
|
|
31
|
+
url.password ||
|
|
32
|
+
url.search ||
|
|
33
|
+
url.hash)
|
|
34
|
+
throw new Error("Expected an HTTP(S) Sonar server URL without credentials, query or fragment.");
|
|
35
|
+
capture.server = url.href.replace(/\/$/u, "");
|
|
36
|
+
if (capture.repositoryUrl)
|
|
37
|
+
declaredScannerRepositoryUrl(capture.repositoryUrl, "Sonar", "local");
|
|
38
|
+
return capture;
|
|
39
|
+
}
|
|
40
|
+
const issueScopeFields = [
|
|
41
|
+
"organization",
|
|
42
|
+
"project",
|
|
43
|
+
"branch",
|
|
44
|
+
"pullRequest",
|
|
45
|
+
];
|
|
46
|
+
const scopeFields = ["server", ...issueScopeFields];
|
|
47
|
+
function mergeSonarScope(scope, data, fields = scopeFields) {
|
|
48
|
+
for (const field of fields) {
|
|
49
|
+
const value = text(data[field]);
|
|
50
|
+
if (value === null)
|
|
51
|
+
continue;
|
|
52
|
+
if (scope[field] !== undefined && scope[field] !== value)
|
|
53
|
+
throw new Error(`The Sonar export contains conflicting ${field} values.`);
|
|
54
|
+
scope[field] = value;
|
|
55
|
+
}
|
|
56
|
+
if (scope.branch && scope.pullRequest)
|
|
57
|
+
throw new Error("The Sonar export mixes branch and pull request results.");
|
|
58
|
+
}
|
|
59
|
+
function requireConsistentSonarRef(scope, hasUnscopedIssue) {
|
|
60
|
+
if (hasUnscopedIssue && (scope.branch || scope.pullRequest))
|
|
61
|
+
throw new Error("The Sonar export mixes issues with a named ref and issues without a ref.");
|
|
62
|
+
}
|
|
63
|
+
/** Normalized Sonar reports and their individual issues retain the source repository. */
|
|
64
|
+
export function sonarRepositoryUrls(provider, findings, report, target) {
|
|
65
|
+
const urls = new Set();
|
|
66
|
+
function add(data, scope) {
|
|
67
|
+
if (data?.["format"] !== sonarFormat)
|
|
68
|
+
return;
|
|
69
|
+
if (provider !== "sonar")
|
|
70
|
+
throw new Error("Retained Sonar evidence requires the sonar provider.");
|
|
71
|
+
mergeSonarScope(scope, data);
|
|
72
|
+
urls.add(declaredScannerRepositoryUrl(data["repositoryUrl"], "Sonar", target));
|
|
73
|
+
}
|
|
74
|
+
const reportScope = {};
|
|
75
|
+
add(report, reportScope);
|
|
76
|
+
const scope = { ...reportScope };
|
|
77
|
+
let hasUnscopedIssue = false;
|
|
78
|
+
for (const { evidence, source_finding_id } of findings) {
|
|
79
|
+
const data = evidence.source_data;
|
|
80
|
+
const rowScope = { ...reportScope };
|
|
81
|
+
add(data ?? undefined, rowScope);
|
|
82
|
+
if (data?.["format"] === sonarFormat && data["issue"] !== undefined) {
|
|
83
|
+
const issue = record(data["issue"], "Retained Sonar issue");
|
|
84
|
+
mergeSonarScope(rowScope, issue, issueScopeFields);
|
|
85
|
+
if (requiredText(issue["key"], "Retained Sonar issue key") !==
|
|
86
|
+
source_finding_id)
|
|
87
|
+
throw new Error("The normalized finding ID does not match the retained Sonar issue key.");
|
|
88
|
+
}
|
|
89
|
+
mergeSonarScope(scope, rowScope);
|
|
90
|
+
if (!rowScope.branch && !rowScope.pullRequest)
|
|
91
|
+
hasUnscopedIssue = true;
|
|
92
|
+
}
|
|
93
|
+
requireConsistentSonarRef(scope, hasUnscopedIssue);
|
|
94
|
+
if (scope.branch &&
|
|
95
|
+
findings.some(({ evidence }) => (report?.["format"] === sonarFormat ||
|
|
96
|
+
evidence.source_data?.["format"] === sonarFormat) &&
|
|
97
|
+
evidence.branch != null &&
|
|
98
|
+
evidence.branch !== scope.branch))
|
|
99
|
+
throw new Error("The finding branch does not match the retained Sonar branch.");
|
|
100
|
+
return urls;
|
|
101
|
+
}
|
|
102
|
+
const pagingSchema = z.object({
|
|
103
|
+
pageIndex: z.int().positive(),
|
|
104
|
+
pageSize: z.int().positive(),
|
|
105
|
+
total: z.int().nonnegative(),
|
|
106
|
+
});
|
|
107
|
+
function indexByKey(value, label) {
|
|
108
|
+
const index = new Map();
|
|
109
|
+
for (const item of array(value ?? [], label)) {
|
|
110
|
+
const row = record(item, label);
|
|
111
|
+
const key = requiredText(row["key"], `${label} key`);
|
|
112
|
+
index.set(key, row);
|
|
113
|
+
}
|
|
114
|
+
return index;
|
|
115
|
+
}
|
|
116
|
+
export function mergeSonarIssueScope(scope, issue) {
|
|
117
|
+
mergeSonarScope(scope, issue, issueScopeFields);
|
|
118
|
+
}
|
|
119
|
+
function readPage(value) {
|
|
120
|
+
const page = record(value, "Sonar issue search page");
|
|
121
|
+
return {
|
|
122
|
+
paging: pagingSchema.parse(page["paging"]),
|
|
123
|
+
issues: array(page["issues"], "Sonar issues").map((issue) => record(issue, "Sonar issue")),
|
|
124
|
+
components: indexByKey(page["components"], "Sonar component"),
|
|
125
|
+
rules: indexByKey(page["rules"], "Sonar rule"),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function completeQueryPages(values) {
|
|
129
|
+
const pages = values
|
|
130
|
+
.map(readPage)
|
|
131
|
+
.sort((a, b) => a.paging.pageIndex - b.paging.pageIndex);
|
|
132
|
+
const first = pages[0]?.paging;
|
|
133
|
+
if (!first ||
|
|
134
|
+
pages.length !== Math.max(1, Math.ceil(first.total / first.pageSize)) ||
|
|
135
|
+
pages.some(({ paging, issues }, i) => paging.pageIndex !== i + 1 ||
|
|
136
|
+
paging.total !== first.total ||
|
|
137
|
+
paging.pageSize !== first.pageSize ||
|
|
138
|
+
issues.length !==
|
|
139
|
+
Math.min(first.pageSize, first.total - i * first.pageSize)))
|
|
140
|
+
throw new Error("Supply every Sonar issue search page exactly once, with consistent paging and issue counts.");
|
|
141
|
+
return pages;
|
|
142
|
+
}
|
|
143
|
+
export function completeSonarPages(values, queryPageCounts) {
|
|
144
|
+
const counts = queryPageCounts ?? [values.length];
|
|
145
|
+
if (counts.reduce((sum, count) => sum + count, 0) !== values.length)
|
|
146
|
+
throw new Error("Sonar query page counts do not match the captured pages.");
|
|
147
|
+
let offset = 0;
|
|
148
|
+
const pages = counts.flatMap((count) => {
|
|
149
|
+
const query = values.slice(offset, offset + count);
|
|
150
|
+
offset += count;
|
|
151
|
+
return completeQueryPages(query);
|
|
152
|
+
});
|
|
153
|
+
const ids = new Set();
|
|
154
|
+
for (const { issues } of pages) {
|
|
155
|
+
for (const issue of issues) {
|
|
156
|
+
const id = text(issue["key"]);
|
|
157
|
+
if (id && ids.has(id))
|
|
158
|
+
throw new Error("Sonar issue search pages overlap. Collect the selection again.");
|
|
159
|
+
if (id)
|
|
160
|
+
ids.add(id);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return pages;
|
|
164
|
+
}
|
|
165
|
+
const severityLevels = {
|
|
166
|
+
BLOCKER: "critical",
|
|
167
|
+
HIGH: "high",
|
|
168
|
+
MEDIUM: "medium",
|
|
169
|
+
LOW: "low",
|
|
170
|
+
INFO: "informational",
|
|
171
|
+
CRITICAL: "high",
|
|
172
|
+
MAJOR: "medium",
|
|
173
|
+
MINOR: "low",
|
|
174
|
+
};
|
|
175
|
+
function securitySeverity(issue) {
|
|
176
|
+
const impacts = array(issue["impacts"] ?? [], "Sonar issue impacts");
|
|
177
|
+
const security = impacts.find((impact) => isRecord(impact) && impact["softwareQuality"] === "SECURITY");
|
|
178
|
+
if (!isRecord(security) &&
|
|
179
|
+
(impacts.length || issue["type"] !== "VULNERABILITY"))
|
|
180
|
+
throw new Error("Sonar issue has no security impact or legacy vulnerability type.");
|
|
181
|
+
const value = isRecord(security) ? security["severity"] : issue["severity"];
|
|
182
|
+
return typeof value === "string" && Object.hasOwn(severityLevels, value)
|
|
183
|
+
? severityLevels[value]
|
|
184
|
+
: "unknown";
|
|
185
|
+
}
|
|
186
|
+
function relatedComponents(issue, primary, components) {
|
|
187
|
+
const keys = new Set([primary]);
|
|
188
|
+
for (const value of array(issue["flows"] ?? [], "Sonar issue flows")) {
|
|
189
|
+
const flow = record(value, "Sonar flow");
|
|
190
|
+
for (const entry of array(flow["locations"], "Sonar flow locations")) {
|
|
191
|
+
const location = record(entry, "Sonar flow location");
|
|
192
|
+
const key = text(location["component"]);
|
|
193
|
+
if (key)
|
|
194
|
+
keys.add(key);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return Array.from(keys).flatMap((key) => components.get(key) ?? []);
|
|
198
|
+
}
|
|
199
|
+
function issueLink(server, project, id, branch, pullRequest) {
|
|
200
|
+
const link = new URL("project/issues", server + "/");
|
|
201
|
+
link.searchParams.set("id", project);
|
|
202
|
+
if (branch)
|
|
203
|
+
link.searchParams.set("branch", branch);
|
|
204
|
+
if (pullRequest)
|
|
205
|
+
link.searchParams.set("pullRequest", pullRequest);
|
|
206
|
+
link.searchParams.set("open", id);
|
|
207
|
+
link.searchParams.set("issues", id);
|
|
208
|
+
return link.href;
|
|
209
|
+
}
|
|
210
|
+
export function normalizeSonarFindings(input, sourceRepositoryUrl, target = "cloud") {
|
|
211
|
+
const capture = isRecord(input) && "format" in input ? parseSonarCapture(input) : undefined;
|
|
212
|
+
const repository = declaredScannerRepositoryUrl(capture?.repositoryUrl ?? sourceRepositoryUrl, "Sonar", target);
|
|
213
|
+
if (capture?.repositoryUrl && sourceRepositoryUrl) {
|
|
214
|
+
const key = target === "cloud" ? cloudRepositoryUrlKey : repositoryUrlKey;
|
|
215
|
+
if (key(repository) !==
|
|
216
|
+
key(declaredScannerRepositoryUrl(sourceRepositoryUrl, "Sonar", target)))
|
|
217
|
+
throw new Error("The Sonar capture repository does not match the declared source repository.");
|
|
218
|
+
}
|
|
219
|
+
const pages = completeSonarPages(capture?.pages ?? (Array.isArray(input) ? input : [input]), capture?.queryPageCounts);
|
|
220
|
+
const rows = pages.flatMap((page) => page.issues.map((issue) => ({ issue, page })));
|
|
221
|
+
const scope = {};
|
|
222
|
+
if (capture)
|
|
223
|
+
mergeSonarScope(scope, capture);
|
|
224
|
+
const hasUnscopedIssue = rows.some(({ issue }) => !text(issue["branch"]) && !text(issue["pullRequest"]));
|
|
225
|
+
for (const { issue } of rows) {
|
|
226
|
+
requiredText(issue["project"], "Sonar issue project");
|
|
227
|
+
mergeSonarIssueScope(scope, issue);
|
|
228
|
+
}
|
|
229
|
+
requireConsistentSonarRef(scope, !capture?.branch && !capture?.pullRequest && hasUnscopedIssue);
|
|
230
|
+
const context = {
|
|
231
|
+
format: sonarFormat,
|
|
232
|
+
...(capture?.projectBase !== undefined && {
|
|
233
|
+
projectBase: capture.projectBase,
|
|
234
|
+
}),
|
|
235
|
+
...scope,
|
|
236
|
+
repositoryUrl: repository,
|
|
237
|
+
};
|
|
238
|
+
return normalizeRecords(rows, ({ issue, page }, id) => {
|
|
239
|
+
const component = requiredText(issue["component"], "Sonar issue component");
|
|
240
|
+
const componentPath = relativePath(page.components.get(component)?.["path"]);
|
|
241
|
+
const base = capture?.projectBase;
|
|
242
|
+
const path = componentPath && base !== undefined
|
|
243
|
+
? base
|
|
244
|
+
? `${base}/${componentPath}`
|
|
245
|
+
: componentPath
|
|
246
|
+
: null;
|
|
247
|
+
const range = issue["textRange"] == null
|
|
248
|
+
? null
|
|
249
|
+
: record(issue["textRange"], "Sonar issue textRange");
|
|
250
|
+
const line = range?.["startLine"] ?? issue["line"] ?? null;
|
|
251
|
+
const rule = requiredText(issue["rule"], "Sonar issue rule");
|
|
252
|
+
const descriptor = page.rules.get(rule);
|
|
253
|
+
const name = text(descriptor?.["name"]);
|
|
254
|
+
const updated = text(issue["updateDate"]);
|
|
255
|
+
const severity = securitySeverity(issue);
|
|
256
|
+
return validateExternalEvidence({
|
|
257
|
+
title: name ?? rule,
|
|
258
|
+
severity,
|
|
259
|
+
description: text(issue["message"]),
|
|
260
|
+
url: capture
|
|
261
|
+
? issueLink(capture.server, capture.project, id, scope.branch, scope.pullRequest)
|
|
262
|
+
: null,
|
|
263
|
+
locations: path ? [{ path, line }] : [],
|
|
264
|
+
branch: scope.branch ?? null,
|
|
265
|
+
source_updated_at: updated
|
|
266
|
+
? Math.floor(Date.parse(updated) / 1000)
|
|
267
|
+
: null,
|
|
268
|
+
details: {
|
|
269
|
+
kind: "sast",
|
|
270
|
+
scanner_origin: "SonarQube",
|
|
271
|
+
repository: { url: repository },
|
|
272
|
+
source_status: text(issue["issueStatus"]) ?? text(issue["status"]),
|
|
273
|
+
rule: { id: rule, name },
|
|
274
|
+
code: { end_line: path ? (range?.["endLine"] ?? null) : null },
|
|
275
|
+
},
|
|
276
|
+
source_data: structuredClone({
|
|
277
|
+
...context,
|
|
278
|
+
issue,
|
|
279
|
+
components: relatedComponents(issue, component, page.components),
|
|
280
|
+
...(descriptor && { rule: descriptor }),
|
|
281
|
+
}),
|
|
282
|
+
}, target);
|
|
283
|
+
}, ({ issue }) => requiredText(issue["key"], "Sonar issue key"), target, { report: context });
|
|
284
|
+
}
|
|
285
|
+
export async function readSonarFindings(path, sourceRepositoryUrl, target = "cloud") {
|
|
286
|
+
return normalizeSonarFindings(await readScannerJson(path), sourceRepositoryUrl, target);
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=sonar-findings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sonar-findings.js","sourceRo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E,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;aAC/D;YACD,WAAW,EAAE,eAAe,CAAC;gBAC3B,GAAG,OAAO;gBACV,KAAK;gBACL,UAAU,EAAE,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC;gBAChE,GAAG,CAAC,UAAU,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;aACxC,CAAC;SACH,EACD,MAAM,CACP,CAAC;IACJ,CAAC,EACD,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC,EAC5D,MAAM,EACN,EAAE,MAAM,EAAE,OAAO,EAAE,CAC6B,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,mBAA2B,EAC3B,MAAM,GAAyB,OAAO;IAEtC,OAAO,sBAAsB,CAC3B,MAAM,eAAe,CAAC,IAAI,CAAC,EAC3B,mBAAmB,EACnB,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n cloudRepositoryUrlKey,\n type ExternalImportTarget,\n repositoryUrlKey,\n validateExternalEvidence,\n} from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport type { Provider, Severity } from \"./external-import-models.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n text,\n} from \"./scanner-import.js\";\nimport { declaredScannerRepositoryUrl } from \"./scanner-repository-url.js\";\n\nconst sonarFormat = \"sonar-issues/v1\";\nconst captureText = z.string().refine((value) => Boolean(value.trim()));\nconst captureSchema = z.object({\n format: z.literal(sonarFormat),\n server: captureText,\n organization: captureText,\n project: captureText,\n branch: captureText.optional(),\n pullRequest: captureText.optional(),\n repositoryUrl: captureText.optional(),\n projectBase: z\n .string()\n .refine((path) => path === \"\" || relativePath(path) === path)\n .optional(),\n pages: z.array(z.unknown()).min(1),\n queryPageCounts: z.array(z.int().positive()).min(1).optional(),\n});\nexport type SonarCapture = z.infer<typeof captureSchema>;\n\nexport function parseSonarCapture(value: unknown): SonarCapture {\n const capture = captureSchema.parse(value);\n if (capture.branch && capture.pullRequest)\n throw new Error(\n \"A Sonar capture must select a branch or a pull request, not both.\",\n );\n const url = URL.parse(capture.server);\n if (\n !url ||\n ![\"https:\", \"http:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n )\n throw new Error(\n \"Expected an HTTP(S) Sonar server URL without credentials, query or fragment.\",\n );\n capture.server = url.href.replace(/\\/$/u, \"\");\n if (capture.repositoryUrl)\n declaredScannerRepositoryUrl(capture.repositoryUrl, \"Sonar\", \"local\");\n return capture;\n}\n\ntype NativeRecord = Record<string, unknown>;\n\nconst issueScopeFields = [\n \"organization\",\n \"project\",\n \"branch\",\n \"pullRequest\",\n] as const;\nconst scopeFields = [\"server\", ...issueScopeFields] as const;\ntype SonarScope = Partial<Record<(typeof scopeFields)[number], string>>;\n\nfunction mergeSonarScope(\n scope: SonarScope,\n data: NativeRecord,\n fields: readonly (keyof SonarScope)[] = scopeFields,\n) {\n for (const field of fields) {\n const value = text(data[field]);\n if (value === null) continue;\n if (scope[field] !== undefined && scope[field] !== value)\n throw new Error(`The Sonar export contains conflicting ${field} values.`);\n scope[field] = value;\n }\n if (scope.branch && scope.pullRequest)\n throw new Error(\"The Sonar export mixes branch and pull request results.\");\n}\n\nfunction requireConsistentSonarRef(\n scope: SonarScope,\n hasUnscopedIssue: boolean,\n) {\n if (hasUnscopedIssue && (scope.branch || scope.pullRequest))\n throw new Error(\n \"The Sonar export mixes issues with a named ref and issues without a ref.\",\n );\n}\n\n/** Normalized Sonar reports and their individual issues retain the source repository. */\nexport function sonarRepositoryUrls(\n provider: Provider,\n findings: ExternalFindings[\"findings\"],\n report: ExternalFindings[\"report\"],\n target: ExternalImportTarget,\n): Set<string> {\n const urls = new Set<string>();\n function add(data: NativeRecord | undefined, scope: SonarScope) {\n if (data?.[\"format\"] !== sonarFormat) return;\n if (provider !== \"sonar\")\n throw new Error(\"Retained Sonar evidence requires the sonar provider.\");\n mergeSonarScope(scope, data);\n urls.add(\n declaredScannerRepositoryUrl(data[\"repositoryUrl\"], \"Sonar\", target),\n );\n }\n const reportScope: SonarScope = {};\n add(report, reportScope);\n const scope = { ...reportScope };\n let hasUnscopedIssue = false;\n for (const { evidence, source_finding_id } of findings) {\n const data = evidence.source_data;\n const rowScope = { ...reportScope };\n add(data ?? undefined, rowScope);\n if (data?.[\"format\"] === sonarFormat && data[\"issue\"] !== undefined) {\n const issue = record(data[\"issue\"], \"Retained Sonar issue\");\n mergeSonarScope(rowScope, issue, issueScopeFields);\n if (\n requiredText(issue[\"key\"], \"Retained Sonar issue key\") !==\n source_finding_id\n )\n throw new Error(\n \"The normalized finding ID does not match the retained Sonar issue key.\",\n );\n }\n mergeSonarScope(scope, rowScope);\n if (!rowScope.branch && !rowScope.pullRequest) hasUnscopedIssue = true;\n }\n requireConsistentSonarRef(scope, hasUnscopedIssue);\n if (\n scope.branch &&\n findings.some(\n ({ evidence }) =>\n (report?.[\"format\"] === sonarFormat ||\n evidence.source_data?.[\"format\"] === sonarFormat) &&\n evidence.branch != null &&\n evidence.branch !== scope.branch,\n )\n )\n throw new Error(\n \"The finding branch does not match the retained Sonar branch.\",\n );\n return urls;\n}\n\nconst pagingSchema = z.object({\n pageIndex: z.int().positive(),\n pageSize: z.int().positive(),\n total: z.int().nonnegative(),\n});\n\nfunction indexByKey(value: unknown, label: string) {\n const index = new Map<string, NativeRecord>();\n for (const item of array(value ?? [], label)) {\n const row = record(item, label);\n const key = requiredText(row[\"key\"], `${label} key`);\n index.set(key, row);\n }\n return index;\n}\n\nexport function mergeSonarIssueScope(scope: SonarScope, issue: NativeRecord) {\n mergeSonarScope(scope, issue, issueScopeFields);\n}\n\nfunction readPage(value: unknown) {\n const page = record(value, \"Sonar issue search page\");\n return {\n paging: pagingSchema.parse(page[\"paging\"]),\n issues: array(page[\"issues\"], \"Sonar issues\").map((issue) =>\n record(issue, \"Sonar issue\"),\n ),\n components: indexByKey(page[\"components\"], \"Sonar component\"),\n rules: indexByKey(page[\"rules\"], \"Sonar rule\"),\n };\n}\n\nfunction completeQueryPages(values: unknown[]) {\n const pages = values\n .map(readPage)\n .sort((a, b) => a.paging.pageIndex - b.paging.pageIndex);\n const first = pages[0]?.paging;\n if (\n !first ||\n pages.length !== Math.max(1, Math.ceil(first.total / first.pageSize)) ||\n pages.some(\n ({ paging, issues }, i) =>\n paging.pageIndex !== i + 1 ||\n paging.total !== first.total ||\n paging.pageSize !== first.pageSize ||\n issues.length !==\n Math.min(first.pageSize, first.total - i * first.pageSize),\n )\n )\n throw new Error(\n \"Supply every Sonar issue search page exactly once, with consistent paging and issue counts.\",\n );\n return pages;\n}\n\nexport function completeSonarPages(\n values: unknown[],\n queryPageCounts?: number[],\n) {\n const counts = queryPageCounts ?? [values.length];\n if (counts.reduce((sum, count) => sum + count, 0) !== values.length)\n throw new Error(\"Sonar query page counts do not match the captured pages.\");\n let offset = 0;\n const pages = counts.flatMap((count) => {\n const query = values.slice(offset, offset + count);\n offset += count;\n return completeQueryPages(query);\n });\n const ids = new Set<string>();\n for (const { issues } of pages) {\n for (const issue of issues) {\n const id = text(issue[\"key\"]);\n if (id && ids.has(id))\n throw new Error(\n \"Sonar issue search pages overlap. Collect the selection again.\",\n );\n if (id) ids.add(id);\n }\n }\n return pages;\n}\n\nconst severityLevels: Readonly<Record<string, Severity>> = {\n BLOCKER: \"critical\",\n HIGH: \"high\",\n MEDIUM: \"medium\",\n LOW: \"low\",\n INFO: \"informational\",\n CRITICAL: \"high\",\n MAJOR: \"medium\",\n MINOR: \"low\",\n};\n\nfunction securitySeverity(issue: NativeRecord): Severity {\n const impacts = array(issue[\"impacts\"] ?? [], \"Sonar issue impacts\");\n const security = impacts.find(\n (impact) => isRecord(impact) && impact[\"softwareQuality\"] === \"SECURITY\",\n );\n if (\n !isRecord(security) &&\n (impacts.length || issue[\"type\"] !== \"VULNERABILITY\")\n )\n throw new Error(\n \"Sonar issue has no security impact or legacy vulnerability type.\",\n );\n const value = isRecord(security) ? security[\"severity\"] : issue[\"severity\"];\n return typeof value === \"string\" && Object.hasOwn(severityLevels, value)\n ? severityLevels[value]!\n : \"unknown\";\n}\n\nfunction relatedComponents(\n issue: NativeRecord,\n primary: string,\n components: Map<string, NativeRecord>,\n) {\n const keys = new Set([primary]);\n for (const value of array(issue[\"flows\"] ?? [], \"Sonar issue flows\")) {\n const flow = record(value, \"Sonar flow\");\n for (const entry of array(flow[\"locations\"], \"Sonar flow locations\")) {\n const location = record(entry, \"Sonar flow location\");\n const key = text(location[\"component\"]);\n if (key) keys.add(key);\n }\n }\n return Array.from(keys).flatMap((key) => components.get(key) ?? []);\n}\n\nfunction issueLink(\n server: string,\n project: string,\n id: string,\n branch?: string,\n pullRequest?: string,\n) {\n const link = new URL(\"project/issues\", server + \"/\");\n link.searchParams.set(\"id\", project);\n if (branch) link.searchParams.set(\"branch\", branch);\n if (pullRequest) link.searchParams.set(\"pullRequest\", pullRequest);\n link.searchParams.set(\"open\", id);\n link.searchParams.set(\"issues\", id);\n return link.href;\n}\n\nexport function normalizeSonarFindings(\n input: unknown,\n sourceRepositoryUrl: string,\n target: ExternalImportTarget = \"cloud\",\n) {\n const capture =\n isRecord(input) && \"format\" in input ? parseSonarCapture(input) : undefined;\n const repository = declaredScannerRepositoryUrl(\n capture?.repositoryUrl ?? sourceRepositoryUrl,\n \"Sonar\",\n target,\n );\n if (capture?.repositoryUrl && sourceRepositoryUrl) {\n const key = target === \"cloud\" ? cloudRepositoryUrlKey : repositoryUrlKey;\n if (\n key(repository) !==\n key(declaredScannerRepositoryUrl(sourceRepositoryUrl, \"Sonar\", target))\n )\n throw new Error(\n \"The Sonar capture repository does not match the declared source repository.\",\n );\n }\n const pages = completeSonarPages(\n capture?.pages ?? (Array.isArray(input) ? input : [input]),\n capture?.queryPageCounts,\n );\n const rows = pages.flatMap((page) =>\n page.issues.map((issue) => ({ issue, page })),\n );\n const scope: SonarScope = {};\n if (capture) mergeSonarScope(scope, capture);\n const hasUnscopedIssue = rows.some(\n ({ issue }) => !text(issue[\"branch\"]) && !text(issue[\"pullRequest\"]),\n );\n for (const { issue } of rows) {\n requiredText(issue[\"project\"], \"Sonar issue project\");\n mergeSonarIssueScope(scope, issue);\n }\n requireConsistentSonarRef(\n scope,\n !capture?.branch && !capture?.pullRequest && hasUnscopedIssue,\n );\n const context = {\n format: sonarFormat,\n ...(capture?.projectBase !== undefined && {\n projectBase: capture.projectBase,\n }),\n ...scope,\n repositoryUrl: repository,\n };\n return normalizeRecords(\n rows,\n ({ issue, page }, id) => {\n const component = requiredText(\n issue[\"component\"],\n \"Sonar issue component\",\n );\n const componentPath = relativePath(\n page.components.get(component)?.[\"path\"],\n );\n const base = capture?.projectBase;\n const path =\n componentPath && base !== undefined\n ? base\n ? `${base}/${componentPath}`\n : componentPath\n : null;\n const range =\n issue[\"textRange\"] == null\n ? null\n : record(issue[\"textRange\"], \"Sonar issue textRange\");\n const line = range?.[\"startLine\"] ?? issue[\"line\"] ?? null;\n const rule = requiredText(issue[\"rule\"], \"Sonar issue rule\");\n const descriptor = page.rules.get(rule);\n const name = text(descriptor?.[\"name\"]);\n const updated = text(issue[\"updateDate\"]);\n const severity = securitySeverity(issue);\n return validateExternalEvidence(\n {\n title: name ?? rule,\n severity,\n description: text(issue[\"message\"]),\n url: capture\n ? issueLink(\n capture.server,\n capture.project,\n id,\n scope.branch,\n scope.pullRequest,\n )\n : null,\n locations: path ? [{ path, line }] : [],\n branch: scope.branch ?? null,\n source_updated_at: updated\n ? Math.floor(Date.parse(updated) / 1000)\n : null,\n details: {\n kind: \"sast\",\n scanner_origin: \"SonarQube\",\n repository: { url: repository },\n source_status: text(issue[\"issueStatus\"]) ?? text(issue[\"status\"]),\n rule: { id: rule, name },\n code: { end_line: path ? (range?.[\"endLine\"] ?? null) : null },\n },\n source_data: structuredClone({\n ...context,\n issue,\n components: relatedComponents(issue, component, page.components),\n ...(descriptor && { rule: descriptor }),\n }),\n },\n target,\n );\n },\n ({ issue }) => requiredText(issue[\"key\"], \"Sonar issue key\"),\n target,\n { report: context },\n ) as ExternalFindings & { report: typeof context };\n}\n\nexport async function readSonarFindings(\n path: string,\n sourceRepositoryUrl: string,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeSonarFindings(\n await readScannerJson(path),\n sourceRepositoryUrl,\n target,\n );\n}\n"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { collectSonarIssues } from "./sonar-collector.js";
|
|
2
|
+
import { type ExternalPublicationDependencies, type ExternalPublicationPreview } from "./external-findings-publish.js";
|
|
3
|
+
interface SonarImportOptions {
|
|
4
|
+
cwd: string;
|
|
5
|
+
capture?: string | undefined;
|
|
6
|
+
project?: string | undefined;
|
|
7
|
+
branch?: string | undefined;
|
|
8
|
+
pullRequest?: string | undefined;
|
|
9
|
+
issueKeys: string[];
|
|
10
|
+
sourceRepositoryUrl?: string | undefined;
|
|
11
|
+
to: "local" | "cloud";
|
|
12
|
+
dryRun: boolean;
|
|
13
|
+
yes: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function prepareSonarImport(options: SonarImportOptions, dependencies: ExternalPublicationDependencies & {
|
|
16
|
+
collect?: typeof collectSonarIssues;
|
|
17
|
+
onCapture?: (path: string) => void;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
info: {
|
|
20
|
+
capture: string;
|
|
21
|
+
repository: string;
|
|
22
|
+
repositoryUrl: string;
|
|
23
|
+
sourceKey: string;
|
|
24
|
+
server: string;
|
|
25
|
+
organization: string;
|
|
26
|
+
project: string;
|
|
27
|
+
branch: string | undefined;
|
|
28
|
+
pullRequest: string | undefined;
|
|
29
|
+
};
|
|
30
|
+
local: import("./external-findings-local.js").LocalExternalImportPreview;
|
|
31
|
+
cloud: ExternalPublicationPreview | undefined;
|
|
32
|
+
cloudError: string | undefined;
|
|
33
|
+
import(): Promise<{
|
|
34
|
+
capture: string;
|
|
35
|
+
repository: string;
|
|
36
|
+
repositoryUrl: string;
|
|
37
|
+
sourceKey: string;
|
|
38
|
+
server: string;
|
|
39
|
+
organization: string;
|
|
40
|
+
project: string;
|
|
41
|
+
branch: string | undefined;
|
|
42
|
+
pullRequest: string | undefined;
|
|
43
|
+
local: {
|
|
44
|
+
counts: {
|
|
45
|
+
created: number;
|
|
46
|
+
updated: number;
|
|
47
|
+
unchanged: number;
|
|
48
|
+
};
|
|
49
|
+
ready: number;
|
|
50
|
+
excluded: {
|
|
51
|
+
position: number;
|
|
52
|
+
source_finding_id: string | null;
|
|
53
|
+
reason: string;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
cloudError: string | undefined;
|
|
57
|
+
cloud: undefined;
|
|
58
|
+
} | {
|
|
59
|
+
capture: string;
|
|
60
|
+
repository: string;
|
|
61
|
+
repositoryUrl: string;
|
|
62
|
+
sourceKey: string;
|
|
63
|
+
server: string;
|
|
64
|
+
organization: string;
|
|
65
|
+
project: string;
|
|
66
|
+
branch: string | undefined;
|
|
67
|
+
pullRequest: string | undefined;
|
|
68
|
+
local: {
|
|
69
|
+
counts: {
|
|
70
|
+
created: number;
|
|
71
|
+
updated: number;
|
|
72
|
+
unchanged: number;
|
|
73
|
+
};
|
|
74
|
+
ready: number;
|
|
75
|
+
excluded: {
|
|
76
|
+
position: number;
|
|
77
|
+
source_finding_id: string | null;
|
|
78
|
+
reason: string;
|
|
79
|
+
}[];
|
|
80
|
+
};
|
|
81
|
+
cloud: import("./external-findings-publish.js").ExternalPublicationResult;
|
|
82
|
+
cloudError: undefined;
|
|
83
|
+
} | {
|
|
84
|
+
capture: string;
|
|
85
|
+
repository: string;
|
|
86
|
+
repositoryUrl: string;
|
|
87
|
+
sourceKey: string;
|
|
88
|
+
server: string;
|
|
89
|
+
organization: string;
|
|
90
|
+
project: string;
|
|
91
|
+
branch: string | undefined;
|
|
92
|
+
pullRequest: string | undefined;
|
|
93
|
+
local: {
|
|
94
|
+
counts: {
|
|
95
|
+
created: number;
|
|
96
|
+
updated: number;
|
|
97
|
+
unchanged: number;
|
|
98
|
+
};
|
|
99
|
+
ready: number;
|
|
100
|
+
excluded: {
|
|
101
|
+
position: number;
|
|
102
|
+
source_finding_id: string | null;
|
|
103
|
+
reason: string;
|
|
104
|
+
}[];
|
|
105
|
+
};
|
|
106
|
+
cloudError: string;
|
|
107
|
+
cloud: import("./external-findings-publish.js").ExternalPublicationResult | undefined;
|
|
108
|
+
}>;
|
|
109
|
+
}>;
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=sonar-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sonar-import.d.ts","sourceRoot":"","sources":["../src/sonar-import.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EAKL,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAEhC,MAAM,gCAAgC,CAAC;AAqBxC,UAAU,kBAAkB;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;CACd;AA8ED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,+BAA+B,GAAG;IAC9C,OAAO,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACpC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgRF"}
|