@openai/codex-security 0.1.23 → 0.1.25
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 +200 -23
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +1 -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/scan-contract.md +10 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +27 -78
- package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -8
- package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
- package/_bundled_plugin/scripts/rank_preview.py +12 -1
- package/_bundled_plugin/scripts/report_projection.py +8 -14
- package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
- package/_bundled_plugin/scripts/windows_scan_local_files.py +5 -15
- package/_bundled_plugin/scripts/workbench_cli.py +14 -1
- package/_bundled_plugin/scripts/workbench_dashboard.py +41 -18
- package/_bundled_plugin/scripts/workbench_db.py +127 -541
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +31 -13
- package/_bundled_plugin/scripts/workbench_findings.py +8 -3
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
- package/_bundled_plugin/scripts/workbench_publication.py +520 -0
- package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +298 -90
- package/_bundled_plugin/scripts/workbench_scan_history.py +375 -68
- package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
- package/_bundled_plugin/scripts/workbench_schema.py +49 -21
- package/_bundled_plugin/scripts/workbench_target.py +96 -17
- package/_bundled_plugin/scripts/workbench_validation.py +1 -5
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
- package/dist/api.d.ts +18 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +350 -28
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +35 -3
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +118 -35
- package/dist/cli.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +4 -2
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +21 -6
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +46 -2
- package/dist/config.js.map +1 -1
- package/dist/cost.d.ts +1 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +23 -11
- package/dist/cost.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +2 -1
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +3 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +122 -36
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -3
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +18 -9
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +2 -7
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +46 -24
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +186 -23
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/scan.d.ts +9 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +24 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-progress.d.ts +21 -0
- package/dist/deep-progress.d.ts.map +1 -0
- package/dist/deep-progress.js +108 -0
- package/dist/deep-progress.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/mock-scan.d.ts +4 -0
- package/dist/mock-scan.d.ts.map +1 -0
- package/dist/mock-scan.js +210 -0
- package/dist/mock-scan.js.map +1 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +2 -2
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +54 -14
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +12 -2
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +11 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +237 -39
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +3 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +70 -3
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +21 -0
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/server/api.d.ts +6 -0
- package/dist/server/api.d.ts.map +1 -0
- package/dist/server/api.js +4 -0
- package/dist/server/api.js.map +1 -0
- package/dist/server/dashboard/app.css +1 -1
- package/dist/server/embeddings.d.ts +2 -1
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +8 -3
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/index.js +2 -28
- package/dist/server/index.js.map +1 -1
- package/dist/server/serve.d.ts +2 -0
- package/dist/server/serve.d.ts.map +1 -0
- package/dist/server/serve.js +28 -0
- package/dist/server/serve.js.map +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +3 -5
- package/dist/targets.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +10 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,mBAAmB,EACnB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,GAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,0BAA0B,GAE3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAwB,MAAM,uBAAuB,CAAC;AAE7E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EACL,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAgBlC,8FAA8F;AAC9F,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAc,EACd,OAA+B;IAE/B,OAAO,MAAM,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAc,EACd,OAA+B,EAC/B,eAKI,EAAE;IAEN,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,W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AE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC3E,MAAM,QAAQ,EAAE,aAAa,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC;QAC1E,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["import { loadContractWithScanDirectory } from \"../contract.js\";\nimport {\n bundledPluginRoot,\n codexSecurityStateDirectory,\n resolvePluginPython,\n runWorkbench,\n} from \"../runtime.js\";\nimport {\n resolveCompletedScan,\n type SavedScanDependencies,\n} from \"../saved-scan.js\";\nimport { CodexReviewRunner } from \"./codex-review.js\";\nimport {\n FindingDeduplicator,\n type DeduplicationResult,\n} from \"./deduplication.js\";\nimport {\n CodexDeduplicationReviewer,\n type DeduplicationReviewer,\n} from \"./deduplication-reviewer.js\";\nimport { FindingsClient, type FindingsRequest } from \"../findings-client.js\";\nimport type { FindingSearchScope } from \"../finding-retrieval.js\";\nimport {\n FindingWorkflow,\n workflowDestination,\n workflowDigest,\n} from \"../finding-workflow.js\";\nimport { publishScanToCustomInternal } from \"../custom-publish.js\";\nimport {\n CheckpointedReviewRunner,\n reviewSettingsDigest,\n} from \"./checkpointed-review.js\";\n\nexport interface DeduplicateScanOptions {\n /** Resume the named local findings workflow, including custom publication. */\n workflowId?: string;\n /** Findings API base URL. The scan's findings must already be indexed there. */\n findingsUrl: string;\n /** Search all repositories instead of the saved scan's targetId. Defaults to false. */\n allRepositories?: boolean;\n signal?: AbortSignal;\n}\n\nexport interface DeduplicateScanResult extends DeduplicationResult {\n scanId: string;\n}\n\n/** Review a saved scan against embedding candidates and persist accepted duplicate groups. */\nexport async function deduplicateScan(\n scanId: string,\n options: DeduplicateScanOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanInternal(scanId, options);\n}\n\n/** @internal */\nexport async function deduplicateScanInternal(\n scanId: string,\n options: DeduplicateScanOptions,\n dependencies: Partial<SavedScanDependencies> & {\n environment?: NodeJS.ProcessEnv;\n reviewer?: DeduplicationReviewer;\n reviewRunner?: Pick<CodexReviewRunner, \"run\">;\n fetch?: FindingsRequest;\n } = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n const environment = dependencies.environment ?? process.env;\n const pluginRoot = await bundledPluginRoot();\n const scan = await resolveCompletedScan(scanId, {\n currentDirectory: dependencies.currentDirectory ?? (() => process.cwd()),\n runWorkbench:\n dependencies.runWorkbench ??\n (async (args) => {\n const stateEnvironment = {\n ...environment,\n CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(environment),\n };\n return await runWorkbench(\n {\n environment: stateEnvironment,\n pluginRoot,\n python: await resolvePluginPython({\n environment: stateEnvironment,\n }),\n signal: options.signal,\n failureMessage: \"Could not read Codex Security scan history\",\n },\n args,\n );\n }),\n });\n const { contract, scanDirectory } = await loadContractWithScanDirectory(\n scan.scanDir,\n {\n pluginRoot,\n expectedScanId: scan.scanId,\n signal: options.signal,\n },\n );\n const client = new FindingsClient(\n options.findingsUrl,\n options.signal,\n dependencies.fetch,\n );\n const scope: FindingSearchScope =\n options.allRepositories === true\n ? { allRepositories: true }\n : { repositoryId: contract.manifest.scan.target.targetId };\n const workflow =\n options.workflowId === undefined\n ? undefined\n : new FindingWorkflow(\n options.workflowId,\n environment,\n dependencies.runWorkbench === undefined\n ? undefined\n : (_options, args, input) =>\n dependencies.runWorkbench!(args, input),\n );\n if (workflow) {\n await workflow.protectArtifacts(scanDirectory);\n await workflow.bind({\n scanId: scan.scanId,\n scanDir: scanDirectory,\n artifactDigest: workflowDigest(contract),\n destination: workflowDestination(options.findingsUrl),\n scope,\n });\n await workflow.complete(\"scan\", null);\n await publishScanToCustomInternal(\n scanDirectory,\n {\n findingsUrl: options.findingsUrl,\n workflowId: options.workflowId,\n expectedScanId: scan.scanId,\n signal: options.signal,\n },\n {\n environment,\n fetch: dependencies.fetch,\n runWorkbench:\n dependencies.runWorkbench === undefined\n ? undefined\n : (_options, args, input) =>\n dependencies.runWorkbench!(args, input),\n },\n );\n }\n const dedupe = async (): Promise<DeduplicateScanResult> => {\n const saved = (await workflow?.get())?.stages.dedupe;\n if (saved?.pendingWrite) {\n await client.storeDedupeGroups(saved.pendingWrite.groups);\n return saved.result as DeduplicateScanResult;\n }\n const runner =\n dependencies.reviewRunner ??\n new CodexReviewRunner(\n environment,\n undefined,\n options.signal,\n scan[\"targetPath\"] as string,\n );\n const checkpoints = workflow\n ? new CheckpointedReviewRunner(\n workflow,\n runner,\n await workflow.sourceSnapshot(scan[\"targetPath\"] as string),\n scope,\n await reviewSettingsDigest(environment),\n )\n : undefined;\n const deduplicator = new FindingDeduplicator(\n {\n potentialDuplicates: (findingId) =>\n client.potentialDuplicates(findingId, scope),\n },\n dependencies.reviewer ??\n new CodexDeduplicationReviewer(checkpoints ?? runner),\n options.signal,\n );\n const reviewed = await deduplicator.run(\n contract.findings.findings.map((finding) => finding.findingId),\n );\n await checkpoints?.assertSourceUnchanged();\n options.signal?.throwIfAborted();\n const result: DeduplicateScanResult = { scanId: scan.scanId, ...reviewed };\n await workflow?.prepareDedupe(result, { groups: result.duplicateGroups });\n await client.storeDedupeGroups(result.duplicateGroups);\n return result;\n };\n return workflow ? await workflow.run(\"dedupe\", dedupe) : await dedupe();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,mBAAmB,EACnB,YAAY,GACb,MAAM,eAAe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,CAAC,SAAS,CAAC;QACd,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAC1C;YACE,mBAAmB,EAAE,CAAC,SAAS,EAAE,EAAE,CACjC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC;SAC/C,EACD,YAAY,CAAC,QAAQ;YACnB,IAAI,0BAA0B,CAAC,WAAW,IAAI,MAAM,CAAC,EACvD,OAAO,CAAC,MAAM,CACf,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,GAAG,CACrC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAC/D,CAAC;QACF,MAAM,WAAW,EAAE,qBAAqB,EAAE,CAAC;QAC3C,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;QACjC,MAAM,MAAM,GAA0B,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC9D,MAAM,QAAQ,EAAE,aAAa,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC;QAC1E,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["import { loadContractWithScanDirectory } from \"../contract.js\";\nimport {\n bundledPluginRoot,\n codexSecurityStateDirectory,\n resolvePluginPython,\n runWorkbench,\n} from \"../runtime.js\";\nimport {\n resolveCompletedScan,\n type SavedScanDependencies,\n} from \"../saved-scan.js\";\nimport { CodexReviewRunner } from \"./codex-review.js\";\nimport {\n FindingDeduplicator,\n type DeduplicationResult,\n} from \"./deduplication.js\";\nimport {\n CodexDeduplicationReviewer,\n type DeduplicationReviewer,\n} from \"./deduplication-reviewer.js\";\nimport { FindingsClient, type FindingsRequest } from \"../findings-client.js\";\nimport type { FindingSearchScope } from \"../finding-retrieval.js\";\nimport {\n FindingWorkflow,\n workflowDestination,\n workflowDigest,\n} from \"../finding-workflow.js\";\nimport { publishScanToCustomInternal } from \"../custom-publish.js\";\nimport {\n CheckpointedReviewRunner,\n reviewSettingsDigest,\n} from \"./checkpointed-review.js\";\nimport { normalizeRepository } from \"../targets.js\";\n\nexport interface DeduplicateScanOptions {\n /** Resume the named local findings workflow, including custom publication. */\n workflowId?: string;\n /** Findings API base URL. The scan's findings must already be indexed there. */\n findingsUrl: string;\n /** Search all repositories instead of the scan's targetId. Defaults to false. */\n allRepositories?: boolean;\n signal?: AbortSignal;\n}\n\nexport interface DeduplicateScanDirectoryOptions\n extends DeduplicateScanOptions {\n /** Local repository checkout used to review duplicate candidates. */\n repository: string;\n /** Require the sealed artifacts to belong to this scan. */\n expectedScanId?: string;\n}\n\nexport interface DeduplicateScanResult extends DeduplicationResult {\n scanId: string;\n}\n\n/** Review a saved scan against embedding candidates and persist accepted duplicate groups. */\nexport async function deduplicateScan(\n scanId: string,\n options: DeduplicateScanOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanInternal(scanId, options);\n}\n\n/** Review a complete, sealed scan directory without resolving local scan history. */\nexport async function deduplicateScanDirectory(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanDirectoryInternal(scanDirectory, options);\n}\n\ntype DeduplicateScanDependencies = Partial<SavedScanDependencies> & {\n environment?: NodeJS.ProcessEnv;\n reviewer?: DeduplicationReviewer;\n reviewRunner?: Pick<CodexReviewRunner, \"run\">;\n fetch?: FindingsRequest;\n};\n\n/** @internal */\nexport async function deduplicateScanDirectoryInternal(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n const repository = await normalizeRepository(\n options.repository,\n options.signal,\n );\n return await deduplicateResolvedScan(\n scanDirectory,\n repository,\n options.expectedScanId,\n options,\n dependencies,\n await bundledPluginRoot(),\n true,\n );\n}\n\n/** @internal */\nexport async function deduplicateScanInternal(\n scanId: string,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n const environment = dependencies.environment ?? process.env;\n const pluginRoot = await bundledPluginRoot();\n const scan = await resolveCompletedScan(scanId, {\n currentDirectory: dependencies.currentDirectory ?? (() => process.cwd()),\n runWorkbench:\n dependencies.runWorkbench ??\n (async (args) => {\n const stateEnvironment = {\n ...environment,\n CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(environment),\n };\n return await runWorkbench(\n {\n environment: stateEnvironment,\n pluginRoot,\n python: await resolvePluginPython({\n environment: stateEnvironment,\n }),\n signal: options.signal,\n failureMessage: \"Could not read Codex Security scan history\",\n },\n args,\n );\n }),\n });\n return await deduplicateResolvedScan(\n scan.scanDir,\n scan[\"targetPath\"] as string,\n scan.scanId,\n options,\n dependencies,\n pluginRoot,\n false,\n );\n}\n\nasync function deduplicateResolvedScan(\n selectedDirectory: string,\n repositoryPath: string,\n expectedScanId: string | undefined,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies,\n pluginRoot: string,\n bindRepository: boolean,\n): Promise<DeduplicateScanResult> {\n const environment = dependencies.environment ?? process.env;\n const { contract, scanDirectory } = await loadContractWithScanDirectory(\n selectedDirectory,\n {\n pluginRoot,\n expectedScanId,\n signal: options.signal,\n },\n );\n const scanId = contract.manifest.scan.id;\n const client = new FindingsClient(\n options.findingsUrl,\n options.signal,\n dependencies.fetch,\n );\n const scope: FindingSearchScope =\n options.allRepositories === true\n ? { allRepositories: true }\n : { repositoryId: contract.manifest.scan.target.targetId };\n const workflow =\n options.workflowId === undefined\n ? undefined\n : new FindingWorkflow(\n options.workflowId,\n environment,\n dependencies.runWorkbench === undefined\n ? undefined\n : (_options, args, input) =>\n dependencies.runWorkbench!(args, input),\n );\n if (workflow) {\n await workflow.protectArtifacts(scanDirectory);\n await workflow.bind({\n ...(bindRepository ? { repositoryPath } : {}),\n scanId,\n scanDir: scanDirectory,\n artifactDigest: workflowDigest(contract),\n destination: workflowDestination(options.findingsUrl),\n scope,\n });\n await workflow.complete(\"scan\", null);\n await publishScanToCustomInternal(\n scanDirectory,\n {\n findingsUrl: options.findingsUrl,\n workflowId: options.workflowId,\n expectedScanId: scanId,\n signal: options.signal,\n },\n {\n environment,\n fetch: dependencies.fetch,\n runWorkbench:\n dependencies.runWorkbench === undefined\n ? undefined\n : (_options, args, input) =>\n dependencies.runWorkbench!(args, input),\n },\n );\n }\n const dedupe = async (): Promise<DeduplicateScanResult> => {\n const saved = (await workflow?.get())?.stages.dedupe;\n if (saved?.pendingWrite) {\n await client.storeDedupeGroups(saved.pendingWrite.groups);\n return saved.result as DeduplicateScanResult;\n }\n const runner =\n dependencies.reviewRunner ??\n new CodexReviewRunner(\n environment,\n undefined,\n options.signal,\n repositoryPath,\n );\n const checkpoints = workflow\n ? new CheckpointedReviewRunner(\n workflow,\n runner,\n await workflow.sourceSnapshot(repositoryPath),\n scope,\n await reviewSettingsDigest(environment),\n )\n : undefined;\n const deduplicator = new FindingDeduplicator(\n {\n potentialDuplicates: (findingId) =>\n client.potentialDuplicates(findingId, scope),\n },\n dependencies.reviewer ??\n new CodexDeduplicationReviewer(checkpoints ?? runner),\n options.signal,\n );\n const reviewed = await deduplicator.run(\n contract.findings.findings.map((finding) => finding.findingId),\n );\n await checkpoints?.assertSourceUnchanged();\n options.signal?.throwIfAborted();\n const result: DeduplicateScanResult = { scanId, ...reviewed };\n await workflow?.prepareDedupe(result, { groups: result.duplicateGroups });\n await client.storeDedupeGroups(result.duplicateGroups);\n return result;\n };\n return workflow ? await workflow.run(\"dedupe\", dedupe) : await dedupe();\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface DeepScanProgress {
|
|
2
|
+
completed: number;
|
|
3
|
+
active: number;
|
|
4
|
+
maximum: number;
|
|
5
|
+
}
|
|
6
|
+
interface DeepScanProgressTrackerOptions {
|
|
7
|
+
read: (signal: AbortSignal) => Promise<unknown>;
|
|
8
|
+
onProgress: (progress: DeepScanProgress) => void;
|
|
9
|
+
onError?: (error: unknown) => void;
|
|
10
|
+
pollIntervalMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class DeepScanProgressTracker {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(options: DeepScanProgressTrackerOptions);
|
|
15
|
+
start(): void;
|
|
16
|
+
refresh(): Promise<void>;
|
|
17
|
+
stop(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function deepScanProgressFromWorkbench(result: unknown): DeepScanProgress | null;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=deep-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-progress.d.ts","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,8BAA8B;IACtC,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAChD,UAAU,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACjD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAID,qBAAa,uBAAuB;;gBAQf,OAAO,EAAE,8BAA8B;IAInD,KAAK,IAAI,IAAI;IAeP,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAmC9B,IAAI,IAAI,IAAI;CAUpB;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,OAAO,GACd,gBAAgB,GAAG,IAAI,CAqBzB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;
|
|
2
|
+
export class DeepScanProgressTracker {
|
|
3
|
+
#options;
|
|
4
|
+
#timer = null;
|
|
5
|
+
#pending = null;
|
|
6
|
+
#abortController = null;
|
|
7
|
+
#lastProgress = null;
|
|
8
|
+
#stopped = false;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.#options = options;
|
|
11
|
+
}
|
|
12
|
+
start() {
|
|
13
|
+
if (this.#timer !== null || this.#stopped)
|
|
14
|
+
return;
|
|
15
|
+
const poll = () => {
|
|
16
|
+
void this.refresh().catch((error) => {
|
|
17
|
+
this.#options.onError?.(error);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
this.#timer = setInterval(poll, this.#options.pollIntervalMs ?? DEEP_PROGRESS_POLL_INTERVAL_MS);
|
|
21
|
+
this.#timer.unref();
|
|
22
|
+
poll();
|
|
23
|
+
}
|
|
24
|
+
async refresh() {
|
|
25
|
+
if (this.#stopped)
|
|
26
|
+
return;
|
|
27
|
+
if (this.#pending !== null)
|
|
28
|
+
return await this.#pending;
|
|
29
|
+
const abortController = new AbortController();
|
|
30
|
+
this.#abortController = abortController;
|
|
31
|
+
let update = null;
|
|
32
|
+
update = (async () => {
|
|
33
|
+
try {
|
|
34
|
+
const progress = deepScanProgressFromWorkbench(await this.#options.read(abortController.signal));
|
|
35
|
+
if (this.#stopped ||
|
|
36
|
+
abortController.signal.aborted ||
|
|
37
|
+
progress === null ||
|
|
38
|
+
sameProgress(progress, this.#lastProgress)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.#lastProgress = progress;
|
|
42
|
+
this.#options.onProgress(progress);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (this.#stopped || abortController.signal.aborted)
|
|
46
|
+
return;
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
if (this.#pending === update)
|
|
51
|
+
this.#pending = null;
|
|
52
|
+
if (this.#abortController === abortController) {
|
|
53
|
+
this.#abortController = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
this.#pending = update;
|
|
58
|
+
await update;
|
|
59
|
+
}
|
|
60
|
+
stop() {
|
|
61
|
+
if (this.#stopped)
|
|
62
|
+
return;
|
|
63
|
+
this.#stopped = true;
|
|
64
|
+
if (this.#timer !== null) {
|
|
65
|
+
clearInterval(this.#timer);
|
|
66
|
+
this.#timer = null;
|
|
67
|
+
}
|
|
68
|
+
this.#abortController?.abort();
|
|
69
|
+
this.#abortController = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function deepScanProgressFromWorkbench(result) {
|
|
73
|
+
if (!isRecord(result) || !isRecord(result["scan"]))
|
|
74
|
+
return null;
|
|
75
|
+
const progress = result["scan"]["progress"];
|
|
76
|
+
if (!isRecord(progress))
|
|
77
|
+
return null;
|
|
78
|
+
const independentReviews = progress["independentReviews"];
|
|
79
|
+
if (independentReviews === undefined)
|
|
80
|
+
return null;
|
|
81
|
+
if (!isRecord(independentReviews) ||
|
|
82
|
+
!isCount(independentReviews["completed"]) ||
|
|
83
|
+
!isCount(independentReviews["active"]) ||
|
|
84
|
+
!isPositiveCount(independentReviews["maximum"])) {
|
|
85
|
+
throw new Error("Codex Security workbench returned invalid Deep Scan progress.");
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
completed: independentReviews["completed"],
|
|
89
|
+
active: independentReviews["active"],
|
|
90
|
+
maximum: independentReviews["maximum"],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function sameProgress(left, right) {
|
|
94
|
+
return (right !== null &&
|
|
95
|
+
left.completed === right.completed &&
|
|
96
|
+
left.active === right.active &&
|
|
97
|
+
left.maximum === right.maximum);
|
|
98
|
+
}
|
|
99
|
+
function isCount(value) {
|
|
100
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
101
|
+
}
|
|
102
|
+
function isPositiveCount(value) {
|
|
103
|
+
return isCount(value) && value > 0;
|
|
104
|
+
}
|
|
105
|
+
function isRecord(value) {
|
|
106
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=deep-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-progress.js","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAaA,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAE7C,MAAM,OAAO,uBAAuB;IACzB,QAAQ,CAAiC;IAClD,MAAM,GAA0B,IAAI,CAAC;IACrC,QAAQ,GAAyB,IAAI,CAAC;IACtC,gBAAgB,GAA2B,IAAI,CAAC;IAChD,aAAa,GAA4B,IAAI,CAAC;IAC9C,QAAQ,GAAG,KAAK,CAAC;IAEjB,YAAmB,OAAuC;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,KAAK;QACV,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAClD,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAC3C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,WAAW,CACvB,IAAI,EACJ,IAAI,CAAC,QAAQ,CAAC,cAAc,IAAI,8BAA8B,CAC/D,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,E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QACpC,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC;KACvC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAAsB,EACtB,KAA8B;IAE9B,OAAO,CACL,KAAK,KAAK,IAAI;QACd,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS;QAClC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAC5B,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CAC/B,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["export interface DeepScanProgress {\n completed: number;\n active: number;\n maximum: number;\n}\n\ninterface DeepScanProgressTrackerOptions {\n read: (signal: AbortSignal) => Promise<unknown>;\n onProgress: (progress: DeepScanProgress) => void;\n onError?: (error: unknown) => void;\n pollIntervalMs?: number;\n}\n\nconst DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;\n\nexport class DeepScanProgressTracker {\n readonly #options: DeepScanProgressTrackerOptions;\n #timer: NodeJS.Timeout | null = null;\n #pending: Promise<void> | null = null;\n #abortController: AbortController | null = null;\n #lastProgress: DeepScanProgress | null = null;\n #stopped = false;\n\n public constructor(options: DeepScanProgressTrackerOptions) {\n this.#options = options;\n }\n\n public start(): void {\n if (this.#timer !== null || this.#stopped) return;\n const poll = () => {\n void this.refresh().catch((error: unknown) => {\n this.#options.onError?.(error);\n });\n };\n this.#timer = setInterval(\n poll,\n this.#options.pollIntervalMs ?? DEEP_PROGRESS_POLL_INTERVAL_MS,\n );\n this.#timer.unref();\n poll();\n }\n\n public async refresh(): Promise<void> {\n if (this.#stopped) return;\n if (this.#pending !== null) return await this.#pending;\n const abortController = new AbortController();\n this.#abortController = abortController;\n let update: Promise<void> | null = null;\n update = (async () => {\n try {\n const progress = deepScanProgressFromWorkbench(\n await this.#options.read(abortController.signal),\n );\n if (\n this.#stopped ||\n abortController.signal.aborted ||\n progress === null ||\n sameProgress(progress, this.#lastProgress)\n ) {\n return;\n }\n this.#lastProgress = progress;\n this.#options.onProgress(progress);\n } catch (error) {\n if (this.#stopped || abortController.signal.aborted) return;\n throw error;\n } finally {\n if (this.#pending === update) this.#pending = null;\n if (this.#abortController === abortController) {\n this.#abortController = null;\n }\n }\n })();\n this.#pending = update;\n await update;\n }\n\n public stop(): void {\n if (this.#stopped) return;\n this.#stopped = true;\n if (this.#timer !== null) {\n clearInterval(this.#timer);\n this.#timer = null;\n }\n this.#abortController?.abort();\n this.#abortController = null;\n }\n}\n\nexport function deepScanProgressFromWorkbench(\n result: unknown,\n): DeepScanProgress | null {\n if (!isRecord(result) || !isRecord(result[\"scan\"])) return null;\n const progress = result[\"scan\"][\"progress\"];\n if (!isRecord(progress)) return null;\n const independentReviews = progress[\"independentReviews\"];\n if (independentReviews === undefined) return null;\n if (\n !isRecord(independentReviews) ||\n !isCount(independentReviews[\"completed\"]) ||\n !isCount(independentReviews[\"active\"]) ||\n !isPositiveCount(independentReviews[\"maximum\"])\n ) {\n throw new Error(\n \"Codex Security workbench returned invalid Deep Scan progress.\",\n );\n }\n return {\n completed: independentReviews[\"completed\"],\n active: independentReviews[\"active\"],\n maximum: independentReviews[\"maximum\"],\n };\n}\n\nfunction sameProgress(\n left: DeepScanProgress,\n right: DeepScanProgress | null,\n): boolean {\n return (\n right !== null &&\n left.completed === right.completed &&\n left.active === right.active &&\n left.maximum === right.maximum\n );\n}\n\nfunction isCount(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction isPositiveCount(value: unknown): value is number {\n return isCount(value) && value > 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n"]}
|
package/dist/errors.d.ts
CHANGED
|
@@ -7,6 +7,19 @@ export declare function safeErrorMessage(error: unknown): string;
|
|
|
7
7
|
export declare class CodexSecurityError extends Error {
|
|
8
8
|
constructor(message: string, options?: ErrorOptions);
|
|
9
9
|
}
|
|
10
|
+
export type DeduplicationReviewStage = "screening" | "pair-review";
|
|
11
|
+
export type DeduplicationReviewFailureCategory = "validation" | "no-submission" | "model" | "transport";
|
|
12
|
+
export interface DeduplicationReviewFailureMetadata {
|
|
13
|
+
stage: DeduplicationReviewStage;
|
|
14
|
+
model: string;
|
|
15
|
+
category: DeduplicationReviewFailureCategory;
|
|
16
|
+
attempts: number;
|
|
17
|
+
reason: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class DeduplicationReviewError extends CodexSecurityError {
|
|
20
|
+
readonly metadata: Readonly<DeduplicationReviewFailureMetadata>;
|
|
21
|
+
constructor(metadata: Readonly<DeduplicationReviewFailureMetadata>, displayReason?: string);
|
|
22
|
+
}
|
|
10
23
|
export declare class ConfigurationError extends CodexSecurityError {
|
|
11
24
|
}
|
|
12
25
|
export declare class AuthenticationRequiredError extends CodexSecurityError {
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3D,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD;AAED,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,EAA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,SAAQ,oBAAoB;aAElD,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM,EACjC,SAAS,GAAE,MAAM,GAAG,QAAiB;CAQxC;AACD,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;AAEvE,qBAAa,8BAA+B,SAAQ,oBAAoB;aAEpD,eAAe,EAAE,MAAM;aACvB,aAAa,EAAE,MAAM;aACrB,QAAQ,EAAE,qBAAqB;gBAF/B,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,EACrB,QAAQ,GAAE,qBAAgC;CAM7D;AACD,qBAAa,mBAAoB,SAAQ,kBAAkB;CAAG;AAC9D,qBAAa,uBAAwB,SAAQ,kBAAkB;CAAG;AAClE,qBAAa,oBAAqB,SAAQ,kBAAkB;IAC1D,SAAgB,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI5E;AAED,qBAAa,0BAA2B,SAAQ,oBAAoB;IAClE,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAGvC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACxB,OAAO,EAAE,MAAM;CASlB"}
|
package/dist/errors.js
CHANGED
|
@@ -18,6 +18,13 @@ export class CodexSecurityError extends Error {
|
|
|
18
18
|
this.name = new.target.name;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
export class DeduplicationReviewError extends CodexSecurityError {
|
|
22
|
+
metadata;
|
|
23
|
+
constructor(metadata, displayReason = metadata.reason) {
|
|
24
|
+
super(`Codex did not complete a validated deduplication review. Findings are unchanged; retry the command. Reason: ${displayReason}`);
|
|
25
|
+
this.metadata = metadata;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
21
28
|
export class ConfigurationError extends CodexSecurityError {
|
|
22
29
|
}
|
|
23
30
|
export class AuthenticationRequiredError extends CodexSecurityError {
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,iBAAiB,CAAC;AAE3D,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,sBAAsB,GAC1B,iKAAiK,CAAC,IAAI,CACpK,OAAO,CACR,CAAC;IACJ,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAClC,8DAA8D,CAC/D,CAAC;IACF,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAC9D,uPAAuP,CAAC,IAAI,CAC1P,KAAK,CACN,CACF,CAAC;IACF,OAAO,sBAAsB,IAAI,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC;AAC3E,CAAC;AAED,kDAAkD;AAClD,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAmB,OAAe,EAAE,OAAsB;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,kBAAkB;CAAG;AAC7D,MAAM,OAAO,2BAA4B,SAAQ,kB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CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,SAAS,CAAC,UAAU,CAAC,qCAAqC,OAAO,GAAG,EACjJ,OAAO,CACR,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { formatUsd, type ScanCost } from \"./cost-model.js\";\n\n/** Returns the original error message without altering its contents. */\nexport function errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/** Omit credential-bearing messages at persistence and display boundaries. */\nexport function safeErrorMessage(error: unknown): string {\n const message = errorMessage(error);\n const recognizableCredential =\n /(?:\\b(?:sk-(?:proj-)?|github_pat_|gh[pousr]_|npm_)\\S+|\\b(?:bearer|basic|token)(?:\\s|%20|\\+)+\\S+|:\\/\\/[^\\s/@]+@|-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----)/iu.test(\n message,\n );\n const assignments = message.matchAll(\n /(?<![\\w%.-])[\\w%.-]+(?:\\\\*[\"']|\\]|%5d)*\\s*(?:[:=]|%3[ad])/giu,\n );\n const sensitiveField = Array.from(assignments).some(([field]) =>\n /(?:api(?:[_-]|%5f|%2d)?key|access(?:[_-]|%5f|%2d)?key|private(?:[_-]|%5f|%2d)?key|authorization|auth(?!or)|token|secret|credential|signature|sig(?=[^A-Za-z0-9]|value|data|token|secret|credential|password|header|field|id|key|$)|password|passwd)/iu.test(\n field,\n ),\n );\n return recognizableCredential || sensitiveField ? \"[redacted]\" : message;\n}\n\n/** Base error for Codex Security SDK failures. */\nexport class CodexSecurityError extends Error {\n public constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\nexport class ConfigurationError extends CodexSecurityError {}\nexport class AuthenticationRequiredError extends CodexSecurityError {}\nexport class PluginBootstrapError extends CodexSecurityError {}\nexport class PluginPythonUnavailableError extends PluginBootstrapError {}\nexport class InvalidTargetError extends CodexSecurityError {}\nexport class OutputDirectoryError extends CodexSecurityError {}\nexport class OutputDirectoryNotEmptyError extends OutputDirectoryError {\n public constructor(\n public readonly directory: string,\n operation: \"scan\" | \"policy\" = \"scan\",\n ) {\n super(\n operation === \"policy\"\n ? `Policy output directory is not empty: ${directory}. Choose a new or empty directory.`\n : `Scan output directory is not empty: ${directory}. To keep the existing results and start a new scan, add --archive-existing.`,\n );\n }\n}\nexport type ProtectedScanPathKind = \"output\" | \"temporary\" | \"runtime\";\n\nexport class OutputInsideProtectedRootError extends OutputDirectoryError {\n public constructor(\n public readonly outputDirectory: string,\n public readonly protectedRoot: string,\n public readonly pathKind: ProtectedScanPathKind = \"output\",\n ) {\n super(\n `Scan ${pathKind} directory must be outside the protected scan root: ${outputDirectory}`,\n );\n }\n}\nexport class IncompleteScanError extends CodexSecurityError {}\nexport class ContractValidationError extends CodexSecurityError {}\nexport class ScanInterruptedError extends CodexSecurityError {\n public readonly scanDir: string;\n\n public constructor(message: string, scanDir: string, options?: ErrorOptions) {\n super(message, options);\n this.scanDir = scanDir;\n }\n}\n\nexport class ScanCostLimitExceededError extends ScanInterruptedError {\n public readonly maxCostUsd: number;\n public readonly cost: Readonly<ScanCost>;\n\n public constructor(\n maxCostUsd: number,\n cost: Readonly<ScanCost>,\n scanDir: string,\n ) {\n super(\n `Scan stopped: estimated cost ${formatUsd(cost.estimatedUsd)} exceeded the ${formatUsd(maxCostUsd)} limit; partial output remains at ${scanDir}.`,\n scanDir,\n );\n this.maxCostUsd = maxCostUsd;\n this.cost = cost;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,iBAAiB,CAAC;AAE3D,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK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IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { formatUsd, type ScanCost } from \"./cost-model.js\";\n\n/** Returns the original error message without altering its contents. */\nexport function errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/** Omit credential-bearing messages at persistence and display boundaries. */\nexport function safeErrorMessage(error: unknown): string {\n const message = errorMessage(error);\n const recognizableCredential =\n /(?:\\b(?:sk-(?:proj-)?|github_pat_|gh[pousr]_|npm_)\\S+|\\b(?:bearer|basic|token)(?:\\s|%20|\\+)+\\S+|:\\/\\/[^\\s/@]+@|-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----)/iu.test(\n message,\n );\n const assignments = message.matchAll(\n /(?<![\\w%.-])[\\w%.-]+(?:\\\\*[\"']|\\]|%5d)*\\s*(?:[:=]|%3[ad])/giu,\n );\n const sensitiveField = Array.from(assignments).some(([field]) =>\n /(?:api(?:[_-]|%5f|%2d)?key|access(?:[_-]|%5f|%2d)?key|private(?:[_-]|%5f|%2d)?key|authorization|auth(?!or)|token|secret|credential|signature|sig(?=[^A-Za-z0-9]|value|data|token|secret|credential|password|header|field|id|key|$)|password|passwd)/iu.test(\n field,\n ),\n );\n return recognizableCredential || sensitiveField ? \"[redacted]\" : message;\n}\n\n/** Base error for Codex Security SDK failures. */\nexport class CodexSecurityError extends Error {\n public constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\nexport type DeduplicationReviewStage = \"screening\" | \"pair-review\";\nexport type DeduplicationReviewFailureCategory =\n | \"validation\"\n | \"no-submission\"\n | \"model\"\n | \"transport\";\n\nexport interface DeduplicationReviewFailureMetadata {\n stage: DeduplicationReviewStage;\n model: string;\n category: DeduplicationReviewFailureCategory;\n attempts: number;\n reason: string;\n}\n\nexport class DeduplicationReviewError extends CodexSecurityError {\n public constructor(\n public readonly metadata: Readonly<DeduplicationReviewFailureMetadata>,\n displayReason: string = metadata.reason,\n ) {\n super(\n `Codex did not complete a validated deduplication review. Findings are unchanged; retry the command. Reason: ${displayReason}`,\n );\n }\n}\n\nexport class ConfigurationError extends CodexSecurityError {}\nexport class AuthenticationRequiredError extends CodexSecurityError {}\nexport class PluginBootstrapError extends CodexSecurityError {}\nexport class PluginPythonUnavailableError extends PluginBootstrapError {}\nexport class InvalidTargetError extends CodexSecurityError {}\nexport class OutputDirectoryError extends CodexSecurityError {}\nexport class OutputDirectoryNotEmptyError extends OutputDirectoryError {\n public constructor(\n public readonly directory: string,\n operation: \"scan\" | \"policy\" = \"scan\",\n ) {\n super(\n operation === \"policy\"\n ? `Policy output directory is not empty: ${directory}. Choose a new or empty directory.`\n : `Scan output directory is not empty: ${directory}. To keep the existing results and start a new scan, add --archive-existing.`,\n );\n }\n}\nexport type ProtectedScanPathKind = \"output\" | \"temporary\" | \"runtime\";\n\nexport class OutputInsideProtectedRootError extends OutputDirectoryError {\n public constructor(\n public readonly outputDirectory: string,\n public readonly protectedRoot: string,\n public readonly pathKind: ProtectedScanPathKind = \"output\",\n ) {\n super(\n `Scan ${pathKind} directory must be outside the protected scan root: ${outputDirectory}`,\n );\n }\n}\nexport class IncompleteScanError extends CodexSecurityError {}\nexport class ContractValidationError extends CodexSecurityError {}\nexport class ScanInterruptedError extends CodexSecurityError {\n public readonly scanDir: string;\n\n public constructor(message: string, scanDir: string, options?: ErrorOptions) {\n super(message, options);\n this.scanDir = scanDir;\n }\n}\n\nexport class ScanCostLimitExceededError extends ScanInterruptedError {\n public readonly maxCostUsd: number;\n public readonly cost: Readonly<ScanCost>;\n\n public constructor(\n maxCostUsd: number,\n cost: Readonly<ScanCost>,\n scanDir: string,\n ) {\n super(\n `Scan stopped: estimated cost ${formatUsd(cost.estimatedUsd)} exceeded the ${formatUsd(maxCostUsd)} limit; partial output remains at ${scanDir}.`,\n scanDir,\n );\n this.maxCostUsd = maxCostUsd;\n this.cost = cost;\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,14 +5,15 @@ export { normalizeComponentPlan, planComponents } from "./component-plan.js";
|
|
|
5
5
|
export type { ComponentPlan, ComponentPlanningOptions, } from "./component-plan.js";
|
|
6
6
|
export { estimateScanCost } from "./cost.js";
|
|
7
7
|
export type { ScanCost, ScanSessionEvent } from "./cost.js";
|
|
8
|
+
export type { DeepScanProgress } from "./deep-progress.js";
|
|
8
9
|
export type { CustomValidationResult } from "./custom-validation.js";
|
|
9
10
|
export type { ScanActivity, ScanActivityStatus } from "./scan-activity.js";
|
|
10
|
-
export type { CodexSecurityMetadata, DeepScanOptions, ScanAuthMode, ScanAuthentication, ScanOptions, ScanPreflight, ScanReconnectDetails, ScanTrustedAccessStatus, ScanWarningDetails, ValidationOptions, ValidationResult, } from "./api.js";
|
|
11
|
+
export type { CodexSecurityMetadata, DeepScanOptions, ScanAuthMode, ScanAuthentication, ScanBudget, ScanOptions, ScanPreflight, ScanReconnectDetails, ScanTrustedAccessStatus, ScanWarningDetails, ValidationOptions, ValidationResult, } from "./api.js";
|
|
11
12
|
export type { ScanPhase, ScanProgress, ScanWorkerPhase, ScanWorkerStatus, } from "./worker-progress.js";
|
|
12
13
|
export { CodexLoginHandle } from "./auth.js";
|
|
13
14
|
export type { AccountStatus, LoginResult } from "./auth.js";
|
|
14
|
-
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, IncompleteScanError, InvalidTargetError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
15
|
-
export type { ProtectedScanPathKind } from "./errors.js";
|
|
15
|
+
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, DeduplicationReviewError, IncompleteScanError, InvalidTargetError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
16
|
+
export type { DeduplicationReviewFailureCategory, DeduplicationReviewFailureMetadata, DeduplicationReviewStage, ProtectedScanPathKind, } from "./errors.js";
|
|
16
17
|
export { DEFAULT_CODEX_CONFIG, mergedCodexConfig, writeCodexConfig, } from "./config.js";
|
|
17
18
|
export type { CodexSecurityConfig, JsonObject, JsonValue } from "./config.js";
|
|
18
19
|
export { loadContract, requireScanFile } from "./contract.js";
|
|
@@ -21,8 +22,8 @@ export type * from "./models.js";
|
|
|
21
22
|
export { checkScanPublication, publishScan } from "./publish.js";
|
|
22
23
|
export { publishScanToCustom } from "./custom-publish.js";
|
|
23
24
|
export type { PublishScanToCustomOptions, CustomPublicationResult, } from "./custom-publish.js";
|
|
24
|
-
export { deduplicateScan } from "./deduplication/scan.js";
|
|
25
|
-
export type { DeduplicateScanOptions, DeduplicateScanResult, } from "./deduplication/scan.js";
|
|
25
|
+
export { deduplicateScan, deduplicateScanDirectory, } from "./deduplication/scan.js";
|
|
26
|
+
export type { DeduplicateScanDirectoryOptions, DeduplicateScanOptions, DeduplicateScanResult, } from "./deduplication/scan.js";
|
|
26
27
|
export { importGitHubCodeScanningAlerts } from "./github.js";
|
|
27
28
|
export type { GitHubCodeScanningImportOptions, ImportedGitHubCodeScanningAlert, } from "./github.js";
|
|
28
29
|
export type { CheckScanPublicationOptions, CheckScanPublicationResult, PublishScanOptions, PublishScanProgress, PublishScanResult, } from "./publish.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE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,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,12 @@ export { runComponentScans } from "./component-scan.js";
|
|
|
3
3
|
export { normalizeComponentPlan, planComponents } from "./component-plan.js";
|
|
4
4
|
export { estimateScanCost } from "./cost.js";
|
|
5
5
|
export { CodexLoginHandle } from "./auth.js";
|
|
6
|
-
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, IncompleteScanError, InvalidTargetError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
6
|
+
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, DeduplicationReviewError, IncompleteScanError, InvalidTargetError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
7
7
|
export { DEFAULT_CODEX_CONFIG, mergedCodexConfig, writeCodexConfig, } from "./config.js";
|
|
8
8
|
export { loadContract, requireScanFile } from "./contract.js";
|
|
9
9
|
export { checkScanPublication, publishScan } from "./publish.js";
|
|
10
10
|
export { publishScanToCustom } from "./custom-publish.js";
|
|
11
|
-
export { deduplicateScan } from "./deduplication/scan.js";
|
|
11
|
+
export { deduplicateScan, deduplicateScanDirectory, } from "./deduplication/scan.js";
|
|
12
12
|
export { importGitHubCodeScanningAlerts } from "./github.js";
|
|
13
13
|
export { ScanResult } from "./result.js";
|
|
14
14
|
export { bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, createIsolatedHome, createMarketplace, extractPluginZip, importAmbientAuth, MARKETPLACE_NAME, pluginExecutionEnvironment, pluginMetadata, PLUGIN_NAME, prepareOutputDir, resolveCodexCommand, resolvePluginPath, resolvePluginPython, validateOutputDir, } from "./runtime.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAyB7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAOrB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAK1D,OAAO,EACL,eAAe,EACf,wBAAwB,GACzB,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAY7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAOtB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { CodexSecurity, createSecurity } from \"./api.js\";\nexport { runComponentScans } from \"./component-scan.js\";\nexport type {\n ComponentDeduplicationSummary,\n ComponentReceipt,\n ComponentScanOptions,\n ComponentScanEvent,\n ComponentScanResult,\n} from \"./component-scan.js\";\nexport { normalizeComponentPlan, planComponents } from \"./component-plan.js\";\nexport type {\n ComponentPlan,\n ComponentPlanningOptions,\n} from \"./component-plan.js\";\nexport { estimateScanCost } from \"./cost.js\";\nexport type { ScanCost, ScanSessionEvent } from \"./cost.js\";\nexport type { DeepScanProgress } from \"./deep-progress.js\";\nexport type { CustomValidationResult } from \"./custom-validation.js\";\nexport type { ScanActivity, ScanActivityStatus } from \"./scan-activity.js\";\nexport type {\n CodexSecurityMetadata,\n DeepScanOptions,\n ScanAuthMode,\n ScanAuthentication,\n ScanBudget,\n ScanOptions,\n ScanPreflight,\n ScanReconnectDetails,\n ScanTrustedAccessStatus,\n ScanWarningDetails,\n ValidationOptions,\n ValidationResult,\n} from \"./api.js\";\nexport type {\n ScanPhase,\n ScanProgress,\n ScanWorkerPhase,\n ScanWorkerStatus,\n} from \"./worker-progress.js\";\nexport { CodexLoginHandle } from \"./auth.js\";\nexport type { AccountStatus, LoginResult } from \"./auth.js\";\n\nexport {\n AuthenticationRequiredError,\n CodexSecurityError,\n ConfigurationError,\n ContractValidationError,\n DeduplicationReviewError,\n IncompleteScanError,\n InvalidTargetError,\n OutputDirectoryError,\n OutputDirectoryNotEmptyError,\n OutputInsideProtectedRootError,\n PluginBootstrapError,\n PluginPythonUnavailableError,\n ScanCostLimitExceededError,\n ScanInterruptedError,\n} from \"./errors.js\";\nexport type {\n DeduplicationReviewFailureCategory,\n DeduplicationReviewFailureMetadata,\n DeduplicationReviewStage,\n ProtectedScanPathKind,\n} from \"./errors.js\";\nexport {\n DEFAULT_CODEX_CONFIG,\n mergedCodexConfig,\n writeCodexConfig,\n} from \"./config.js\";\nexport type { CodexSecurityConfig, JsonObject, JsonValue } from \"./config.js\";\nexport { loadContract, requireScanFile } from \"./contract.js\";\nexport type { LoadedContract, ScanExpectation } from \"./contract.js\";\nexport type * from \"./models.js\";\nexport { checkScanPublication, publishScan } from \"./publish.js\";\nexport { publishScanToCustom } from \"./custom-publish.js\";\nexport type {\n PublishScanToCustomOptions,\n CustomPublicationResult,\n} from \"./custom-publish.js\";\nexport {\n deduplicateScan,\n deduplicateScanDirectory,\n} from \"./deduplication/scan.js\";\nexport type {\n DeduplicateScanDirectoryOptions,\n DeduplicateScanOptions,\n DeduplicateScanResult,\n} from \"./deduplication/scan.js\";\nexport { importGitHubCodeScanningAlerts } from \"./github.js\";\nexport type {\n GitHubCodeScanningImportOptions,\n ImportedGitHubCodeScanningAlert,\n} from \"./github.js\";\nexport type {\n CheckScanPublicationOptions,\n CheckScanPublicationResult,\n PublishScanOptions,\n PublishScanProgress,\n PublishScanResult,\n} from \"./publish.js\";\nexport { ScanResult } from \"./result.js\";\nexport type {\n RepositoryFinding,\n ScanResultOptions,\n TurnResultMetadata,\n} from \"./result.js\";\nexport {\n bootstrapPlugin,\n bundledPluginRoot,\n cleanupSdkDirectory,\n createIsolatedHome,\n createMarketplace,\n extractPluginZip,\n importAmbientAuth,\n MARKETPLACE_NAME,\n pluginExecutionEnvironment,\n pluginMetadata,\n PLUGIN_NAME,\n prepareOutputDir,\n resolveCodexCommand,\n resolvePluginPath,\n resolvePluginPython,\n validateOutputDir,\n} from \"./runtime.js\";\nexport type {\n CodexCommand,\n PluginInstall,\n PluginPythonOptions,\n ProcessEnvironment,\n} from \"./runtime.js\";\nexport {\n DiffTarget,\n normalizeRepository,\n normalizeTarget,\n repositoryRevision,\n validateMode,\n} from \"./targets.js\";\nexport type { NormalizedTarget, ScanMode, ScanTarget } from \"./targets.js\";\nexport { BUNDLED_PLUGIN_VERSION, VERSION } from \"./version.js\";\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { JsonObject } from "./config.js";
|
|
2
|
+
import type { NormalizedTarget } from "./targets.js";
|
|
3
|
+
export declare function writeMockScanDraft(scanDir: string, scanId: string, target: NormalizedTarget, registration: JsonObject, signal: AbortSignal): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=mock-scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-scan.d.ts","sourceRoot":"","sources":["../src/mock-scan.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAuMrD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,UAAU,EACxB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,CA0Df"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// Entirely synthetic examples; the paths and snippets do not come from the target.
|
|
5
|
+
const EXAMPLES = [
|
|
6
|
+
{
|
|
7
|
+
id: "command-injection",
|
|
8
|
+
title: "Export filename reaches a shell command",
|
|
9
|
+
severity: "critical",
|
|
10
|
+
cwe: "CWE-78",
|
|
11
|
+
summary: "The example export route interpolates an untrusted filename into a shell command, allowing shell metacharacters to execute another command.",
|
|
12
|
+
code: "exec(`convert ${request.body.filename} output.pdf`);",
|
|
13
|
+
remediation: "Pass the filename as a separate argument to a process API that does not invoke a shell.",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: "path-traversal",
|
|
17
|
+
title: "Archive entry escapes the extraction directory",
|
|
18
|
+
severity: "high",
|
|
19
|
+
cwe: "CWE-22",
|
|
20
|
+
summary: "The example archive extractor writes a supplied entry name without checking containment, allowing a parent-directory entry to overwrite a file outside the extraction directory.",
|
|
21
|
+
code: "await writeFile(join(outputDirectory, entry.name), entry.contents);",
|
|
22
|
+
remediation: "Resolve each entry destination and reject paths outside the extraction directory before writing.",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "missing-authorization",
|
|
26
|
+
title: "Document download omits the ownership check",
|
|
27
|
+
severity: "high",
|
|
28
|
+
cwe: "CWE-862",
|
|
29
|
+
summary: "The example download handler accepts a document ID from any signed-in account and returns the document without checking that the account owns it.",
|
|
30
|
+
code: "response.json(await documents.findById(request.params.id));",
|
|
31
|
+
remediation: "Restrict document lookup to records the authenticated account is authorized to read.",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "stored-xss",
|
|
35
|
+
title: "Comment preview renders stored HTML",
|
|
36
|
+
severity: "medium",
|
|
37
|
+
cwe: "CWE-79",
|
|
38
|
+
summary: "The example preview inserts a stored comment directly into HTML, allowing a comment author to execute script in another viewer's browser.",
|
|
39
|
+
code: "preview.innerHTML = comment.body;",
|
|
40
|
+
remediation: "Render comments as text or sanitize intentionally supported HTML before insertion.",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "verbose-errors",
|
|
44
|
+
title: "Error response exposes an internal stack trace",
|
|
45
|
+
severity: "low",
|
|
46
|
+
cwe: "CWE-209",
|
|
47
|
+
summary: "The example error handler returns a stack trace to a remote caller, revealing internal module names and filesystem layout.",
|
|
48
|
+
code: "response.status(500).send(error.stack);",
|
|
49
|
+
remediation: "Return a generic error identifier and retain diagnostic details in internal logs.",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "version-disclosure",
|
|
53
|
+
title: "Response header advertises the framework version",
|
|
54
|
+
severity: "informational",
|
|
55
|
+
cwe: "CWE-200",
|
|
56
|
+
summary: "The example response header exposes the precise framework version. This helps fingerprint the service but does not establish an exploitable vulnerability.",
|
|
57
|
+
code: 'response.setHeader("X-Example-Version", frameworkVersion);',
|
|
58
|
+
remediation: "Omit the framework version from public response headers.",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "sql-injection",
|
|
62
|
+
title: "Search term is concatenated into a SQL query",
|
|
63
|
+
severity: "high",
|
|
64
|
+
cwe: "CWE-89",
|
|
65
|
+
summary: "The example search handler concatenates request text into SQL, allowing a caller to change the query and read records beyond the intended search.",
|
|
66
|
+
code: "db.query(`SELECT * FROM items WHERE name = '${request.query.name}'`);",
|
|
67
|
+
remediation: "Use a parameterized query for the search term.",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "ssrf",
|
|
71
|
+
title: "Image proxy fetches arbitrary destinations",
|
|
72
|
+
severity: "medium",
|
|
73
|
+
cwe: "CWE-918",
|
|
74
|
+
summary: "The example image proxy fetches a caller-supplied URL without restricting its destination, allowing requests to internal services reachable by the proxy.",
|
|
75
|
+
code: "return await fetch(request.query.imageUrl);",
|
|
76
|
+
remediation: "Restrict fetch destinations to the intended image hosts and enforce that policy across redirects.",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "open-redirect",
|
|
80
|
+
title: "Sign-in callback accepts an external redirect",
|
|
81
|
+
severity: "medium",
|
|
82
|
+
cwe: "CWE-601",
|
|
83
|
+
summary: "The example sign-in callback redirects to a supplied URL without checking its origin, allowing an attacker to send users from the sign-in flow to an unrelated site.",
|
|
84
|
+
code: "response.redirect(request.query.returnTo);",
|
|
85
|
+
remediation: "Accept only application-relative return paths or explicitly permitted origins.",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "cookie-flags",
|
|
89
|
+
title: "Session cookie omits HttpOnly",
|
|
90
|
+
severity: "low",
|
|
91
|
+
cwe: "CWE-1004",
|
|
92
|
+
summary: "The example session cookie is accessible to browser scripts because HttpOnly is absent, increasing the impact of a separate script-injection vulnerability.",
|
|
93
|
+
code: 'response.cookie("session", sessionId, { secure: true });',
|
|
94
|
+
remediation: "Set HttpOnly on the session cookie.",
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
function mockFindings(scanId) {
|
|
98
|
+
const findings = EXAMPLES.map((example, index) => {
|
|
99
|
+
const unique = index >= 6;
|
|
100
|
+
const path = `mock/${example.id}${unique ? `-${scanId}` : ""}.ts`;
|
|
101
|
+
return {
|
|
102
|
+
ruleId: `mock.${example.id}`,
|
|
103
|
+
identity: { anchor: example.id, ...(unique ? { instance: scanId } : {}) },
|
|
104
|
+
title: `[Mock] ${example.title}`,
|
|
105
|
+
summary: `Synthetic test finding. ${example.summary}`,
|
|
106
|
+
severity: { level: example.severity },
|
|
107
|
+
confidence: {
|
|
108
|
+
level: "high",
|
|
109
|
+
rationale: "Deterministic fixture; not a conclusion about the scanned repository.",
|
|
110
|
+
},
|
|
111
|
+
taxonomy: { category: example.id, cwe: [example.cwe] },
|
|
112
|
+
locations: [{ path, startLine: 10, endLine: 10, role: "sink" }],
|
|
113
|
+
codeEvidence: [
|
|
114
|
+
{
|
|
115
|
+
id: "example-sink",
|
|
116
|
+
label: "Synthetic vulnerable operation",
|
|
117
|
+
path,
|
|
118
|
+
startLine: 10,
|
|
119
|
+
language: "typescript",
|
|
120
|
+
role: "sink",
|
|
121
|
+
code: example.code,
|
|
122
|
+
explanation: "Illustrative fixture code; this file is not read from or written to the repository.",
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
rootCause: { summary: example.summary, evidenceRefs: ["example-sink"] },
|
|
126
|
+
remediation: example.remediation,
|
|
127
|
+
validation: {
|
|
128
|
+
status: "mock",
|
|
129
|
+
method: "synthetic",
|
|
130
|
+
summary: "Fixture only; no code was analyzed or executed.",
|
|
131
|
+
},
|
|
132
|
+
attackPath: {
|
|
133
|
+
summary: example.summary,
|
|
134
|
+
assumptions: [
|
|
135
|
+
"The fictional example exposes this operation to untrusted input.",
|
|
136
|
+
],
|
|
137
|
+
evidenceRefs: ["example-sink"],
|
|
138
|
+
},
|
|
139
|
+
remediationTests: [
|
|
140
|
+
`In the example application, verify the fix: ${example.remediation}`,
|
|
141
|
+
],
|
|
142
|
+
preventiveControls: [example.remediation],
|
|
143
|
+
provenance: { source: "mock" },
|
|
144
|
+
extensions: {
|
|
145
|
+
mock: true,
|
|
146
|
+
mockGroup: example.id,
|
|
147
|
+
mockRecurrence: unique ? "unique" : "shared",
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
// Alternate reports have distinct identities but describe the same root causes.
|
|
152
|
+
for (const [index, title] of [
|
|
153
|
+
[0, "Shell metacharacters in the export name execute commands"],
|
|
154
|
+
[1, "Parent-directory archive names overwrite files outside extraction"],
|
|
155
|
+
]) {
|
|
156
|
+
const original = findings[index];
|
|
157
|
+
findings.push({
|
|
158
|
+
...structuredClone(original),
|
|
159
|
+
identity: { anchor: `${EXAMPLES[index].id}-alternate-report` },
|
|
160
|
+
title: `[Mock] ${title}`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return findings;
|
|
164
|
+
}
|
|
165
|
+
export async function writeMockScanDraft(scanDir, scanId, target, registration, signal) {
|
|
166
|
+
const contract = registration["contract"];
|
|
167
|
+
const diff = contract.diffTarget;
|
|
168
|
+
const snapshotDigest = diff && diff.kind !== "working_tree"
|
|
169
|
+
? `codex-security-snapshot/v1:sha256:${createHash("sha256").update(["codex-security-diff/v1", diff.kind, diff.baseRevision, diff.headRevision].join("\0")).digest("hex")}`
|
|
170
|
+
: undefined;
|
|
171
|
+
const description = "Synthetic mock scan for testing. No LLM calls or security analysis were performed. Locations and code snippets describe fictional examples.";
|
|
172
|
+
const documents = {
|
|
173
|
+
"scan-manifest.json": {
|
|
174
|
+
scan: {
|
|
175
|
+
target: {
|
|
176
|
+
kind: contract.target.allowedKinds[0],
|
|
177
|
+
...(snapshotDigest === undefined ? {} : { snapshotDigest }),
|
|
178
|
+
},
|
|
179
|
+
scope: {
|
|
180
|
+
summary: description,
|
|
181
|
+
runtimeStatus: "mock",
|
|
182
|
+
limitations: [description],
|
|
183
|
+
},
|
|
184
|
+
extensions: { mock: true },
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
"findings.json": { findings: mockFindings(scanId) },
|
|
188
|
+
"coverage.json": {
|
|
189
|
+
completeness: "complete",
|
|
190
|
+
inventoryStrategy: target.kind === "paths"
|
|
191
|
+
? "scoped_path"
|
|
192
|
+
: target.kind === "repository"
|
|
193
|
+
? "repository"
|
|
194
|
+
: "diff",
|
|
195
|
+
surfaces: EXAMPLES.map((example) => ({
|
|
196
|
+
id: `mock-${example.id}`,
|
|
197
|
+
label: `[Mock] ${example.title}`,
|
|
198
|
+
disposition: "reported",
|
|
199
|
+
receiptRefs: [],
|
|
200
|
+
notes: description,
|
|
201
|
+
})),
|
|
202
|
+
explicitExclusions: [],
|
|
203
|
+
deferred: [],
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
for (const [name, document] of Object.entries(documents)) {
|
|
207
|
+
await writeFile(join(scanDir, name), `${JSON.stringify(document, null, 2)}\n`, { flag: "wx", signal });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=mock-scan.js.map
|