@openai/codex-security 0.8.0 → 0.8.2
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 +16 -10
- package/_bundled_plugin/.codex-plugin/plugin.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/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/scan-artifacts.md +1 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +37 -1
- package/_bundled_plugin/scripts/servicenow_avit.py +107 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
- package/_bundled_plugin/scripts/workbench_db.py +1 -3
- package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
- package/_bundled_plugin/scripts/workbench_scan_start.py +4 -1
- package/_bundled_plugin/scripts/workbench_target.py +0 -108
- package/_bundled_plugin/skills/publish-findings/SKILL.md +9 -3
- package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
- package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
- package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +563 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +36 -15
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +12 -3
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +30 -10
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.js +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +1 -0
- package/dist/cli-help.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +72 -50
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +16 -12
- package/dist/contract.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +12 -4
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.js +2 -2
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +1 -1
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +36 -22
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +3 -1
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +12 -8
- package/dist/deduplication/records.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +46 -61
- package/dist/endor-findings.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +8 -6
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +3 -1
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +136 -36
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +3 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +56 -31
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +2 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +9 -0
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +11 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +13 -1
- package/dist/external-findings.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/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +5 -5
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts +6 -0
- package/dist/github-dependabot-findings.d.ts.map +1 -0
- package/dist/github-dependabot-findings.js +247 -0
- package/dist/github-dependabot-findings.js.map +1 -0
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +11 -4
- package/dist/github-findings.js.map +1 -1
- package/dist/github-identifiers.d.ts +4 -0
- package/dist/github-identifiers.d.ts.map +1 -0
- package/dist/github-identifiers.js +9 -0
- package/dist/github-identifiers.js.map +1 -0
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +4 -6
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +5 -0
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +27 -3
- package/dist/host-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +13 -5
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts +9 -0
- package/dist/inspector-findings.d.ts.map +1 -0
- package/dist/inspector-findings.js +517 -0
- package/dist/inspector-findings.js.map +1 -0
- package/dist/patch-tui.d.ts +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +4 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +15 -5
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +25 -15
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scanner-import.d.ts +6 -2
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +23 -14
- package/dist/scanner-import.js.map +1 -1
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +39 -49
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +78 -88
- package/dist/snyk-findings.js.map +1 -1
- package/docs/cli.md +52 -14
- package/docs/dedupe-records.md +17 -4
- package/docs/hosted-scans.md +14 -0
- package/package.json +5 -5
- package/schemas/external-findings.schema.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-import-models.js","sourceRoot":"","sources":["../src/external-import-models.ts"],"names":[],"mappings":"AAAA,qGAAqG","sourcesContent":["/* Generated from schemas/external-findings.schema.json. Run pnpm generate:external-import-models. */\n\nexport type RequestId = string;\nexport type Id = string;\nexport type RepoConnectorId = string;\nexport type EnvironmentId = string;\nexport type ResetMarker = string;\nexport type Provider = \"wiz\" | \"endor\" | \"snyk\" | \"github\" | \"semgrep\";\nexport type SourceKey = string;\nexport type ClientId = string;\nexport type SourceFindingId = string;\nexport type ExpectedVersion = number;\nexport type Title = string;\nexport type Severity =\n \"critical\" | \"high\" | \"medium\" | \"low\" | \"informational\" | \"unknown\";\nexport type Description = string | null;\nexport type Url = string | null;\n/**\n * @maxItems 100\n */\nexport type AdvisoryIds = string[];\nexport type Name = string;\nexport type Ecosystem = string | null;\nexport type InstalledVersion = string | null;\nexport type VulnerableVersionRange = string | null;\nexport type ManifestPath = string | null;\n/**\n * @maxItems 100\n */\nexport type FixedVersions = string[];\n/**\n * @maxItems 100\n */\nexport type Packages = ImportedPackage[];\nexport type Path = string;\nexport type Line = number | null;\n/**\n * @maxItems 100\n */\nexport type Locations = ImportedLocation[];\nexport type Branch = string | null;\nexport type CodeRevision = string | null;\nexport type SourceScanId = string | null;\n/**\n * @maxItems 100\n */\nexport type ImageDigests = string[];\nexport type SourceUpdatedAt = number | null;\nexport type Kind = \"sast\" | \"secret\" | \"iac\" | \"advisory\";\nexport type Url1 = string;\nexport type Id1 = string | null;\nexport type Name1 = string | null;\nexport type Source = \"repository\" | \"global\";\nexport type SourceStatus = string | null;\nexport type ScannerOrigin = string | null;\nexport type ScannerVerdict = string | null;\nexport type Id2 = string | null;\nexport type ShortId = string | null;\nexport type Name2 = string | null;\n/**\n * @maxItems 100\n */\nexport type WeaknessIds = string[];\nexport type RemediationInstructions = string | null;\nexport type EndLine = number | null;\nexport type Snippet = string | null;\nexport type Type = string | null;\nexport type ImportedSecretConfidence = string;\nexport type ValidationStatus = string | null;\nexport type IsEncrypted = boolean | null;\nexport type IsManaged = boolean | null;\nexport type IntroducedCommit = string | null;\nexport type Platform = string | null;\nexport type CloudPlatform = string | null;\nexport type Expected = string | null;\nexport type Actual = string | null;\nexport type FileUrl = string | null;\n/**\n * @minItems 1\n * @maxItems 100\n */\nexport type Items = FindingImportItem[];\nexport type Id3 = string;\nexport type Object = \"security.finding_import\";\nexport type Actor = string;\nexport type CreatedAt = number;\nexport type ItemCount = number;\nexport type Created = number;\nexport type Updated = number;\nexport type Unchanged = number;\nexport type Error = number;\nexport type ClientId1 = string;\nexport type Outcome = \"created\" | \"updated\" | \"unchanged\" | \"error\";\nexport type SourceReportId = string | null;\nexport type ObservationId = string | null;\nexport type CanonicalFindingId = string | null;\nexport type Version = number | null;\nexport type Code =\n \"version_conflict\" | \"scope_conflict\" | \"stale_source_snapshot\";\nexport type Message = string;\nexport type Results = FindingImportResult[];\nexport type Object1 = \"page\";\nexport type Id4 = string;\nexport type Object2 = \"security.repository\";\nexport type RepoConnectorId1 = string;\nexport type Url2 = string;\nexport type DefaultBranch = string | null;\nexport type ResetMarker1 = string;\nexport type ImportEnvironmentId = string | null;\nexport type Data = ImportRepository[];\nexport type HasMore = boolean;\nexport type Next = string | null;\nexport type Id5 = string;\nexport type Object3 = \"security.source_report\";\nexport type Origin = \"imported\";\nexport type RepoId = string;\nexport type RepoConnectorId2 = string;\nexport type EnvironmentId1 = string;\nexport type CanonicalFindingId1 = string;\nexport type SourceFindingId1 = string;\nexport type ObservationId1 = string;\nexport type Version1 = number;\nexport type State = \"not_assessed\";\nexport type Id6 = string;\nexport type Actor1 = string;\nexport type CreatedAt1 = number;\nexport type CreatedAt2 = number;\nexport type UpdatedAt = number;\nexport type Object4 = \"page\";\nexport type Id7 = string;\nexport type Object5 = \"security.source_report_summary\";\nexport type Origin1 = \"imported\";\nexport type RepoId1 = string;\nexport type RepoConnectorId3 = string;\nexport type EnvironmentId2 = string;\nexport type CanonicalFindingId2 = string;\nexport type SourceFindingId2 = string;\nexport type ObservationId2 = string;\nexport type Version2 = number;\nexport type Title1 = string;\nexport type Severity1 =\n \"critical\" | \"high\" | \"medium\" | \"low\" | \"informational\" | \"unknown\";\nexport type SourceUpdatedAt1 = number | null;\nexport type CreatedAt3 = number;\nexport type UpdatedAt1 = number;\nexport type Data1 = SourceReportSummary[];\nexport type HasMore1 = boolean;\nexport type Next1 = string | null;\n\n/**\n * Schema export root; transport endpoints return the individual models.\n */\nexport interface ExternalFindingContracts {\n request: FindingImportRequest;\n receipt: FindingImportReceipt;\n repositories: ImportRepositoryPage;\n source_report: SourceReport;\n source_reports: SourceReportPage;\n}\nexport interface FindingImportRequest {\n request_id: RequestId;\n repository: ImportDestination;\n source: ImportSource;\n items: Items;\n}\nexport interface ImportDestination {\n id: Id;\n repo_connector_id: RepoConnectorId;\n environment_id: EnvironmentId;\n reset_marker: ResetMarker;\n}\nexport interface ImportSource {\n provider: Provider;\n source_key: SourceKey;\n}\nexport interface FindingImportItem {\n client_id: ClientId;\n source_finding_id: SourceFindingId;\n expected_version: ExpectedVersion;\n evidence: ImportedFindingEvidence;\n}\nexport interface ImportedFindingEvidence {\n title: Title;\n severity: Severity;\n description?: Description;\n url?: Url;\n advisory_ids?: AdvisoryIds;\n packages?: Packages;\n locations?: Locations;\n branch?: Branch;\n code_revision?: CodeRevision;\n source_scan_id?: SourceScanId;\n image_digests?: ImageDigests;\n source_updated_at?: SourceUpdatedAt;\n source_data?: SourceData;\n details?: ImportedFindingDetails | null;\n}\nexport interface ImportedPackage {\n name: Name;\n ecosystem?: Ecosystem;\n installed_version?: InstalledVersion;\n vulnerable_version_range?: VulnerableVersionRange;\n manifest_path?: ManifestPath;\n fixed_versions?: FixedVersions;\n}\nexport interface ImportedLocation {\n path: Path;\n line?: Line;\n}\nexport interface SourceData {\n [k: string]: unknown;\n}\n/**\n * Typed repository evidence; vendor state is not a Codex assessment.\n */\nexport interface ImportedFindingDetails {\n kind: Kind;\n repository?: ImportedRepositoryReference | null;\n advisory?: ImportedAdvisoryContext | null;\n source_status?: SourceStatus;\n scanner_origin?: ScannerOrigin;\n scanner_verdict?: ScannerVerdict;\n rule?: ImportedFindingRule | null;\n weakness_ids?: WeaknessIds;\n remediation_instructions?: RemediationInstructions;\n code?: ImportedCodeContext | null;\n secret?: ImportedSecretDetails | null;\n configuration?: ImportedConfigurationDetails | null;\n file_url?: FileUrl;\n}\n/**\n * Vendor repository identity, resolved to the full source-control URL.\n */\nexport interface ImportedRepositoryReference {\n url: Url1;\n id?: Id1;\n name?: Name1;\n}\n/**\n * Where the advisory was read; applicability is assessed separately.\n */\nexport interface ImportedAdvisoryContext {\n source: Source;\n}\nexport interface ImportedFindingRule {\n id?: Id2;\n short_id?: ShortId;\n name?: Name2;\n}\n/**\n * Optional range and snippet for the evidence's first source location.\n */\nexport interface ImportedCodeContext {\n end_line?: EndLine;\n snippet?: Snippet;\n}\nexport interface ImportedSecretDetails {\n type?: Type;\n confidence?: ImportedSecretConfidence | null;\n validation_status?: ValidationStatus;\n is_encrypted?: IsEncrypted;\n is_managed?: IsManaged;\n introduced_commit?: IntroducedCommit;\n}\nexport interface ImportedConfigurationDetails {\n platform?: Platform;\n cloud_platform?: CloudPlatform;\n expected?: Expected;\n actual?: Actual;\n}\nexport interface FindingImportReceipt {\n id: Id3;\n object?: Object;\n repository: ImportDestination;\n source: ImportSource;\n actor: Actor;\n created_at: CreatedAt;\n item_count: ItemCount;\n counts: ImportCounts;\n results: Results;\n}\nexport interface ImportCounts {\n created?: Created;\n updated?: Updated;\n unchanged?: Unchanged;\n error?: Error;\n}\nexport interface FindingImportResult {\n client_id: ClientId1;\n outcome: Outcome;\n source_report_id?: SourceReportId;\n observation_id?: ObservationId;\n canonical_finding_id?: CanonicalFindingId;\n version?: Version;\n error?: ImportItemError | null;\n}\nexport interface ImportItemError {\n code: Code;\n message: Message;\n}\nexport interface ImportRepositoryPage {\n object?: Object1;\n data: Data;\n has_more: HasMore;\n next: Next;\n}\nexport interface ImportRepository {\n id: Id4;\n object?: Object2;\n repo_connector_id: RepoConnectorId1;\n url: Url2;\n default_branch?: DefaultBranch;\n reset_marker: ResetMarker1;\n import_environment_id?: ImportEnvironmentId;\n}\nexport interface SourceReport {\n id: Id5;\n object?: Object3;\n origin?: Origin;\n repo_id: RepoId;\n repo_connector_id: RepoConnectorId2;\n environment_id: EnvironmentId1;\n canonical_finding_id: CanonicalFindingId1;\n source: ImportSource;\n source_finding_id: SourceFindingId1;\n observation_id: ObservationId1;\n version: Version1;\n evidence: ImportedFindingEvidence;\n assessment?: ImportedAssessment;\n last_import?: LastImport | null;\n created_at: CreatedAt2;\n updated_at: UpdatedAt;\n}\nexport interface ImportedAssessment {\n state?: State;\n}\nexport interface LastImport {\n id: Id6;\n actor: Actor1;\n created_at: CreatedAt1;\n}\nexport interface SourceReportPage {\n object?: Object4;\n data: Data1;\n has_more: HasMore1;\n next: Next1;\n}\nexport interface SourceReportSummary {\n id: Id7;\n object?: Object5;\n origin?: Origin1;\n repo_id: RepoId1;\n repo_connector_id: RepoConnectorId3;\n environment_id: EnvironmentId2;\n canonical_finding_id: CanonicalFindingId2;\n source: ImportSource;\n source_finding_id: SourceFindingId2;\n observation_id: ObservationId2;\n version: Version2;\n title: Title1;\n severity: Severity1;\n source_updated_at: SourceUpdatedAt1;\n assessment?: ImportedAssessment;\n created_at: CreatedAt3;\n updated_at: UpdatedAt1;\n}\n\nexport type ExternalFindingEvidence = ImportedFindingEvidence;\n"]}
|
|
1
|
+
{"version":3,"file":"external-import-models.js","sourceRoot":"","sources":["../src/external-import-models.ts"],"names":[],"mappings":"AAAA,qGAAqG","sourcesContent":["/* Generated from schemas/external-findings.schema.json. Run pnpm generate:external-import-models. */\n\nexport type RequestId = string;\nexport type Id = string;\nexport type RepoConnectorId = string;\nexport type EnvironmentId = string;\nexport type ResetMarker = string;\nexport type Provider =\n \"wiz\" | \"endor\" | \"snyk\" | \"github\" | \"semgrep\" | \"inspector\";\nexport type SourceKey = string;\nexport type ClientId = string;\nexport type SourceFindingId = string;\nexport type ExpectedVersion = number;\nexport type Title = string;\nexport type Severity =\n \"critical\" | \"high\" | \"medium\" | \"low\" | \"informational\" | \"unknown\";\nexport type Description = string | null;\nexport type Url = string | null;\n/**\n * @maxItems 100\n */\nexport type AdvisoryIds = string[];\nexport type Name = string;\nexport type Ecosystem = string | null;\nexport type InstalledVersion = string | null;\nexport type VulnerableVersionRange = string | null;\nexport type ManifestPath = string | null;\n/**\n * @maxItems 100\n */\nexport type FixedVersions = string[];\n/**\n * @maxItems 100\n */\nexport type Packages = ImportedPackage[];\nexport type Path = string;\nexport type Line = number | null;\n/**\n * @maxItems 100\n */\nexport type Locations = ImportedLocation[];\nexport type Branch = string | null;\nexport type CodeRevision = string | null;\nexport type SourceScanId = string | null;\n/**\n * @maxItems 100\n */\nexport type ImageDigests = string[];\nexport type SourceUpdatedAt = number | null;\nexport type Kind = \"sast\" | \"secret\" | \"iac\" | \"advisory\";\nexport type Url1 = string;\nexport type Id1 = string | null;\nexport type Name1 = string | null;\nexport type Source = \"repository\" | \"global\";\nexport type SourceStatus = string | null;\nexport type ScannerOrigin = string | null;\nexport type ScannerVerdict = string | null;\nexport type Id2 = string | null;\nexport type ShortId = string | null;\nexport type Name2 = string | null;\n/**\n * @maxItems 100\n */\nexport type WeaknessIds = string[];\nexport type RemediationInstructions = string | null;\nexport type EndLine = number | null;\nexport type Snippet = string | null;\nexport type Type = string | null;\nexport type ImportedSecretConfidence = string;\nexport type ValidationStatus = string | null;\nexport type IsEncrypted = boolean | null;\nexport type IsManaged = boolean | null;\nexport type IntroducedCommit = string | null;\nexport type Platform = string | null;\nexport type CloudPlatform = string | null;\nexport type Expected = string | null;\nexport type Actual = string | null;\nexport type FileUrl = string | null;\n/**\n * @minItems 1\n * @maxItems 100\n */\nexport type Items = FindingImportItem[];\nexport type Id3 = string;\nexport type Object = \"security.finding_import\";\nexport type Actor = string;\nexport type CreatedAt = number;\nexport type ItemCount = number;\nexport type Created = number;\nexport type Updated = number;\nexport type Unchanged = number;\nexport type Error = number;\nexport type ClientId1 = string;\nexport type Outcome = \"created\" | \"updated\" | \"unchanged\" | \"error\";\nexport type SourceReportId = string | null;\nexport type ObservationId = string | null;\nexport type CanonicalFindingId = string | null;\nexport type Version = number | null;\nexport type Code =\n \"version_conflict\" | \"scope_conflict\" | \"stale_source_snapshot\";\nexport type Message = string;\nexport type Results = FindingImportResult[];\nexport type Object1 = \"page\";\nexport type Id4 = string;\nexport type Object2 = \"security.repository\";\nexport type RepoConnectorId1 = string;\nexport type Url2 = string;\nexport type DefaultBranch = string | null;\nexport type ResetMarker1 = string;\nexport type ImportEnvironmentId = string | null;\nexport type Data = ImportRepository[];\nexport type HasMore = boolean;\nexport type Next = string | null;\nexport type Id5 = string;\nexport type Object3 = \"security.source_report\";\nexport type Origin = \"imported\";\nexport type RepoId = string;\nexport type RepoConnectorId2 = string;\nexport type EnvironmentId1 = string;\nexport type CanonicalFindingId1 = string;\nexport type SourceFindingId1 = string;\nexport type ObservationId1 = string;\nexport type Version1 = number;\nexport type State = \"not_assessed\";\nexport type Id6 = string;\nexport type Actor1 = string;\nexport type CreatedAt1 = number;\nexport type CreatedAt2 = number;\nexport type UpdatedAt = number;\nexport type Object4 = \"page\";\nexport type Id7 = string;\nexport type Object5 = \"security.source_report_summary\";\nexport type Origin1 = \"imported\";\nexport type RepoId1 = string;\nexport type RepoConnectorId3 = string;\nexport type EnvironmentId2 = string;\nexport type CanonicalFindingId2 = string;\nexport type SourceFindingId2 = string;\nexport type ObservationId2 = string;\nexport type Version2 = number;\nexport type Title1 = string;\nexport type Severity1 =\n \"critical\" | \"high\" | \"medium\" | \"low\" | \"informational\" | \"unknown\";\nexport type SourceUpdatedAt1 = number | null;\nexport type CreatedAt3 = number;\nexport type UpdatedAt1 = number;\nexport type Data1 = SourceReportSummary[];\nexport type HasMore1 = boolean;\nexport type Next1 = string | null;\n\n/**\n * Schema export root; transport endpoints return the individual models.\n */\nexport interface ExternalFindingContracts {\n request: FindingImportRequest;\n receipt: FindingImportReceipt;\n repositories: ImportRepositoryPage;\n source_report: SourceReport;\n source_reports: SourceReportPage;\n}\nexport interface FindingImportRequest {\n request_id: RequestId;\n repository: ImportDestination;\n source: ImportSource;\n items: Items;\n}\nexport interface ImportDestination {\n id: Id;\n repo_connector_id: RepoConnectorId;\n environment_id: EnvironmentId;\n reset_marker: ResetMarker;\n}\nexport interface ImportSource {\n provider: Provider;\n source_key: SourceKey;\n}\nexport interface FindingImportItem {\n client_id: ClientId;\n source_finding_id: SourceFindingId;\n expected_version: ExpectedVersion;\n evidence: ImportedFindingEvidence;\n}\nexport interface ImportedFindingEvidence {\n title: Title;\n severity: Severity;\n description?: Description;\n url?: Url;\n advisory_ids?: AdvisoryIds;\n packages?: Packages;\n locations?: Locations;\n branch?: Branch;\n code_revision?: CodeRevision;\n source_scan_id?: SourceScanId;\n image_digests?: ImageDigests;\n source_updated_at?: SourceUpdatedAt;\n source_data?: SourceData;\n details?: ImportedFindingDetails | null;\n}\nexport interface ImportedPackage {\n name: Name;\n ecosystem?: Ecosystem;\n installed_version?: InstalledVersion;\n vulnerable_version_range?: VulnerableVersionRange;\n manifest_path?: ManifestPath;\n fixed_versions?: FixedVersions;\n}\nexport interface ImportedLocation {\n path: Path;\n line?: Line;\n}\nexport interface SourceData {\n [k: string]: unknown;\n}\n/**\n * Typed repository evidence; vendor state is not a Codex assessment.\n */\nexport interface ImportedFindingDetails {\n kind: Kind;\n repository?: ImportedRepositoryReference | null;\n advisory?: ImportedAdvisoryContext | null;\n source_status?: SourceStatus;\n scanner_origin?: ScannerOrigin;\n scanner_verdict?: ScannerVerdict;\n rule?: ImportedFindingRule | null;\n weakness_ids?: WeaknessIds;\n remediation_instructions?: RemediationInstructions;\n code?: ImportedCodeContext | null;\n secret?: ImportedSecretDetails | null;\n configuration?: ImportedConfigurationDetails | null;\n file_url?: FileUrl;\n}\n/**\n * Vendor repository identity, resolved to the full source-control URL.\n */\nexport interface ImportedRepositoryReference {\n url: Url1;\n id?: Id1;\n name?: Name1;\n}\n/**\n * Where the advisory was read; applicability is assessed separately.\n */\nexport interface ImportedAdvisoryContext {\n source: Source;\n}\nexport interface ImportedFindingRule {\n id?: Id2;\n short_id?: ShortId;\n name?: Name2;\n}\n/**\n * Optional range and snippet for the evidence's first source location.\n */\nexport interface ImportedCodeContext {\n end_line?: EndLine;\n snippet?: Snippet;\n}\nexport interface ImportedSecretDetails {\n type?: Type;\n confidence?: ImportedSecretConfidence | null;\n validation_status?: ValidationStatus;\n is_encrypted?: IsEncrypted;\n is_managed?: IsManaged;\n introduced_commit?: IntroducedCommit;\n}\nexport interface ImportedConfigurationDetails {\n platform?: Platform;\n cloud_platform?: CloudPlatform;\n expected?: Expected;\n actual?: Actual;\n}\nexport interface FindingImportReceipt {\n id: Id3;\n object?: Object;\n repository: ImportDestination;\n source: ImportSource;\n actor: Actor;\n created_at: CreatedAt;\n item_count: ItemCount;\n counts: ImportCounts;\n results: Results;\n}\nexport interface ImportCounts {\n created?: Created;\n updated?: Updated;\n unchanged?: Unchanged;\n error?: Error;\n}\nexport interface FindingImportResult {\n client_id: ClientId1;\n outcome: Outcome;\n source_report_id?: SourceReportId;\n observation_id?: ObservationId;\n canonical_finding_id?: CanonicalFindingId;\n version?: Version;\n error?: ImportItemError | null;\n}\nexport interface ImportItemError {\n code: Code;\n message: Message;\n}\nexport interface ImportRepositoryPage {\n object?: Object1;\n data: Data;\n has_more: HasMore;\n next: Next;\n}\nexport interface ImportRepository {\n id: Id4;\n object?: Object2;\n repo_connector_id: RepoConnectorId1;\n url: Url2;\n default_branch?: DefaultBranch;\n reset_marker: ResetMarker1;\n import_environment_id?: ImportEnvironmentId;\n}\nexport interface SourceReport {\n id: Id5;\n object?: Object3;\n origin?: Origin;\n repo_id: RepoId;\n repo_connector_id: RepoConnectorId2;\n environment_id: EnvironmentId1;\n canonical_finding_id: CanonicalFindingId1;\n source: ImportSource;\n source_finding_id: SourceFindingId1;\n observation_id: ObservationId1;\n version: Version1;\n evidence: ImportedFindingEvidence;\n assessment?: ImportedAssessment;\n last_import?: LastImport | null;\n created_at: CreatedAt2;\n updated_at: UpdatedAt;\n}\nexport interface ImportedAssessment {\n state?: State;\n}\nexport interface LastImport {\n id: Id6;\n actor: Actor1;\n created_at: CreatedAt1;\n}\nexport interface SourceReportPage {\n object?: Object4;\n data: Data1;\n has_more: HasMore1;\n next: Next1;\n}\nexport interface SourceReportSummary {\n id: Id7;\n object?: Object5;\n origin?: Origin1;\n repo_id: RepoId1;\n repo_connector_id: RepoConnectorId3;\n environment_id: EnvironmentId2;\n canonical_finding_id: CanonicalFindingId2;\n source: ImportSource;\n source_finding_id: SourceFindingId2;\n observation_id: ObservationId2;\n version: Version2;\n title: Title1;\n severity: Severity1;\n source_updated_at: SourceUpdatedAt1;\n assessment?: ImportedAssessment;\n created_at: CreatedAt3;\n updated_at: UpdatedAt1;\n}\n\nexport type ExternalFindingEvidence = ImportedFindingEvidence;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-advisories.d.ts","sourceRoot":"","sources":["../src/github-advisories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"github-advisories.d.ts","sourceRoot":"","sources":["../src/github-advisories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAS7C,eAAO,MAAM,sBAAsB,YACjC,WAAW,EACX,OAAO,EACP,QAAQ,EACR,QAAQ,CACA,CAAC;AAEX,MAAM,WAAW,2BAA2B;IAC1C,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAC;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAYrB;AAED,iBAAe,mBAAmB,CAChC,MAAM,EAAE,OAAO,EACf,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAOrB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CANONICAL_GHSA_ID, githubRepositoryParts, } from "./github-identifiers.js";
|
|
1
2
|
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
2
3
|
import { requireExternalImports } from "./external-imports-feature.js";
|
|
3
4
|
import { createAuthenticatedGitHub } from "./github.js";
|
|
@@ -13,18 +14,17 @@ export async function importGitHubAdvisories(options, dependencies = {}) {
|
|
|
13
14
|
const environment = dependencies.environment ?? process.env;
|
|
14
15
|
requireExternalImports(environment);
|
|
15
16
|
const repository = options.repository.trim();
|
|
16
|
-
const parts =
|
|
17
|
-
if (!parts
|
|
17
|
+
const parts = githubRepositoryParts(repository);
|
|
18
|
+
if (!parts)
|
|
18
19
|
throw new CodexSecurityError("GitHub repository must be OWNER/REPO.");
|
|
19
|
-
const owner = parts
|
|
20
|
-
const repo = parts[2];
|
|
20
|
+
const [owner, repo] = parts;
|
|
21
21
|
const ids = [
|
|
22
22
|
...new Set((options.advisoryIds ?? []).map((id) => id
|
|
23
23
|
.trim()
|
|
24
24
|
.toLowerCase()
|
|
25
25
|
.replace(/^ghsa-/u, "GHSA-"))),
|
|
26
26
|
];
|
|
27
|
-
if (ids.some((id) =>
|
|
27
|
+
if (ids.some((id) => !CANONICAL_GHSA_ID.test(id)))
|
|
28
28
|
throw new CodexSecurityError("GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form.");
|
|
29
29
|
const source = options.source ?? "repository";
|
|
30
30
|
const state = options.state ?? "published";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-advisories.js","sourceRoot":"","sources":["../src/github-advisories.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,WAAW;IACX,OAAO;IACP,QAAQ;IACR,QAAQ;CACA,CAAC;AAsCX,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAoC,EACpC,YAAY,GAAqC,EAAE;IAEnD,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAC5D,sBAAsB,CAAC,WAAW,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,oCAAoC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClE,MAAM,IAAI,kBAAkB,CAAC,uCAAuC,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;IACxB,MAAM,IAAI,GAAG,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vC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import type { Octokit } from \"@octokit/core\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport { requireExternalImports } from \"./external-imports-feature.js\";\nimport { createAuthenticatedGitHub } from \"./github.js\";\n\nexport const GITHUB_ADVISORY_STATES = [\n \"published\",\n \"draft\",\n \"triage\",\n \"closed\",\n] as const;\n\nexport interface GitHubAdvisoryImportOptions {\n /** Source repository, or the selected target for explicit global advisory IDs. */\n repository: string;\n /** Exact GHSA IDs. Required for the global advisory API. */\n advisoryIds?: readonly string[];\n /** Repository advisories by default; global never enumerates the database. */\n source?: \"repository\" | \"global\";\n /** Repository list state (default: published). Exact IDs ignore state. */\n state?: (typeof GITHUB_ADVISORY_STATES)[number];\n /** Defaults to GH_HOST or github.com. */\n githubHost?: string;\n /** Omit to use the authenticated GitHub CLI. */\n githubToken?: string;\n signal?: AbortSignal;\n}\n\ntype RepositoryAdvisory = Awaited<ReturnType<typeof fetchRepositoryAdvisory>>;\ntype GlobalAdvisory = Awaited<ReturnType<typeof fetchGlobalAdvisory>>;\n\nexport interface ImportedGitHubAdvisory {\n source: \"github-security-advisory\";\n selection: \"repository\" | \"global\";\n repository: string;\n githubHost: string;\n ghsaId: string;\n url: string;\n /** Upstream disclosure, not proof that the selected repository is affected. */\n advisory: RepositoryAdvisory | GlobalAdvisory;\n}\n\ninterface GitHubAdvisoryImportDependencies {\n environment?: NodeJS.ProcessEnv;\n currentDirectory?: string;\n createGitHub?: (host: string, signal?: AbortSignal) => Promise<Octokit>;\n}\n\n/** Read repository disclosures or explicitly selected public GHSA records. */\nexport async function importGitHubAdvisories(\n options: GitHubAdvisoryImportOptions,\n dependencies: GitHubAdvisoryImportDependencies = {},\n): Promise<ImportedGitHubAdvisory[]> {\n options.signal?.throwIfAborted();\n const environment = dependencies.environment ?? process.env;\n requireExternalImports(environment);\n const repository = options.repository.trim();\n const parts = /^([a-z0-9_.-]+)\\/([a-z0-9_.-]+)$/iu.exec(repository);\n if (!parts || parts.slice(1).some((part) => /^\\.{1,2}$/u.test(part)))\n throw new CodexSecurityError(\"GitHub repository must be OWNER/REPO.\");\n const owner = parts[1]!;\n const repo = parts[2]!;\n const ids = [\n ...new Set(\n (options.advisoryIds ?? []).map((id) =>\n id\n .trim()\n .toLowerCase()\n .replace(/^ghsa-/u, \"GHSA-\"),\n ),\n ),\n ];\n if (ids.some((id) => !/^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/u.test(id)))\n throw new CodexSecurityError(\n \"GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form.\",\n );\n const source = options.source ?? \"repository\";\n const state = options.state ?? \"published\";\n if (source !== \"repository\" && source !== \"global\")\n throw new CodexSecurityError(\n \"GitHub advisory source must be repository or global.\",\n );\n if (!GITHUB_ADVISORY_STATES.includes(state))\n throw new CodexSecurityError(\"GitHub advisory state is invalid.\");\n if (source === \"global\" && ids.length === 0)\n throw new CodexSecurityError(\n \"Select explicit GHSA IDs for global advisories; database-wide import is not supported.\",\n );\n if (ids.length > 0 && state !== \"published\")\n throw new CodexSecurityError(\n \"--github-state only filters repository lists; omit it when selecting exact GHSA IDs.\",\n );\n const host =\n options.githubHost?.trim() ??\n (environment[\"GH_HOST\"]?.trim() || \"github.com\");\n if (!host) throw new CodexSecurityError(\"GitHub host must not be empty.\");\n\n try {\n const github = dependencies.createGitHub\n ? await dependencies.createGitHub(host, options.signal)\n : await createAuthenticatedGitHub(host, {\n token: options.githubToken,\n environment,\n currentDirectory: dependencies.currentDirectory,\n signal: options.signal,\n });\n const advisories: (RepositoryAdvisory | GlobalAdvisory)[] = [];\n if (ids.length > 0) {\n for (const id of ids) {\n options.signal?.throwIfAborted();\n advisories.push(\n source === \"global\"\n ? await fetchGlobalAdvisory(github, id, options.signal)\n : await fetchRepositoryAdvisory(\n github,\n owner,\n repo,\n id,\n options.signal,\n ),\n );\n }\n } else {\n let after: string | undefined;\n const cursors = new Set<string>();\n do {\n options.signal?.throwIfAborted();\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories\",\n {\n owner,\n repo,\n state,\n per_page: 100,\n after,\n request: { signal: options.signal, redirect: \"error\" },\n },\n );\n advisories.push(...response.data);\n const next = response.headers.link\n ?.split(\",\")\n .find((link) => /;\\s*rel=\"next\"/u.test(link));\n const nextUrl = next?.match(/<([^>]+)>/u)?.[1];\n // Keep requests on the authenticated route; only carry over the cursor.\n after = nextUrl\n ? (new URL(nextUrl).searchParams.get(\"after\") ?? undefined)\n : undefined;\n if (next && (!after || cursors.has(after)))\n throw new CodexSecurityError(\n \"GitHub returned invalid advisory pagination.\",\n );\n if (after) cursors.add(after);\n } while (after !== undefined);\n }\n return advisories.map((advisory) => ({\n source: \"github-security-advisory\",\n selection: source,\n repository,\n githubHost: host,\n ghsaId: advisory.ghsa_id,\n url: advisory.html_url,\n advisory,\n }));\n } catch (error) {\n options.signal?.throwIfAborted();\n if (error instanceof CodexSecurityError) throw error;\n const status =\n typeof error === \"object\" && error !== null && \"status\" in error\n ? error.status\n : undefined;\n if (status === 401)\n throw new CodexSecurityError(\"GitHub authentication failed.\");\n if (status === 403)\n throw new CodexSecurityError(\n \"GitHub denied security advisory access. Check repository advisory permissions and API rate limits.\",\n );\n if (status === 404)\n throw new CodexSecurityError(\n \"GitHub repository or security advisory was not found or is not accessible.\",\n );\n if (status === 429)\n throw new CodexSecurityError(\n \"GitHub request was rate limited. Wait and retry.\",\n );\n throw new CodexSecurityError(\n `GitHub security advisory request failed${typeof status === \"number\" ? ` (HTTP ${status})` : \"\"}: ${errorMessage(error)}`,\n );\n }\n}\n\nasync function fetchRepositoryAdvisory(\n github: Octokit,\n owner: string,\n repo: string,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories/{ghsa_id}\",\n {\n owner,\n repo,\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n },\n );\n return response.data;\n}\n\nasync function fetchGlobalAdvisory(\n github: Octokit,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\"GET /advisories/{ghsa_id}\", {\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n });\n return response.data;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"github-advisories.js","sourceRoot":"","sources":["../src/github-advisories.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,WAAW;IACX,OAAO;IACP,QAAQ;IACR,QAAQ;CACA,CAAC;AAsCX,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAoC,EACpC,YAAY,GAAqC,EAAE;IAEnD,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAC5D,sBAAsB,CAAC,WAAW,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAChD,IAAI,CAAC,KAAK;QACR,MAAM,IAAI,kBAAkB,CAAC,uCAAuC,CAAC,CAAC;IACxE,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;IAC5B,MAAM,GAAG,GAAG;QACV,GAAG,IAAI,GAAG,CACR,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACrC,EAA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,GAAG;YAChB,MAAM,IAAI,kBAAkB,CAAC,+BAA+B,CAAC,CAAC;QAChE,IAAI,MAAM,KAAK,GAAG;YAChB,MAAM,IAAI,kBAAkB,CAC1B,oGAAoG,CACrG,CAAC;QACJ,IAAI,MAAM,KAAK,GAAG;YAChB,MAAM,IAAI,kBAAkB,CAC1B,4EAA4E,CAC7E,CAAC;QACJ,IAAI,MAAM,KAAK,GAAG;YAChB,MAAM,IAAI,kBAAkB,CAC1B,kDAAkD,CACnD,CAAC;QACJ,MAAM,IAAI,kBAAkB,CAC1B,0CAA0C,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,YAAY,CAAC,KAAK,CAAC,EAAE,CAC1H,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,uBAAuB,CACpC,MAAe,EACf,KAAa,EACb,IAAY,EACZ,EAAU,EACV,MAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CACnC,yDAAyD,EACzD;QACE,KAAK;QACL,IAAI;QACJ,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE;KACvC,CACF,CAAC;IACF,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,mBAAmB,CAChC,MAAe,EACf,EAAU,EACV,MAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,2BAA2B,EAAE;QACjE,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE;KACvC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import type { Octokit } from \"@octokit/core\";\nimport {\n CANONICAL_GHSA_ID,\n githubRepositoryParts,\n} from \"./github-identifiers.js\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport { requireExternalImports } from \"./external-imports-feature.js\";\nimport { createAuthenticatedGitHub } from \"./github.js\";\n\nexport const GITHUB_ADVISORY_STATES = [\n \"published\",\n \"draft\",\n \"triage\",\n \"closed\",\n] as const;\n\nexport interface GitHubAdvisoryImportOptions {\n /** Source repository, or the selected target for explicit global advisory IDs. */\n repository: string;\n /** Exact GHSA IDs. Required for the global advisory API. */\n advisoryIds?: readonly string[];\n /** Repository advisories by default; global never enumerates the database. */\n source?: \"repository\" | \"global\";\n /** Repository list state (default: published). Exact IDs ignore state. */\n state?: (typeof GITHUB_ADVISORY_STATES)[number];\n /** Defaults to GH_HOST or github.com. */\n githubHost?: string;\n /** Omit to use the authenticated GitHub CLI. */\n githubToken?: string;\n signal?: AbortSignal;\n}\n\ntype RepositoryAdvisory = Awaited<ReturnType<typeof fetchRepositoryAdvisory>>;\ntype GlobalAdvisory = Awaited<ReturnType<typeof fetchGlobalAdvisory>>;\n\nexport interface ImportedGitHubAdvisory {\n source: \"github-security-advisory\";\n selection: \"repository\" | \"global\";\n repository: string;\n githubHost: string;\n ghsaId: string;\n url: string;\n /** Upstream disclosure, not proof that the selected repository is affected. */\n advisory: RepositoryAdvisory | GlobalAdvisory;\n}\n\ninterface GitHubAdvisoryImportDependencies {\n environment?: NodeJS.ProcessEnv;\n currentDirectory?: string;\n createGitHub?: (host: string, signal?: AbortSignal) => Promise<Octokit>;\n}\n\n/** Read repository disclosures or explicitly selected public GHSA records. */\nexport async function importGitHubAdvisories(\n options: GitHubAdvisoryImportOptions,\n dependencies: GitHubAdvisoryImportDependencies = {},\n): Promise<ImportedGitHubAdvisory[]> {\n options.signal?.throwIfAborted();\n const environment = dependencies.environment ?? process.env;\n requireExternalImports(environment);\n const repository = options.repository.trim();\n const parts = githubRepositoryParts(repository);\n if (!parts)\n throw new CodexSecurityError(\"GitHub repository must be OWNER/REPO.\");\n const [owner, repo] = parts;\n const ids = [\n ...new Set(\n (options.advisoryIds ?? []).map((id) =>\n id\n .trim()\n .toLowerCase()\n .replace(/^ghsa-/u, \"GHSA-\"),\n ),\n ),\n ];\n if (ids.some((id) => !CANONICAL_GHSA_ID.test(id)))\n throw new CodexSecurityError(\n \"GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form.\",\n );\n const source = options.source ?? \"repository\";\n const state = options.state ?? \"published\";\n if (source !== \"repository\" && source !== \"global\")\n throw new CodexSecurityError(\n \"GitHub advisory source must be repository or global.\",\n );\n if (!GITHUB_ADVISORY_STATES.includes(state))\n throw new CodexSecurityError(\"GitHub advisory state is invalid.\");\n if (source === \"global\" && ids.length === 0)\n throw new CodexSecurityError(\n \"Select explicit GHSA IDs for global advisories; database-wide import is not supported.\",\n );\n if (ids.length > 0 && state !== \"published\")\n throw new CodexSecurityError(\n \"--github-state only filters repository lists; omit it when selecting exact GHSA IDs.\",\n );\n const host =\n options.githubHost?.trim() ??\n (environment[\"GH_HOST\"]?.trim() || \"github.com\");\n if (!host) throw new CodexSecurityError(\"GitHub host must not be empty.\");\n\n try {\n const github = dependencies.createGitHub\n ? await dependencies.createGitHub(host, options.signal)\n : await createAuthenticatedGitHub(host, {\n token: options.githubToken,\n environment,\n currentDirectory: dependencies.currentDirectory,\n signal: options.signal,\n });\n const advisories: (RepositoryAdvisory | GlobalAdvisory)[] = [];\n if (ids.length > 0) {\n for (const id of ids) {\n options.signal?.throwIfAborted();\n advisories.push(\n source === \"global\"\n ? await fetchGlobalAdvisory(github, id, options.signal)\n : await fetchRepositoryAdvisory(\n github,\n owner,\n repo,\n id,\n options.signal,\n ),\n );\n }\n } else {\n let after: string | undefined;\n const cursors = new Set<string>();\n do {\n options.signal?.throwIfAborted();\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories\",\n {\n owner,\n repo,\n state,\n per_page: 100,\n after,\n request: { signal: options.signal, redirect: \"error\" },\n },\n );\n advisories.push(...response.data);\n const next = response.headers.link\n ?.split(\",\")\n .find((link) => /;\\s*rel=\"next\"/u.test(link));\n const nextUrl = next?.match(/<([^>]+)>/u)?.[1];\n // Keep requests on the authenticated route; only carry over the cursor.\n after = nextUrl\n ? (new URL(nextUrl).searchParams.get(\"after\") ?? undefined)\n : undefined;\n if (next && (!after || cursors.has(after)))\n throw new CodexSecurityError(\n \"GitHub returned invalid advisory pagination.\",\n );\n if (after) cursors.add(after);\n } while (after !== undefined);\n }\n return advisories.map((advisory) => ({\n source: \"github-security-advisory\",\n selection: source,\n repository,\n githubHost: host,\n ghsaId: advisory.ghsa_id,\n url: advisory.html_url,\n advisory,\n }));\n } catch (error) {\n options.signal?.throwIfAborted();\n if (error instanceof CodexSecurityError) throw error;\n const status =\n typeof error === \"object\" && error !== null && \"status\" in error\n ? error.status\n : undefined;\n if (status === 401)\n throw new CodexSecurityError(\"GitHub authentication failed.\");\n if (status === 403)\n throw new CodexSecurityError(\n \"GitHub denied security advisory access. Check repository advisory permissions and API rate limits.\",\n );\n if (status === 404)\n throw new CodexSecurityError(\n \"GitHub repository or security advisory was not found or is not accessible.\",\n );\n if (status === 429)\n throw new CodexSecurityError(\n \"GitHub request was rate limited. Wait and retry.\",\n );\n throw new CodexSecurityError(\n `GitHub security advisory request failed${typeof status === \"number\" ? ` (HTTP ${status})` : \"\"}: ${errorMessage(error)}`,\n );\n }\n}\n\nasync function fetchRepositoryAdvisory(\n github: Octokit,\n owner: string,\n repo: string,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories/{ghsa_id}\",\n {\n owner,\n repo,\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n },\n );\n return response.data;\n}\n\nasync function fetchGlobalAdvisory(\n github: Octokit,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\"GET /advisories/{ghsa_id}\", {\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n });\n return response.data;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ExternalImportTarget } from "./external-import-contract.js";
|
|
2
|
+
import type { ExternalFinding, ExternalFindings } from "./external-findings.js";
|
|
3
|
+
export declare function isGitHubDependabotAlert(value: unknown): value is Record<string, unknown>;
|
|
4
|
+
export declare function dependabotRepository({ source_finding_id: id, evidence: { source_data: sourceData, url }, }: ExternalFinding): string | undefined;
|
|
5
|
+
export declare function normalizeGitHubDependabotAlerts(input: unknown, target?: ExternalImportTarget): ExternalFindings;
|
|
6
|
+
//# sourceMappingURL=github-dependabot-findings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-dependabot-findings.d.ts","sourceRoot":"","sources":["../src/github-dependabot-findings.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAKhF,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAalC;AAkHD,wBAAgB,oBAAoB,CAAC,EACnC,iBAAiB,EAAE,EAAE,EACrB,QAAQ,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,GAC3C,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CA8BtC;AAmID,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAwClB"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GHSA_ID, githubRepositoryParts } from "./github-identifiers.js";
|
|
3
|
+
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
4
|
+
import { validateExternalEvidence, } from "./external-import-contract.js";
|
|
5
|
+
import { isGitHubCloudHost } from "./git-remote.js";
|
|
6
|
+
import { isRecord } from "./record.js";
|
|
7
|
+
import { record, relativePath, requiredText, text } from "./scanner-import.js";
|
|
8
|
+
export function isGitHubDependabotAlert(value) {
|
|
9
|
+
return (isRecord(value) &&
|
|
10
|
+
("security_vulnerability" in value ||
|
|
11
|
+
("dependency" in value && "security_advisory" in value) ||
|
|
12
|
+
[value["url"], value["html_url"]].some((url) => typeof url === "string" &&
|
|
13
|
+
/^\/(?:[^/]+\/[^/]+\/security\/dependabot|(?:api\/v3\/)?repos\/[^/]+\/[^/]+\/dependabot\/alerts)\/\d+$/iu.test(URL.parse(url)?.pathname ?? ""))));
|
|
14
|
+
}
|
|
15
|
+
function webIdentity(url) {
|
|
16
|
+
const match = /^(https?):\/\/([^/?#@\\\s]+)\/([^/?#]+\/[^/?#]+)\/security\/dependabot\/([1-9]\d*)$/iu.exec(url);
|
|
17
|
+
if (!match || !githubRepositoryParts(match[3]))
|
|
18
|
+
return null;
|
|
19
|
+
const parsed = URL.parse(url);
|
|
20
|
+
if (!parsed ||
|
|
21
|
+
(parsed.protocol === "http:" && isGitHubCloudHost(parsed.hostname)))
|
|
22
|
+
return null;
|
|
23
|
+
const host = match[2].toLowerCase();
|
|
24
|
+
const repository = match[3].toLowerCase();
|
|
25
|
+
const origin = `${parsed.protocol}//${host}`;
|
|
26
|
+
const number = match[4];
|
|
27
|
+
const apiBase = isGitHubCloudHost(parsed.hostname)
|
|
28
|
+
? `https://api.${host}`
|
|
29
|
+
: `${origin}/api/v3`;
|
|
30
|
+
const repositoryUrl = `${origin}/${repository}`;
|
|
31
|
+
const apiRepo = `${apiBase}/repos/${repository}`;
|
|
32
|
+
return {
|
|
33
|
+
repository,
|
|
34
|
+
repositoryUrl,
|
|
35
|
+
apiRepo,
|
|
36
|
+
number,
|
|
37
|
+
sourceId: `${host}/${repository}/dependabot/${number}`,
|
|
38
|
+
htmlUrl: `${repositoryUrl}/security/dependabot/${number}`,
|
|
39
|
+
apiUrl: `${apiRepo}/dependabot/alerts/${number}`,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// Normalized SDK evidence may link to either REST or the web UI.
|
|
43
|
+
function alertUrlIdentity(url) {
|
|
44
|
+
if (typeof url !== "string")
|
|
45
|
+
return null;
|
|
46
|
+
const web = webIdentity(url);
|
|
47
|
+
if (web)
|
|
48
|
+
return web;
|
|
49
|
+
const api = /^(https?:\/\/)([^/?#@\\\s]+)\/(api\/v3\/)?repos\/([^/]+\/[^/]+)\/dependabot\/alerts\/([1-9]\d*)$/iu.exec(url);
|
|
50
|
+
if (!api)
|
|
51
|
+
return null;
|
|
52
|
+
const host = api[3] ? api[2] : api[2].replace(/^api\./iu, "");
|
|
53
|
+
const parsed = webIdentity(`${api[1]}${host}/${api[4]}/security/dependabot/${api[5]}`);
|
|
54
|
+
return parsed?.apiUrl === url.toLowerCase() ? parsed : null;
|
|
55
|
+
}
|
|
56
|
+
function checkSourceFamily(alert) {
|
|
57
|
+
if (alert["source"] === "github-code-scanning" ||
|
|
58
|
+
alert["source"] === "github-security-advisory")
|
|
59
|
+
throw new Error("Dependabot alert conflicts with its GitHub source family.");
|
|
60
|
+
}
|
|
61
|
+
function checkNativeClaims(alert, occurrence) {
|
|
62
|
+
if ("number" in alert && alert["number"] !== Number(occurrence.number))
|
|
63
|
+
throw new Error("Dependabot alert number must match the repository alert URL.");
|
|
64
|
+
if (("url" in alert &&
|
|
65
|
+
text(alert["url"])?.toLowerCase() !== occurrence.apiUrl) ||
|
|
66
|
+
("html_url" in alert &&
|
|
67
|
+
text(alert["html_url"])?.toLowerCase() !== occurrence.htmlUrl))
|
|
68
|
+
throw new Error("Dependabot API url and html_url must identify the same host, repository and alert number.");
|
|
69
|
+
if ("repository" in alert) {
|
|
70
|
+
const declared = record(alert["repository"], "Dependabot repository");
|
|
71
|
+
if (text(declared["full_name"])?.toLowerCase() !== occurrence.repository ||
|
|
72
|
+
("html_url" in declared &&
|
|
73
|
+
text(declared["html_url"])?.toLowerCase() !==
|
|
74
|
+
occurrence.repositoryUrl) ||
|
|
75
|
+
("url" in declared &&
|
|
76
|
+
text(declared["url"])?.toLowerCase() !== occurrence.apiRepo))
|
|
77
|
+
throw new Error("Dependabot repository metadata conflicts with its alert URLs.");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function identity(alert) {
|
|
81
|
+
checkSourceFamily(alert);
|
|
82
|
+
const number = alert["number"];
|
|
83
|
+
if (typeof number !== "number" || !Number.isSafeInteger(number) || number < 1)
|
|
84
|
+
throw new Error("Dependabot alert number must be a positive safe integer.");
|
|
85
|
+
const url = requiredText(alert["html_url"], "Dependabot html_url");
|
|
86
|
+
const parsed = webIdentity(url);
|
|
87
|
+
if (!parsed || parsed.number !== String(number))
|
|
88
|
+
throw new Error("Dependabot html_url must identify the repository and alert number.");
|
|
89
|
+
requiredText(alert["url"], "Dependabot API url");
|
|
90
|
+
checkNativeClaims(alert, parsed);
|
|
91
|
+
return {
|
|
92
|
+
repositoryUrl: parsed.repositoryUrl,
|
|
93
|
+
sourceId: parsed.sourceId,
|
|
94
|
+
url,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function dependabotRepository({ source_finding_id: id, evidence: { source_data: sourceData, url }, }) {
|
|
98
|
+
const native = isGitHubDependabotAlert(sourceData) ? sourceData : null;
|
|
99
|
+
const raw = native &&
|
|
100
|
+
(alertUrlIdentity(native["html_url"]) ?? alertUrlIdentity(native["url"]));
|
|
101
|
+
const projected = alertUrlIdentity(url);
|
|
102
|
+
const occurrence = raw ?? projected;
|
|
103
|
+
const structuredId = /^[^/]+\/[^/]+\/[^/]+\/(?:dependabot|code-scanning|security-advisory)\//u.test(id);
|
|
104
|
+
if (!occurrence) {
|
|
105
|
+
if (/^[^/]+\/[^/]+\/[^/]+\/dependabot\/[1-9]\d*$/u.test(id))
|
|
106
|
+
throw new CodexSecurityError("The normalized Dependabot occurrence needs the original alert or its repository alert URL.");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (isRecord(sourceData))
|
|
110
|
+
checkSourceFamily(sourceData);
|
|
111
|
+
if (native)
|
|
112
|
+
checkNativeClaims(native, occurrence);
|
|
113
|
+
// A caller may have stored this occurrence under an opaque ID before native imports existed.
|
|
114
|
+
if ((structuredId || id === "") && id !== occurrence.sourceId)
|
|
115
|
+
throw new CodexSecurityError("The normalized source finding ID does not match the original Dependabot alert.");
|
|
116
|
+
if (raw && projected && raw.htmlUrl !== projected.htmlUrl)
|
|
117
|
+
throw new CodexSecurityError("The normalized alert URL does not match the original Dependabot alert.");
|
|
118
|
+
return occurrence.repositoryUrl;
|
|
119
|
+
}
|
|
120
|
+
function selectedAlerts(input) {
|
|
121
|
+
const selection = Array.isArray(input) ? input : [input];
|
|
122
|
+
const hasPages = selection.some(Array.isArray);
|
|
123
|
+
if (hasPages && !selection.every(Array.isArray))
|
|
124
|
+
throw new Error("Dependabot input must not mix alert records and page arrays.");
|
|
125
|
+
const rows = hasPages ? selection.flat() : selection;
|
|
126
|
+
if (!rows.every(isGitHubDependabotAlert))
|
|
127
|
+
throw new Error("Expected complete native Dependabot repository alerts, not mixed families, page shapes or API envelopes.");
|
|
128
|
+
return rows;
|
|
129
|
+
}
|
|
130
|
+
// Parse only the matched vulnerability projection. Keep the complete upstream alert as evidence.
|
|
131
|
+
const nonblank = z.string().regex(/\S/u);
|
|
132
|
+
const matchedVulnerability = z.object({
|
|
133
|
+
package: z.object({ name: nonblank, ecosystem: nonblank }),
|
|
134
|
+
vulnerable_version_range: nonblank,
|
|
135
|
+
first_patched_version: z.object({ identifier: nonblank }).nullable(),
|
|
136
|
+
severity: z.enum(["critical", "high", "medium", "low"]),
|
|
137
|
+
});
|
|
138
|
+
function evidence(alert, url) {
|
|
139
|
+
const dependency = record(alert["dependency"], "Dependabot dependency");
|
|
140
|
+
const advisory = record(alert["security_advisory"], "Dependabot security_advisory");
|
|
141
|
+
const { package: { name, ecosystem }, vulnerable_version_range: range, first_patched_version: patch, severity, } = matchedVulnerability.parse(alert["security_vulnerability"]);
|
|
142
|
+
if ("package" in dependency) {
|
|
143
|
+
const observed = record(dependency["package"], "Dependabot dependency package");
|
|
144
|
+
if (observed["name"] !== name || observed["ecosystem"] !== ecosystem)
|
|
145
|
+
throw new Error("Dependabot dependency and matched vulnerability packages disagree.");
|
|
146
|
+
}
|
|
147
|
+
const path = dependency["manifest_path"] ?? null;
|
|
148
|
+
if (path !== null) {
|
|
149
|
+
const filename = relativePath(path)?.split("/").at(-1);
|
|
150
|
+
if (typeof path !== "string" ||
|
|
151
|
+
/^[a-z][a-z\d+.-]*:/iu.test(path) ||
|
|
152
|
+
!filename ||
|
|
153
|
+
filename === ".")
|
|
154
|
+
throw new Error("Dependabot manifest_path must identify a repository-relative file.");
|
|
155
|
+
}
|
|
156
|
+
const ghsa = requiredText(advisory["ghsa_id"], "Dependabot GHSA ID");
|
|
157
|
+
if (!GHSA_ID.test(ghsa))
|
|
158
|
+
throw new Error("Dependabot security_advisory must identify a GHSA.");
|
|
159
|
+
const affected = advisory["vulnerabilities"];
|
|
160
|
+
if (!Array.isArray(affected) ||
|
|
161
|
+
!affected.some((entry) => isRecord(entry) &&
|
|
162
|
+
isRecord(entry["package"]) &&
|
|
163
|
+
entry["package"]["name"] === name &&
|
|
164
|
+
entry["package"]["ecosystem"] === ecosystem &&
|
|
165
|
+
entry["vulnerable_version_range"] === range))
|
|
166
|
+
throw new Error("Dependabot advisory does not cover the matched package and vulnerable range.");
|
|
167
|
+
const state = alert["state"];
|
|
168
|
+
if (typeof state !== "string" ||
|
|
169
|
+
!["open", "dismissed", "auto_dismissed", "fixed"].includes(state))
|
|
170
|
+
throw new Error("Dependabot alert state must be open, dismissed, auto_dismissed or fixed.");
|
|
171
|
+
const updated = Date.parse(requiredText(alert["updated_at"], "Dependabot updated_at")) /
|
|
172
|
+
1000;
|
|
173
|
+
if (!Number.isFinite(updated) || updated < 0)
|
|
174
|
+
throw new Error("Dependabot updated_at must be a valid timestamp.");
|
|
175
|
+
const advisoryIds = new Set([ghsa]);
|
|
176
|
+
const cve = text(advisory["cve_id"]);
|
|
177
|
+
if (cve)
|
|
178
|
+
advisoryIds.add(cve);
|
|
179
|
+
const identifiers = advisory["identifiers"];
|
|
180
|
+
if (Array.isArray(identifiers)) {
|
|
181
|
+
for (const item of identifiers) {
|
|
182
|
+
const value = isRecord(item) && text(item["value"]);
|
|
183
|
+
if (!value)
|
|
184
|
+
continue;
|
|
185
|
+
if ((item["type"] === "GHSA" || /^GHSA-/iu.test(value)) &&
|
|
186
|
+
value.toUpperCase() !== ghsa.toUpperCase())
|
|
187
|
+
throw new Error("Dependabot advisory identifiers disagree on the GHSA.");
|
|
188
|
+
advisoryIds.add(value);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
title: requiredText(advisory["summary"], "Dependabot advisory summary"),
|
|
193
|
+
description: text(advisory["description"]),
|
|
194
|
+
severity,
|
|
195
|
+
url,
|
|
196
|
+
advisory_ids: [...advisoryIds],
|
|
197
|
+
packages: [
|
|
198
|
+
{
|
|
199
|
+
name,
|
|
200
|
+
ecosystem,
|
|
201
|
+
manifest_path: path,
|
|
202
|
+
vulnerable_version_range: range,
|
|
203
|
+
fixed_versions: patch ? [patch.identifier] : [],
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
locations: path ? [{ path }] : [],
|
|
207
|
+
source_updated_at: Math.floor(updated),
|
|
208
|
+
source_data: structuredClone(alert),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
export function normalizeGitHubDependabotAlerts(input, target = "cloud") {
|
|
212
|
+
const alerts = selectedAlerts(input);
|
|
213
|
+
const result = {
|
|
214
|
+
read: alerts.length,
|
|
215
|
+
findings: [],
|
|
216
|
+
excluded: [],
|
|
217
|
+
};
|
|
218
|
+
const ids = new Set();
|
|
219
|
+
let sourceRepository;
|
|
220
|
+
for (const [index, alert] of alerts.entries()) {
|
|
221
|
+
const { repositoryUrl, sourceId, url } = identity(alert);
|
|
222
|
+
if (sourceRepository !== undefined && sourceRepository !== repositoryUrl)
|
|
223
|
+
throw new CodexSecurityError("Select Dependabot alerts from only one GitHub host and repository.");
|
|
224
|
+
sourceRepository = repositoryUrl;
|
|
225
|
+
if (ids.has(sourceId))
|
|
226
|
+
throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(sourceId)}. Select each Dependabot alert once.`);
|
|
227
|
+
ids.add(sourceId);
|
|
228
|
+
const inputEvidence = evidence(alert, url);
|
|
229
|
+
try {
|
|
230
|
+
if (target === "cloud" && Buffer.byteLength(sourceId) > 512)
|
|
231
|
+
throw new Error("Source finding ID exceeds the Cloud limit of 512 UTF-8 bytes.");
|
|
232
|
+
result.findings.push({
|
|
233
|
+
source_finding_id: sourceId,
|
|
234
|
+
evidence: validateExternalEvidence(inputEvidence, target),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
result.excluded.push({
|
|
239
|
+
position: index + 1,
|
|
240
|
+
source_finding_id: sourceId,
|
|
241
|
+
reason: errorMessage(error),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=github-dependabot-findings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-dependabot-findings.js","sourceRoot":"","sources":["../src/github-dependabot-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAEL,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE/E,MAAM,UAAU,uBAAuB,CACrC,KAA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AAa;YACtE,MAAM,IAAI,kBAAkB,CAC1B,oEAAoE,CACrE,CAAC;QACJ,gBAAgB,GAAG,aAAa,CAAC;QACjC,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,MAAM,IAAI,kBAAkB,CAC1B,+BAA+B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,sCAAsC,CAC9F,CAAC;QACJ,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAClB,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC;YACH,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,GAAG;gBACzD,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;YACJ,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACnB,iBAAiB,EAAE,QAAQ;gBAC3B,QAAQ,EAAE,wBAAwB,CAAC,aAAa,EAAE,MAAM,CAAC;aAC1D,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACnB,QAAQ,EAAE,KAAK,GAAG,CAAC;gBACnB,iBAAiB,EAAE,QAAQ;gBAC3B,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC;aAC5B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { GHSA_ID, githubRepositoryParts } from \"./github-identifiers.js\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport {\n type ExternalImportTarget,\n validateExternalEvidence,\n} from \"./external-import-contract.js\";\nimport type { ExternalFinding, ExternalFindings } from \"./external-findings.js\";\nimport { isGitHubCloudHost } from \"./git-remote.js\";\nimport { isRecord } from \"./record.js\";\nimport { record, relativePath, requiredText, text } from \"./scanner-import.js\";\n\nexport function isGitHubDependabotAlert(\n value: unknown,\n): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (\"security_vulnerability\" in value ||\n (\"dependency\" in value && \"security_advisory\" in value) ||\n [value[\"url\"], value[\"html_url\"]].some(\n (url) =>\n typeof url === \"string\" &&\n /^\\/(?:[^/]+\\/[^/]+\\/security\\/dependabot|(?:api\\/v3\\/)?repos\\/[^/]+\\/[^/]+\\/dependabot\\/alerts)\\/\\d+$/iu.test(\n URL.parse(url)?.pathname ?? \"\",\n ),\n ))\n );\n}\n\nfunction webIdentity(url: string) {\n const match =\n /^(https?):\\/\\/([^/?#@\\\\\\s]+)\\/([^/?#]+\\/[^/?#]+)\\/security\\/dependabot\\/([1-9]\\d*)$/iu.exec(\n url,\n );\n if (!match || !githubRepositoryParts(match[3]!)) return null;\n const parsed = URL.parse(url);\n if (\n !parsed ||\n (parsed.protocol === \"http:\" && isGitHubCloudHost(parsed.hostname))\n )\n return null;\n const host = match[2]!.toLowerCase();\n const repository = match[3]!.toLowerCase();\n const origin = `${parsed.protocol}//${host}`;\n const number = match[4]!;\n const apiBase = isGitHubCloudHost(parsed.hostname)\n ? `https://api.${host}`\n : `${origin}/api/v3`;\n const repositoryUrl = `${origin}/${repository}`;\n const apiRepo = `${apiBase}/repos/${repository}`;\n return {\n repository,\n repositoryUrl,\n apiRepo,\n number,\n sourceId: `${host}/${repository}/dependabot/${number}`,\n htmlUrl: `${repositoryUrl}/security/dependabot/${number}`,\n apiUrl: `${apiRepo}/dependabot/alerts/${number}`,\n };\n}\n\n// Normalized SDK evidence may link to either REST or the web UI.\nfunction alertUrlIdentity(url: unknown) {\n if (typeof url !== \"string\") return null;\n const web = webIdentity(url);\n if (web) return web;\n const api =\n /^(https?:\\/\\/)([^/?#@\\\\\\s]+)\\/(api\\/v3\\/)?repos\\/([^/]+\\/[^/]+)\\/dependabot\\/alerts\\/([1-9]\\d*)$/iu.exec(\n url,\n );\n if (!api) return null;\n const host = api[3] ? api[2] : api[2]!.replace(/^api\\./iu, \"\");\n const parsed = webIdentity(\n `${api[1]}${host}/${api[4]}/security/dependabot/${api[5]}`,\n );\n return parsed?.apiUrl === url.toLowerCase() ? parsed : null;\n}\n\nfunction checkSourceFamily(alert: Record<string, unknown>) {\n if (\n alert[\"source\"] === \"github-code-scanning\" ||\n alert[\"source\"] === \"github-security-advisory\"\n )\n throw new Error(\n \"Dependabot alert conflicts with its GitHub source family.\",\n );\n}\n\nfunction checkNativeClaims(\n alert: Record<string, unknown>,\n occurrence: NonNullable<ReturnType<typeof webIdentity>>,\n) {\n if (\"number\" in alert && alert[\"number\"] !== Number(occurrence.number))\n throw new Error(\n \"Dependabot alert number must match the repository alert URL.\",\n );\n if (\n (\"url\" in alert &&\n text(alert[\"url\"])?.toLowerCase() !== occurrence.apiUrl) ||\n (\"html_url\" in alert &&\n text(alert[\"html_url\"])?.toLowerCase() !== occurrence.htmlUrl)\n )\n throw new Error(\n \"Dependabot API url and html_url must identify the same host, repository and alert number.\",\n );\n if (\"repository\" in alert) {\n const declared = record(alert[\"repository\"], \"Dependabot repository\");\n if (\n text(declared[\"full_name\"])?.toLowerCase() !== occurrence.repository ||\n (\"html_url\" in declared &&\n text(declared[\"html_url\"])?.toLowerCase() !==\n occurrence.repositoryUrl) ||\n (\"url\" in declared &&\n text(declared[\"url\"])?.toLowerCase() !== occurrence.apiRepo)\n )\n throw new Error(\n \"Dependabot repository metadata conflicts with its alert URLs.\",\n );\n }\n}\n\nfunction identity(alert: Record<string, unknown>) {\n checkSourceFamily(alert);\n const number = alert[\"number\"];\n if (typeof number !== \"number\" || !Number.isSafeInteger(number) || number < 1)\n throw new Error(\"Dependabot alert number must be a positive safe integer.\");\n const url = requiredText(alert[\"html_url\"], \"Dependabot html_url\");\n const parsed = webIdentity(url);\n if (!parsed || parsed.number !== String(number))\n throw new Error(\n \"Dependabot html_url must identify the repository and alert number.\",\n );\n requiredText(alert[\"url\"], \"Dependabot API url\");\n checkNativeClaims(alert, parsed);\n return {\n repositoryUrl: parsed.repositoryUrl,\n sourceId: parsed.sourceId,\n url,\n };\n}\n\nexport function dependabotRepository({\n source_finding_id: id,\n evidence: { source_data: sourceData, url },\n}: ExternalFinding): string | undefined {\n const native = isGitHubDependabotAlert(sourceData) ? sourceData : null;\n const raw =\n native &&\n (alertUrlIdentity(native[\"html_url\"]) ?? alertUrlIdentity(native[\"url\"]));\n const projected = alertUrlIdentity(url);\n const occurrence = raw ?? projected;\n const structuredId =\n /^[^/]+\\/[^/]+\\/[^/]+\\/(?:dependabot|code-scanning|security-advisory)\\//u.test(\n id,\n );\n if (!occurrence) {\n if (/^[^/]+\\/[^/]+\\/[^/]+\\/dependabot\\/[1-9]\\d*$/u.test(id))\n throw new CodexSecurityError(\n \"The normalized Dependabot occurrence needs the original alert or its repository alert URL.\",\n );\n return;\n }\n if (isRecord(sourceData)) checkSourceFamily(sourceData);\n if (native) checkNativeClaims(native, occurrence);\n // A caller may have stored this occurrence under an opaque ID before native imports existed.\n if ((structuredId || id === \"\") && id !== occurrence.sourceId)\n throw new CodexSecurityError(\n \"The normalized source finding ID does not match the original Dependabot alert.\",\n );\n if (raw && projected && raw.htmlUrl !== projected.htmlUrl)\n throw new CodexSecurityError(\n \"The normalized alert URL does not match the original Dependabot alert.\",\n );\n return occurrence.repositoryUrl;\n}\n\nfunction selectedAlerts(input: unknown) {\n const selection = Array.isArray(input) ? input : [input];\n const hasPages = selection.some(Array.isArray);\n if (hasPages && !selection.every(Array.isArray))\n throw new Error(\n \"Dependabot input must not mix alert records and page arrays.\",\n );\n const rows: unknown[] = hasPages ? selection.flat() : selection;\n if (!rows.every(isGitHubDependabotAlert))\n throw new Error(\n \"Expected complete native Dependabot repository alerts, not mixed families, page shapes or API envelopes.\",\n );\n return rows;\n}\n\n// Parse only the matched vulnerability projection. Keep the complete upstream alert as evidence.\nconst nonblank = z.string().regex(/\\S/u);\nconst matchedVulnerability = z.object({\n package: z.object({ name: nonblank, ecosystem: nonblank }),\n vulnerable_version_range: nonblank,\n first_patched_version: z.object({ identifier: nonblank }).nullable(),\n severity: z.enum([\"critical\", \"high\", \"medium\", \"low\"]),\n});\n\nfunction evidence(alert: Record<string, unknown>, url: string) {\n const dependency = record(alert[\"dependency\"], \"Dependabot dependency\");\n const advisory = record(\n alert[\"security_advisory\"],\n \"Dependabot security_advisory\",\n );\n const {\n package: { name, ecosystem },\n vulnerable_version_range: range,\n first_patched_version: patch,\n severity,\n } = matchedVulnerability.parse(alert[\"security_vulnerability\"]);\n if (\"package\" in dependency) {\n const observed = record(\n dependency[\"package\"],\n \"Dependabot dependency package\",\n );\n if (observed[\"name\"] !== name || observed[\"ecosystem\"] !== ecosystem)\n throw new Error(\n \"Dependabot dependency and matched vulnerability packages disagree.\",\n );\n }\n const path = dependency[\"manifest_path\"] ?? null;\n if (path !== null) {\n const filename = relativePath(path)?.split(\"/\").at(-1);\n if (\n typeof path !== \"string\" ||\n /^[a-z][a-z\\d+.-]*:/iu.test(path) ||\n !filename ||\n filename === \".\"\n )\n throw new Error(\n \"Dependabot manifest_path must identify a repository-relative file.\",\n );\n }\n const ghsa = requiredText(advisory[\"ghsa_id\"], \"Dependabot GHSA ID\");\n if (!GHSA_ID.test(ghsa))\n throw new Error(\"Dependabot security_advisory must identify a GHSA.\");\n const affected = advisory[\"vulnerabilities\"];\n if (\n !Array.isArray(affected) ||\n !affected.some(\n (entry) =>\n isRecord(entry) &&\n isRecord(entry[\"package\"]) &&\n entry[\"package\"][\"name\"] === name &&\n entry[\"package\"][\"ecosystem\"] === ecosystem &&\n entry[\"vulnerable_version_range\"] === range,\n )\n )\n throw new Error(\n \"Dependabot advisory does not cover the matched package and vulnerable range.\",\n );\n const state = alert[\"state\"];\n if (\n typeof state !== \"string\" ||\n ![\"open\", \"dismissed\", \"auto_dismissed\", \"fixed\"].includes(state)\n )\n throw new Error(\n \"Dependabot alert state must be open, dismissed, auto_dismissed or fixed.\",\n );\n const updated =\n Date.parse(requiredText(alert[\"updated_at\"], \"Dependabot updated_at\")) /\n 1000;\n if (!Number.isFinite(updated) || updated < 0)\n throw new Error(\"Dependabot updated_at must be a valid timestamp.\");\n const advisoryIds = new Set([ghsa]);\n const cve = text(advisory[\"cve_id\"]);\n if (cve) advisoryIds.add(cve);\n const identifiers = advisory[\"identifiers\"];\n if (Array.isArray(identifiers)) {\n for (const item of identifiers) {\n const value = isRecord(item) && text(item[\"value\"]);\n if (!value) continue;\n if (\n (item[\"type\"] === \"GHSA\" || /^GHSA-/iu.test(value)) &&\n value.toUpperCase() !== ghsa.toUpperCase()\n )\n throw new Error(\n \"Dependabot advisory identifiers disagree on the GHSA.\",\n );\n advisoryIds.add(value);\n }\n }\n return {\n title: requiredText(advisory[\"summary\"], \"Dependabot advisory summary\"),\n description: text(advisory[\"description\"]),\n severity,\n url,\n advisory_ids: [...advisoryIds],\n packages: [\n {\n name,\n ecosystem,\n manifest_path: path,\n vulnerable_version_range: range,\n fixed_versions: patch ? [patch.identifier] : [],\n },\n ],\n locations: path ? [{ path }] : [],\n source_updated_at: Math.floor(updated),\n source_data: structuredClone(alert),\n };\n}\n\nexport function normalizeGitHubDependabotAlerts(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const alerts = selectedAlerts(input);\n const result: ExternalFindings = {\n read: alerts.length,\n findings: [],\n excluded: [],\n };\n const ids = new Set<string>();\n let sourceRepository: string | undefined;\n for (const [index, alert] of alerts.entries()) {\n const { repositoryUrl, sourceId, url } = identity(alert);\n if (sourceRepository !== undefined && sourceRepository !== repositoryUrl)\n throw new CodexSecurityError(\n \"Select Dependabot alerts from only one GitHub host and repository.\",\n );\n sourceRepository = repositoryUrl;\n if (ids.has(sourceId))\n throw new CodexSecurityError(\n `Duplicate source finding id ${JSON.stringify(sourceId)}. Select each Dependabot alert once.`,\n );\n ids.add(sourceId);\n const inputEvidence = evidence(alert, url);\n try {\n if (target === \"cloud\" && Buffer.byteLength(sourceId) > 512)\n throw new Error(\n \"Source finding ID exceeds the Cloud limit of 512 UTF-8 bytes.\",\n );\n result.findings.push({\n source_finding_id: sourceId,\n evidence: validateExternalEvidence(inputEvidence, target),\n });\n } catch (error) {\n result.excluded.push({\n position: index + 1,\n source_finding_id: sourceId,\n reason: errorMessage(error),\n });\n }\n }\n return result;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-findings.d.ts","sourceRoot":"","sources":["../src/github-findings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"github-findings.d.ts","sourceRoot":"","sources":["../src/github-findings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAK1E,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AA4SrE,uFAAuF;AACvF,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,SAAS,+BAA+B,EAAE,EAClD,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAElB;AAED,qFAAqF;AACrF,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,SAAS,sBAAsB,EAAE,EAC7C,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAElB;AAED,uFAAuF;AACvF,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,oBAA8B,GACrC,OAAO,CAAC,gBAAgB,CAAC,CAoB3B"}
|
package/dist/github-findings.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { hash } from "node:crypto";
|
|
2
|
+
import { GHSA_ID, githubRepositoryParts } from "./github-identifiers.js";
|
|
2
3
|
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
3
4
|
import { validateExternalEvidence } from "./external-import-contract.js";
|
|
5
|
+
import { isGitHubDependabotAlert, normalizeGitHubDependabotAlerts, } from "./github-dependabot-findings.js";
|
|
4
6
|
import { parseJsonOrJsonl, readScannerText, text } from "./scanner-import.js";
|
|
5
7
|
function object(value) {
|
|
6
8
|
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
@@ -9,8 +11,7 @@ function object(value) {
|
|
|
9
11
|
}
|
|
10
12
|
function repositoryName(value) {
|
|
11
13
|
const repository = text(value);
|
|
12
|
-
|
|
13
|
-
if (!parts || parts.slice(1).some((part) => /^\.{1,2}$/u.test(part)))
|
|
14
|
+
if (!repository || !githubRepositoryParts(repository))
|
|
14
15
|
throw new Error("GitHub repository must be OWNER/REPO.");
|
|
15
16
|
return repository;
|
|
16
17
|
}
|
|
@@ -117,7 +118,7 @@ function advisoryFinding(record, target = "cloud") {
|
|
|
117
118
|
const selection = record["selection"];
|
|
118
119
|
if (!advisory ||
|
|
119
120
|
!id ||
|
|
120
|
-
|
|
121
|
+
!GHSA_ID.test(id) ||
|
|
121
122
|
text(advisory["ghsa_id"])?.toUpperCase() !== id.toUpperCase())
|
|
122
123
|
throw new Error("Expected a GitHub advisory import with matching GHSA IDs.");
|
|
123
124
|
if (selection !== "repository" && selection !== "global")
|
|
@@ -249,7 +250,13 @@ export function normalizeGitHubAdvisories(advisories, target = "cloud") {
|
|
|
249
250
|
export async function readGitHubFindings(path, target = "cloud") {
|
|
250
251
|
try {
|
|
251
252
|
const payload = parseJsonOrJsonl(await readScannerText(path));
|
|
252
|
-
|
|
253
|
+
const rows = Array.isArray(payload) ? payload : [payload];
|
|
254
|
+
if ((rows.length > 0 && rows.every(Array.isArray)) ||
|
|
255
|
+
rows.some((row) => Array.isArray(row)
|
|
256
|
+
? row.some(isGitHubDependabotAlert)
|
|
257
|
+
: isGitHubDependabotAlert(row)))
|
|
258
|
+
return normalizeGitHubDependabotAlerts(payload, target);
|
|
259
|
+
return normalizeRecords(rows, target);
|
|
253
260
|
}
|
|
254
261
|
catch (cause) {
|
|
255
262
|
throw new CodexSecurityError(`Could not read GitHub findings as UTF-8 JSON or JSONL: ${errorMessage(cause)}`, { cause });
|