@cdxgen/cdxgen 0.0.1 → 13.0.1
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 +921 -87
- package/bin/audit.js +239 -0
- package/bin/cdxgen.js +2335 -0
- package/bin/convert.js +220 -0
- package/bin/evinse.js +353 -0
- package/bin/hbom.js +504 -0
- package/bin/repl.js +2224 -0
- package/bin/sign.js +195 -0
- package/bin/tracebom.js +303 -0
- package/bin/validate.js +268 -0
- package/bin/verify.js +189 -0
- package/data/README.md +307 -0
- package/data/bom-1.4.schema.json +1605 -0
- package/data/bom-1.5.schema.json +3660 -0
- package/data/bom-1.6.schema.json +5511 -0
- package/data/bom-1.7.schema.json +6700 -0
- package/data/cbomosdb-queries.json +68 -0
- package/data/component-tags.json +339 -0
- package/data/container-knowledge-index.json +125 -0
- package/data/cosdb-queries.json +17 -0
- package/data/crypto-oid.json +1998 -0
- package/data/cryptography-defs.json +3793 -0
- package/data/cryptography-defs.schema.json +576 -0
- package/data/cyclonedx-2.0-bundled.schema.json +7182 -0
- package/data/frameworks-list.json +219 -0
- package/data/glibc-stdlib.json +117 -0
- package/data/gtfobins-index.json +6296 -0
- package/data/helpers/init.gradle +71 -0
- package/data/jsf-0.82.schema.json +211 -0
- package/data/known-licenses.json +82 -0
- package/data/lic-mapping.json +338 -0
- package/data/license-aliases.json +6624 -0
- package/data/license-db.json +39059 -0
- package/data/license-deprecations.json +302 -0
- package/data/lolbas-index.json +150 -0
- package/data/predictive-audit-allowlist.json +11 -0
- package/data/pypi-pkg-aliases.json +1199 -0
- package/data/python-stdlib.json +308 -0
- package/data/queries-darwin.json +193 -0
- package/data/queries-win.json +257 -0
- package/data/queries.json +268 -0
- package/data/ruby-known-modules.json +281 -0
- package/data/rules/ai-agent-governance.yaml +323 -0
- package/data/rules/ai-bom.yaml +268 -0
- package/data/rules/ai-oversight.yaml +186 -0
- package/data/rules/ai-provenance.yaml +92 -0
- package/data/rules/asar-archives.yaml +150 -0
- package/data/rules/cbom-security.yaml +165 -0
- package/data/rules/chrome-extensions.yaml +248 -0
- package/data/rules/ci-permissions.yaml +802 -0
- package/data/rules/container-risk.yaml +353 -0
- package/data/rules/dependency-sources.yaml +236 -0
- package/data/rules/golem-go.yaml +229 -0
- package/data/rules/hbom-compliance.yaml +325 -0
- package/data/rules/hbom-performance.yaml +307 -0
- package/data/rules/hbom-security.yaml +248 -0
- package/data/rules/host-topology.yaml +165 -0
- package/data/rules/mcp-servers.yaml +388 -0
- package/data/rules/obom-runtime.yaml +1776 -0
- package/data/rules/package-integrity.yaml +364 -0
- package/data/rules/rootfs-hardening.yaml +179 -0
- package/data/rules/vscode-extensions.yaml +237 -0
- package/data/spdx-export.schema.json +6794 -0
- package/data/spdx-license-list.json +7449 -0
- package/data/spdx-licenses.json +759 -0
- package/data/spdx.schema.json +819 -0
- package/data/templates/README.md +3 -0
- package/data/templates/asvs-4.0.3.cdx.json +2943 -0
- package/data/templates/asvs-5.0.cdx.json +3046 -0
- package/data/templates/bsimm-v13.cdx.json +1008 -0
- package/data/templates/masvs-2.0.0.cdx.json +225 -0
- package/data/templates/nist-ssdf-1.1.cdx.json +828 -0
- package/data/templates/pcissc-secure-slc-1.1.cdx.json +1027 -0
- package/data/templates/scvs-1.0.0.cdx.json +813 -0
- package/data/templates/ssaf-DRAFT-2023-11.cdx.json +127 -0
- package/data/vendor-alias.json +41967 -0
- package/data/wrapdb-releases.json +4227 -0
- package/index.cjs +15 -0
- package/lib/audit/index.js +2800 -0
- package/lib/audit/progress.js +114 -0
- package/lib/audit/reporters.js +937 -0
- package/lib/audit/scoring.js +560 -0
- package/lib/audit/targets.js +798 -0
- package/lib/cli/bomAssembly.js +1882 -0
- package/lib/cli/cliOptions.js +543 -0
- package/lib/cli/index.js +2759 -0
- package/lib/cli/jsBom.js +2087 -0
- package/lib/cli/jvmBom.js +1858 -0
- package/lib/cli/managedBom.js +2083 -0
- package/lib/cli/nativeBom.js +2125 -0
- package/lib/core/activity.js +1087 -0
- package/lib/core/env.js +719 -0
- package/lib/core/fs.js +1058 -0
- package/lib/core/httpClient.js +730 -0
- package/lib/core/logger.js +280 -0
- package/lib/core/parallel.js +323 -0
- package/lib/core/paths.js +70 -0
- package/lib/core/projectConfig.js +122 -0
- package/lib/core/propertySanitizer.js +174 -0
- package/lib/core/spdx.js +5 -0
- package/lib/core/state.js +59 -0
- package/lib/core/text.js +207 -0
- package/lib/core/ui.js +920 -0
- package/lib/core/urls.js +84 -0
- package/lib/ecosystems/asarutils.js +1636 -0
- package/lib/ecosystems/bunutils.js +402 -0
- package/lib/ecosystems/caxa.js +77 -0
- package/lib/ecosystems/chromextutils.js +1174 -0
- package/lib/ecosystems/cmakeResolver.js +587 -0
- package/lib/ecosystems/cppEvidence.js +305 -0
- package/lib/ecosystems/denoutils.js +1094 -0
- package/lib/ecosystems/dotnetutils.js +132 -0
- package/lib/ecosystems/ecosystems.js +2772 -0
- package/lib/ecosystems/golem.js +1807 -0
- package/lib/ecosystems/gradleutils.js +1048 -0
- package/lib/ecosystems/jsEvidence.js +317 -0
- package/lib/ecosystems/npmutils.js +586 -0
- package/lib/ecosystems/parsers-bazel.js +875 -0
- package/lib/ecosystems/parsers-dotnet.js +1430 -0
- package/lib/ecosystems/parsers-gleam.js +302 -0
- package/lib/ecosystems/parsers-go.js +818 -0
- package/lib/ecosystems/parsers-js.js +4222 -0
- package/lib/ecosystems/parsers-jvm.js +948 -0
- package/lib/ecosystems/parsers-misc.js +3191 -0
- package/lib/ecosystems/parsers-python.js +2070 -0
- package/lib/ecosystems/parsers-rust.js +1294 -0
- package/lib/ecosystems/parsers-zig.js +861 -0
- package/lib/ecosystems/pep770.js +341 -0
- package/lib/ecosystems/pylockutils.js +427 -0
- package/lib/ecosystems/pythonutils.js +1281 -0
- package/lib/ecosystems/registryProvenance.js +1003 -0
- package/lib/ecosystems/remote/huggingface.js +1343 -0
- package/lib/ecosystems/rubyutils.js +1629 -0
- package/lib/ecosystems/rusi.js +820 -0
- package/lib/ecosystems/sbtutils.js +972 -0
- package/lib/ecosystems/tea.js +607 -0
- package/lib/ecosystems/utils.js +583 -0
- package/lib/ecosystems/zigResolver.js +410 -0
- package/lib/evinser/db.js +145 -0
- package/lib/evinser/evinser.js +2362 -0
- package/lib/evinser/scalasem.js +65 -0
- package/lib/evinser/swiftsem.js +767 -0
- package/lib/helpers/annotationFormatter.js +84 -0
- package/lib/helpers/bomSigner.js +312 -0
- package/lib/helpers/exportUtils.js +160 -0
- package/lib/helpers/remote/dependency-track.js +117 -0
- package/lib/helpers/versutils.js +202 -0
- package/lib/helpers/vsixutils.js +1069 -0
- package/lib/inventory/agentFormulationParser.js +322 -0
- package/lib/inventory/aiCollector.js +2140 -0
- package/lib/inventory/aiInventory.js +414 -0
- package/lib/inventory/aiModelVariants.js +121 -0
- package/lib/inventory/aiOversightCollector.js +661 -0
- package/lib/inventory/aiProvenanceCollector.js +822 -0
- package/lib/inventory/analyzer.js +6089 -0
- package/lib/inventory/analyzerScope.js +807 -0
- package/lib/inventory/astWorker.js +20 -0
- package/lib/inventory/atomUtils.js +1092 -0
- package/lib/inventory/auditCategories.js +192 -0
- package/lib/inventory/bomUtils.js +369 -0
- package/lib/inventory/cacheCommands.js +182 -0
- package/lib/inventory/cacheDir.js +104 -0
- package/lib/inventory/cbomutils.js +590 -0
- package/lib/inventory/cdxrs.js +434 -0
- package/lib/inventory/ciParsers/azurePipelines.js +295 -0
- package/lib/inventory/ciParsers/circleCi.js +286 -0
- package/lib/inventory/ciParsers/common.js +24 -0
- package/lib/inventory/ciParsers/githubActions.js +2434 -0
- package/lib/inventory/ciParsers/gitlabCi.js +213 -0
- package/lib/inventory/ciParsers/jenkins.js +180 -0
- package/lib/inventory/citations.js +234 -0
- package/lib/inventory/communityAiConfigParser.js +756 -0
- package/lib/inventory/containerRisk.js +204 -0
- package/lib/inventory/cryptoAlgorithmFamily.js +258 -0
- package/lib/inventory/deps.js +807 -0
- package/lib/inventory/depsUtils.js +588 -0
- package/lib/inventory/display.js +2128 -0
- package/lib/inventory/dosai.js +601 -0
- package/lib/inventory/dosaiParsers.js +154 -0
- package/lib/inventory/dynamic.js +145 -0
- package/lib/inventory/envcontext.js +1793 -0
- package/lib/inventory/evidenceUtils.js +774 -0
- package/lib/inventory/fetchBatch.js +779 -0
- package/lib/inventory/fetchRate.js +255 -0
- package/lib/inventory/forgeEnricher.js +300 -0
- package/lib/inventory/formulationParsers.js +422 -0
- package/lib/inventory/gtfobins.js +339 -0
- package/lib/inventory/hbom.js +719 -0
- package/lib/inventory/hbomAnalysis.js +310 -0
- package/lib/inventory/hbomLoader.js +35 -0
- package/lib/inventory/hostTopology.js +835 -0
- package/lib/inventory/inventoryStats.js +100 -0
- package/lib/inventory/jsonLike.js +121 -0
- package/lib/inventory/licenseEnhancer.js +918 -0
- package/lib/inventory/lolbas.js +285 -0
- package/lib/inventory/mcp.js +253 -0
- package/lib/inventory/mcpConfigParser.js +683 -0
- package/lib/inventory/mcpDiscovery.js +112 -0
- package/lib/inventory/mcpPinning.js +209 -0
- package/lib/inventory/osPackageResolver.js +493 -0
- package/lib/inventory/osinfo.js +383 -0
- package/lib/inventory/osqueryTransform.js +274 -0
- package/lib/inventory/plugins.js +466 -0
- package/lib/inventory/protobom.js +231 -0
- package/lib/inventory/protobomLoader.js +43 -0
- package/lib/inventory/provenanceUtils.js +224 -0
- package/lib/inventory/purl.js +749 -0
- package/lib/inventory/rustFormulationParser.js +339 -0
- package/lib/inventory/sbomDocument.js +340 -0
- package/lib/inventory/source.js +1488 -0
- package/lib/inventory/spdx.js +361 -0
- package/lib/inventory/spdxExpression.js +512 -0
- package/lib/inventory/spdxUtils.js +107 -0
- package/lib/inventory/table.js +267 -0
- package/lib/inventory/traceRunner.js +439 -0
- package/lib/inventory/unicodeScan.js +147 -0
- package/lib/managers/binary.js +3459 -0
- package/lib/managers/containerutils.js +125 -0
- package/lib/managers/docker.js +2145 -0
- package/lib/managers/dockerConnection.js +162 -0
- package/lib/managers/oci.js +704 -0
- package/lib/managers/piptree.js +267 -0
- package/lib/parsers/cmakeCache.js +199 -0
- package/lib/parsers/gguf.js +492 -0
- package/lib/parsers/gitAiNotes.js +233 -0
- package/lib/parsers/gitmodules.js +239 -0
- package/lib/parsers/htmlExtract.js +610 -0
- package/lib/parsers/huggingfaceManifest.js +551 -0
- package/lib/parsers/huggingfaceUtils.js +506 -0
- package/lib/parsers/iri.js +618 -0
- package/lib/parsers/npmrc.js +99 -0
- package/lib/parsers/ollama.js +101 -0
- package/lib/parsers/xml.js +841 -0
- package/lib/server/openapi.yaml +433 -0
- package/lib/server/server.js +616 -0
- package/lib/stages/postgen/annotator.js +977 -0
- package/lib/stages/postgen/auditBom.js +468 -0
- package/lib/stages/postgen/postgen.js +1239 -0
- package/lib/stages/postgen/ruleEngine.js +731 -0
- package/lib/stages/postgen/sortBom.js +195 -0
- package/lib/stages/postgen/spdxConverter.js +796 -0
- package/lib/stages/postgen/specVersionCompat.js +703 -0
- package/lib/stages/pregen/envAudit.js +388 -0
- package/lib/stages/pregen/pregen.js +637 -0
- package/lib/third-party/README.md +9 -0
- package/lib/third-party/arborist/CHANGELOG.md +1109 -0
- package/lib/third-party/arborist/LICENSE.md +20 -0
- package/lib/third-party/arborist/README.md +315 -0
- package/lib/third-party/arborist/lib/arborist/index.js +258 -0
- package/lib/third-party/arborist/lib/arborist/load-actual.js +605 -0
- package/lib/third-party/arborist/lib/arborist/load-virtual.js +300 -0
- package/lib/third-party/arborist/lib/bin-links.js +120 -0
- package/lib/third-party/arborist/lib/calc-dep-flags.js +130 -0
- package/lib/third-party/arborist/lib/case-insensitive-map.js +51 -0
- package/lib/third-party/arborist/lib/consistent-resolve.js +42 -0
- package/lib/third-party/arborist/lib/debug.js +50 -0
- package/lib/third-party/arborist/lib/dep-valid.js +190 -0
- package/lib/third-party/arborist/lib/edge.js +417 -0
- package/lib/third-party/arborist/lib/from-path.js +36 -0
- package/lib/third-party/arborist/lib/gather-dep-set.js +43 -0
- package/lib/third-party/arborist/lib/index.js +22 -0
- package/lib/third-party/arborist/lib/inventory.js +138 -0
- package/lib/third-party/arborist/lib/link.js +169 -0
- package/lib/third-party/arborist/lib/node.js +1673 -0
- package/lib/third-party/arborist/lib/npm-extension.js +45 -0
- package/lib/third-party/arborist/lib/override-resolves.js +11 -0
- package/lib/third-party/arborist/lib/override-set.js +319 -0
- package/lib/third-party/arborist/lib/package-extensions.js +289 -0
- package/lib/third-party/arborist/lib/printable.js +210 -0
- package/lib/third-party/arborist/lib/proc-log.js +30 -0
- package/lib/third-party/arborist/lib/realpath.js +100 -0
- package/lib/third-party/arborist/lib/relpath.js +4 -0
- package/lib/third-party/arborist/lib/shrinkwrap.js +1291 -0
- package/lib/third-party/arborist/lib/spec-from-lock.js +34 -0
- package/lib/third-party/arborist/lib/tree-check.js +165 -0
- package/lib/third-party/arborist/lib/validate-npm-package-name.js +107 -0
- package/lib/third-party/arborist/lib/version-from-tgz.js +51 -0
- package/lib/third-party/arborist/lib/yarn-lock.js +397 -0
- package/lib/validator/bomValidator.js +985 -0
- package/lib/validator/complianceEngine.js +241 -0
- package/lib/validator/complianceRules.js +1680 -0
- package/lib/validator/generated/runtime.mjs +17 -0
- package/lib/validator/generated/validate-1.6.mjs +21258 -0
- package/lib/validator/generated/validate-1.7.mjs +24803 -0
- package/lib/validator/generated/validate-2.0.mjs +22931 -0
- package/lib/validator/index.js +246 -0
- package/lib/validator/reporters/annotations.js +142 -0
- package/lib/validator/reporters/console.js +160 -0
- package/lib/validator/reporters/index.js +41 -0
- package/lib/validator/reporters/json.js +37 -0
- package/lib/validator/reporters/sarif.js +184 -0
- package/package.json +209 -26
- package/types/bin/audit.d.ts +3 -0
- package/types/bin/audit.d.ts.map +1 -0
- package/types/bin/cdxgen.d.ts +3 -0
- package/types/bin/cdxgen.d.ts.map +1 -0
- package/types/bin/convert.d.ts +3 -0
- package/types/bin/convert.d.ts.map +1 -0
- package/types/bin/evinse.d.ts +3 -0
- package/types/bin/evinse.d.ts.map +1 -0
- package/types/bin/hbom.d.ts +3 -0
- package/types/bin/hbom.d.ts.map +1 -0
- package/types/bin/repl.d.ts +3 -0
- package/types/bin/repl.d.ts.map +1 -0
- package/types/bin/sign.d.ts +3 -0
- package/types/bin/sign.d.ts.map +1 -0
- package/types/bin/tracebom.d.ts +3 -0
- package/types/bin/tracebom.d.ts.map +1 -0
- package/types/bin/validate.d.ts +14 -0
- package/types/bin/validate.d.ts.map +1 -0
- package/types/bin/verify.d.ts +3 -0
- package/types/bin/verify.d.ts.map +1 -0
- package/types/lib/audit/index.d.ts +153 -0
- package/types/lib/audit/index.d.ts.map +1 -0
- package/types/lib/audit/progress.d.ts +31 -0
- package/types/lib/audit/progress.d.ts.map +1 -0
- package/types/lib/audit/reporters.d.ts +62 -0
- package/types/lib/audit/reporters.d.ts.map +1 -0
- package/types/lib/audit/scoring.d.ts +36 -0
- package/types/lib/audit/scoring.d.ts.map +1 -0
- package/types/lib/audit/targets.d.ts +77 -0
- package/types/lib/audit/targets.d.ts.map +1 -0
- package/types/lib/cli/bomAssembly.d.ts +329 -0
- package/types/lib/cli/bomAssembly.d.ts.map +1 -0
- package/types/lib/cli/cliOptions.d.ts +156 -0
- package/types/lib/cli/cliOptions.d.ts.map +1 -0
- package/types/lib/cli/index.d.ts +107 -0
- package/types/lib/cli/index.d.ts.map +1 -0
- package/types/lib/cli/jsBom.d.ts +94 -0
- package/types/lib/cli/jsBom.d.ts.map +1 -0
- package/types/lib/cli/jvmBom.d.ts +54 -0
- package/types/lib/cli/jvmBom.d.ts.map +1 -0
- package/types/lib/cli/managedBom.d.ts +105 -0
- package/types/lib/cli/managedBom.d.ts.map +1 -0
- package/types/lib/cli/nativeBom.d.ts +143 -0
- package/types/lib/cli/nativeBom.d.ts.map +1 -0
- package/types/lib/core/activity.d.ts +178 -0
- package/types/lib/core/activity.d.ts.map +1 -0
- package/types/lib/core/env.d.ts +192 -0
- package/types/lib/core/env.d.ts.map +1 -0
- package/types/lib/core/fs.d.ts +158 -0
- package/types/lib/core/fs.d.ts.map +1 -0
- package/types/lib/core/httpClient.d.ts +149 -0
- package/types/lib/core/httpClient.d.ts.map +1 -0
- package/types/lib/core/logger.d.ts +50 -0
- package/types/lib/core/logger.d.ts.map +1 -0
- package/types/lib/core/parallel.d.ts +95 -0
- package/types/lib/core/parallel.d.ts.map +1 -0
- package/types/lib/core/paths.d.ts +36 -0
- package/types/lib/core/paths.d.ts.map +1 -0
- package/types/lib/core/projectConfig.d.ts +23 -0
- package/types/lib/core/projectConfig.d.ts.map +1 -0
- package/types/lib/core/propertySanitizer.d.ts +23 -0
- package/types/lib/core/propertySanitizer.d.ts.map +1 -0
- package/types/lib/core/spdx.d.ts +5 -0
- package/types/lib/core/spdx.d.ts.map +1 -0
- package/types/lib/core/state.d.ts +20 -0
- package/types/lib/core/state.d.ts.map +1 -0
- package/types/lib/core/text.d.ts +78 -0
- package/types/lib/core/text.d.ts.map +1 -0
- package/types/lib/core/ui.d.ts +87 -0
- package/types/lib/core/ui.d.ts.map +1 -0
- package/types/lib/core/urls.d.ts +43 -0
- package/types/lib/core/urls.d.ts.map +1 -0
- package/types/lib/ecosystems/asarutils.d.ts +71 -0
- package/types/lib/ecosystems/asarutils.d.ts.map +1 -0
- package/types/lib/ecosystems/bunutils.d.ts +38 -0
- package/types/lib/ecosystems/bunutils.d.ts.map +1 -0
- package/types/lib/ecosystems/caxa.d.ts +8 -0
- package/types/lib/ecosystems/caxa.d.ts.map +1 -0
- package/types/lib/ecosystems/chromextutils.d.ts +97 -0
- package/types/lib/ecosystems/chromextutils.d.ts.map +1 -0
- package/types/lib/ecosystems/cmakeResolver.d.ts +176 -0
- package/types/lib/ecosystems/cmakeResolver.d.ts.map +1 -0
- package/types/lib/ecosystems/cppEvidence.d.ts +35 -0
- package/types/lib/ecosystems/cppEvidence.d.ts.map +1 -0
- package/types/lib/ecosystems/denoutils.d.ts +76 -0
- package/types/lib/ecosystems/denoutils.d.ts.map +1 -0
- package/types/lib/ecosystems/dotnetutils.d.ts +45 -0
- package/types/lib/ecosystems/dotnetutils.d.ts.map +1 -0
- package/types/lib/ecosystems/ecosystems.d.ts +279 -0
- package/types/lib/ecosystems/ecosystems.d.ts.map +1 -0
- package/types/lib/ecosystems/golem.d.ts +60 -0
- package/types/lib/ecosystems/golem.d.ts.map +1 -0
- package/types/lib/ecosystems/gradleutils.d.ts +139 -0
- package/types/lib/ecosystems/gradleutils.d.ts.map +1 -0
- package/types/lib/ecosystems/jsEvidence.d.ts +17 -0
- package/types/lib/ecosystems/jsEvidence.d.ts.map +1 -0
- package/types/lib/ecosystems/npmutils.d.ts +183 -0
- package/types/lib/ecosystems/npmutils.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-bazel.d.ts +36 -0
- package/types/lib/ecosystems/parsers-bazel.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-dotnet.d.ts +116 -0
- package/types/lib/ecosystems/parsers-dotnet.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-gleam.d.ts +33 -0
- package/types/lib/ecosystems/parsers-gleam.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-go.d.ts +92 -0
- package/types/lib/ecosystems/parsers-go.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-js.d.ts +242 -0
- package/types/lib/ecosystems/parsers-js.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-jvm.d.ts +100 -0
- package/types/lib/ecosystems/parsers-jvm.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-misc.d.ts +450 -0
- package/types/lib/ecosystems/parsers-misc.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-python.d.ts +145 -0
- package/types/lib/ecosystems/parsers-python.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-rust.d.ts +56 -0
- package/types/lib/ecosystems/parsers-rust.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-zig.d.ts +83 -0
- package/types/lib/ecosystems/parsers-zig.d.ts.map +1 -0
- package/types/lib/ecosystems/pep770.d.ts +38 -0
- package/types/lib/ecosystems/pep770.d.ts.map +1 -0
- package/types/lib/ecosystems/pylockutils.d.ts +68 -0
- package/types/lib/ecosystems/pylockutils.d.ts.map +1 -0
- package/types/lib/ecosystems/pythonutils.d.ts +70 -0
- package/types/lib/ecosystems/pythonutils.d.ts.map +1 -0
- package/types/lib/ecosystems/registryProvenance.d.ts +26 -0
- package/types/lib/ecosystems/registryProvenance.d.ts.map +1 -0
- package/types/lib/ecosystems/remote/huggingface.d.ts +31 -0
- package/types/lib/ecosystems/remote/huggingface.d.ts.map +1 -0
- package/types/lib/ecosystems/rubyutils.d.ts +182 -0
- package/types/lib/ecosystems/rubyutils.d.ts.map +1 -0
- package/types/lib/ecosystems/rusi.d.ts +40 -0
- package/types/lib/ecosystems/rusi.d.ts.map +1 -0
- package/types/lib/ecosystems/sbtutils.d.ts +179 -0
- package/types/lib/ecosystems/sbtutils.d.ts.map +1 -0
- package/types/lib/ecosystems/tea.d.ts +180 -0
- package/types/lib/ecosystems/tea.d.ts.map +1 -0
- package/types/lib/ecosystems/utils.d.ts +41 -0
- package/types/lib/ecosystems/utils.d.ts.map +1 -0
- package/types/lib/ecosystems/zigResolver.d.ts +70 -0
- package/types/lib/ecosystems/zigResolver.d.ts.map +1 -0
- package/types/lib/evinser/db.d.ts +17 -0
- package/types/lib/evinser/db.d.ts.map +1 -0
- package/types/lib/evinser/evinser.d.ts +354 -0
- package/types/lib/evinser/evinser.d.ts.map +1 -0
- package/types/lib/evinser/scalasem.d.ts +15 -0
- package/types/lib/evinser/scalasem.d.ts.map +1 -0
- package/types/lib/evinser/swiftsem.d.ts +103 -0
- package/types/lib/evinser/swiftsem.d.ts.map +1 -0
- package/types/lib/helpers/annotationFormatter.d.ts +23 -0
- package/types/lib/helpers/annotationFormatter.d.ts.map +1 -0
- package/types/lib/helpers/bomSigner.d.ts +28 -0
- package/types/lib/helpers/bomSigner.d.ts.map +1 -0
- package/types/lib/helpers/exportUtils.d.ts +52 -0
- package/types/lib/helpers/exportUtils.d.ts.map +1 -0
- package/types/lib/helpers/remote/dependency-track.d.ts +23 -0
- package/types/lib/helpers/remote/dependency-track.d.ts.map +1 -0
- package/types/lib/helpers/versutils.d.ts +8 -0
- package/types/lib/helpers/versutils.d.ts.map +1 -0
- package/types/lib/helpers/vsixutils.d.ts +130 -0
- package/types/lib/helpers/vsixutils.d.ts.map +1 -0
- package/types/lib/inventory/agentFormulationParser.d.ts +21 -0
- package/types/lib/inventory/agentFormulationParser.d.ts.map +1 -0
- package/types/lib/inventory/aiCollector.d.ts +61 -0
- package/types/lib/inventory/aiCollector.d.ts.map +1 -0
- package/types/lib/inventory/aiInventory.d.ts +103 -0
- package/types/lib/inventory/aiInventory.d.ts.map +1 -0
- package/types/lib/inventory/aiModelVariants.d.ts +31 -0
- package/types/lib/inventory/aiModelVariants.d.ts.map +1 -0
- package/types/lib/inventory/aiOversightCollector.d.ts +28 -0
- package/types/lib/inventory/aiOversightCollector.d.ts.map +1 -0
- package/types/lib/inventory/aiProvenanceCollector.d.ts +13 -0
- package/types/lib/inventory/aiProvenanceCollector.d.ts.map +1 -0
- package/types/lib/inventory/analyzer.d.ts +157 -0
- package/types/lib/inventory/analyzer.d.ts.map +1 -0
- package/types/lib/inventory/analyzerScope.d.ts +106 -0
- package/types/lib/inventory/analyzerScope.d.ts.map +1 -0
- package/types/lib/inventory/astWorker.d.ts +9 -0
- package/types/lib/inventory/astWorker.d.ts.map +1 -0
- package/types/lib/inventory/atomUtils.d.ts +159 -0
- package/types/lib/inventory/atomUtils.d.ts.map +1 -0
- package/types/lib/inventory/auditCategories.d.ts +80 -0
- package/types/lib/inventory/auditCategories.d.ts.map +1 -0
- package/types/lib/inventory/bomUtils.d.ts +145 -0
- package/types/lib/inventory/bomUtils.d.ts.map +1 -0
- package/types/lib/inventory/cacheCommands.d.ts +28 -0
- package/types/lib/inventory/cacheCommands.d.ts.map +1 -0
- package/types/lib/inventory/cacheDir.d.ts +55 -0
- package/types/lib/inventory/cacheDir.d.ts.map +1 -0
- package/types/lib/inventory/cbomutils.d.ts +37 -0
- package/types/lib/inventory/cbomutils.d.ts.map +1 -0
- package/types/lib/inventory/cdxrs.d.ts +90 -0
- package/types/lib/inventory/cdxrs.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/azurePipelines.d.ts +27 -0
- package/types/lib/inventory/ciParsers/azurePipelines.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/circleCi.d.ts +27 -0
- package/types/lib/inventory/ciParsers/circleCi.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/common.d.ts +11 -0
- package/types/lib/inventory/ciParsers/common.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/githubActions.d.ts +38 -0
- package/types/lib/inventory/ciParsers/githubActions.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/gitlabCi.d.ts +26 -0
- package/types/lib/inventory/ciParsers/gitlabCi.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/jenkins.d.ts +26 -0
- package/types/lib/inventory/ciParsers/jenkins.d.ts.map +1 -0
- package/types/lib/inventory/citations.d.ts +90 -0
- package/types/lib/inventory/citations.d.ts.map +1 -0
- package/types/lib/inventory/communityAiConfigParser.d.ts +14 -0
- package/types/lib/inventory/communityAiConfigParser.d.ts.map +1 -0
- package/types/lib/inventory/containerRisk.d.ts +20 -0
- package/types/lib/inventory/containerRisk.d.ts.map +1 -0
- package/types/lib/inventory/cryptoAlgorithmFamily.d.ts +37 -0
- package/types/lib/inventory/cryptoAlgorithmFamily.d.ts.map +1 -0
- package/types/lib/inventory/deps.d.ts +140 -0
- package/types/lib/inventory/deps.d.ts.map +1 -0
- package/types/lib/inventory/depsUtils.d.ts +74 -0
- package/types/lib/inventory/depsUtils.d.ts.map +1 -0
- package/types/lib/inventory/display.d.ts +227 -0
- package/types/lib/inventory/display.d.ts.map +1 -0
- package/types/lib/inventory/dosai.d.ts +130 -0
- package/types/lib/inventory/dosai.d.ts.map +1 -0
- package/types/lib/inventory/dosaiParsers.d.ts +59 -0
- package/types/lib/inventory/dosaiParsers.d.ts.map +1 -0
- package/types/lib/inventory/dynamic.d.ts +25 -0
- package/types/lib/inventory/dynamic.d.ts.map +1 -0
- package/types/lib/inventory/envcontext.d.ts +377 -0
- package/types/lib/inventory/envcontext.d.ts.map +1 -0
- package/types/lib/inventory/evidenceUtils.d.ts +74 -0
- package/types/lib/inventory/evidenceUtils.d.ts.map +1 -0
- package/types/lib/inventory/fetchBatch.d.ts +127 -0
- package/types/lib/inventory/fetchBatch.d.ts.map +1 -0
- package/types/lib/inventory/fetchRate.d.ts +118 -0
- package/types/lib/inventory/fetchRate.d.ts.map +1 -0
- package/types/lib/inventory/forgeEnricher.d.ts +31 -0
- package/types/lib/inventory/forgeEnricher.d.ts.map +1 -0
- package/types/lib/inventory/formulationParsers.d.ts +50 -0
- package/types/lib/inventory/formulationParsers.d.ts.map +1 -0
- package/types/lib/inventory/gtfobins.d.ts +27 -0
- package/types/lib/inventory/gtfobins.d.ts.map +1 -0
- package/types/lib/inventory/hbom.d.ts +58 -0
- package/types/lib/inventory/hbom.d.ts.map +1 -0
- package/types/lib/inventory/hbomAnalysis.d.ts +56 -0
- package/types/lib/inventory/hbomAnalysis.d.ts.map +1 -0
- package/types/lib/inventory/hbomLoader.d.ts +7 -0
- package/types/lib/inventory/hbomLoader.d.ts.map +1 -0
- package/types/lib/inventory/hostTopology.d.ts +47 -0
- package/types/lib/inventory/hostTopology.d.ts.map +1 -0
- package/types/lib/inventory/inventoryStats.d.ts +42 -0
- package/types/lib/inventory/inventoryStats.d.ts.map +1 -0
- package/types/lib/inventory/jsonLike.d.ts +23 -0
- package/types/lib/inventory/jsonLike.d.ts.map +1 -0
- package/types/lib/inventory/licenseEnhancer.d.ts +70 -0
- package/types/lib/inventory/licenseEnhancer.d.ts.map +1 -0
- package/types/lib/inventory/lolbas.d.ts +16 -0
- package/types/lib/inventory/lolbas.d.ts.map +1 -0
- package/types/lib/inventory/mcp.d.ts +29 -0
- package/types/lib/inventory/mcp.d.ts.map +1 -0
- package/types/lib/inventory/mcpConfigParser.d.ts +20 -0
- package/types/lib/inventory/mcpConfigParser.d.ts.map +1 -0
- package/types/lib/inventory/mcpDiscovery.d.ts +33 -0
- package/types/lib/inventory/mcpDiscovery.d.ts.map +1 -0
- package/types/lib/inventory/mcpPinning.d.ts +11 -0
- package/types/lib/inventory/mcpPinning.d.ts.map +1 -0
- package/types/lib/inventory/osPackageResolver.d.ts +49 -0
- package/types/lib/inventory/osPackageResolver.d.ts.map +1 -0
- package/types/lib/inventory/osinfo.d.ts +201 -0
- package/types/lib/inventory/osinfo.d.ts.map +1 -0
- package/types/lib/inventory/osqueryTransform.d.ts +84 -0
- package/types/lib/inventory/osqueryTransform.d.ts.map +1 -0
- package/types/lib/inventory/plugins.d.ts +58 -0
- package/types/lib/inventory/plugins.d.ts.map +1 -0
- package/types/lib/inventory/protobom.d.ts +71 -0
- package/types/lib/inventory/protobom.d.ts.map +1 -0
- package/types/lib/inventory/protobomLoader.d.ts +17 -0
- package/types/lib/inventory/protobomLoader.d.ts.map +1 -0
- package/types/lib/inventory/provenanceUtils.d.ts +98 -0
- package/types/lib/inventory/provenanceUtils.d.ts.map +1 -0
- package/types/lib/inventory/purl.d.ts +313 -0
- package/types/lib/inventory/purl.d.ts.map +1 -0
- package/types/lib/inventory/rustFormulationParser.d.ts +17 -0
- package/types/lib/inventory/rustFormulationParser.d.ts.map +1 -0
- package/types/lib/inventory/sbomDocument.d.ts +59 -0
- package/types/lib/inventory/sbomDocument.d.ts.map +1 -0
- package/types/lib/inventory/source.d.ts +163 -0
- package/types/lib/inventory/source.d.ts.map +1 -0
- package/types/lib/inventory/spdx.d.ts +66 -0
- package/types/lib/inventory/spdx.d.ts.map +1 -0
- package/types/lib/inventory/spdxExpression.d.ts +58 -0
- package/types/lib/inventory/spdxExpression.d.ts.map +1 -0
- package/types/lib/inventory/spdxUtils.d.ts +12 -0
- package/types/lib/inventory/spdxUtils.d.ts.map +1 -0
- package/types/lib/inventory/table.d.ts +22 -0
- package/types/lib/inventory/table.d.ts.map +1 -0
- package/types/lib/inventory/traceRunner.d.ts +80 -0
- package/types/lib/inventory/traceRunner.d.ts.map +1 -0
- package/types/lib/inventory/unicodeScan.d.ts +46 -0
- package/types/lib/inventory/unicodeScan.d.ts.map +1 -0
- package/types/lib/managers/binary.d.ts +147 -0
- package/types/lib/managers/binary.d.ts.map +1 -0
- package/types/lib/managers/containerutils.d.ts +30 -0
- package/types/lib/managers/containerutils.d.ts.map +1 -0
- package/types/lib/managers/docker.d.ts +157 -0
- package/types/lib/managers/docker.d.ts.map +1 -0
- package/types/lib/managers/dockerConnection.d.ts +42 -0
- package/types/lib/managers/dockerConnection.d.ts.map +1 -0
- package/types/lib/managers/oci.d.ts +21 -0
- package/types/lib/managers/oci.d.ts.map +1 -0
- package/types/lib/managers/piptree.d.ts +13 -0
- package/types/lib/managers/piptree.d.ts.map +1 -0
- package/types/lib/parsers/cmakeCache.d.ts +70 -0
- package/types/lib/parsers/cmakeCache.d.ts.map +1 -0
- package/types/lib/parsers/gguf.d.ts +39 -0
- package/types/lib/parsers/gguf.d.ts.map +1 -0
- package/types/lib/parsers/gitAiNotes.d.ts +15 -0
- package/types/lib/parsers/gitAiNotes.d.ts.map +1 -0
- package/types/lib/parsers/gitmodules.d.ts +88 -0
- package/types/lib/parsers/gitmodules.d.ts.map +1 -0
- package/types/lib/parsers/htmlExtract.d.ts +34 -0
- package/types/lib/parsers/htmlExtract.d.ts.map +1 -0
- package/types/lib/parsers/huggingfaceManifest.d.ts +153 -0
- package/types/lib/parsers/huggingfaceManifest.d.ts.map +1 -0
- package/types/lib/parsers/huggingfaceUtils.d.ts +155 -0
- package/types/lib/parsers/huggingfaceUtils.d.ts.map +1 -0
- package/types/lib/parsers/iri.d.ts +68 -0
- package/types/lib/parsers/iri.d.ts.map +1 -0
- package/types/lib/parsers/npmrc.d.ts +33 -0
- package/types/lib/parsers/npmrc.d.ts.map +1 -0
- package/types/lib/parsers/ollama.d.ts +22 -0
- package/types/lib/parsers/ollama.d.ts.map +1 -0
- package/types/lib/parsers/xml.d.ts +47 -0
- package/types/lib/parsers/xml.d.ts.map +1 -0
- package/types/lib/server/server.d.ts +51 -0
- package/types/lib/server/server.d.ts.map +1 -0
- package/types/lib/stages/postgen/annotator.d.ts +36 -0
- package/types/lib/stages/postgen/annotator.d.ts.map +1 -0
- package/types/lib/stages/postgen/auditBom.d.ts +92 -0
- package/types/lib/stages/postgen/auditBom.d.ts.map +1 -0
- package/types/lib/stages/postgen/postgen.d.ts +59 -0
- package/types/lib/stages/postgen/postgen.d.ts.map +1 -0
- package/types/lib/stages/postgen/ruleEngine.d.ts +18 -0
- package/types/lib/stages/postgen/ruleEngine.d.ts.map +1 -0
- package/types/lib/stages/postgen/sortBom.d.ts +34 -0
- package/types/lib/stages/postgen/sortBom.d.ts.map +1 -0
- package/types/lib/stages/postgen/spdxConverter.d.ts +11 -0
- package/types/lib/stages/postgen/spdxConverter.d.ts.map +1 -0
- package/types/lib/stages/postgen/specVersionCompat.d.ts +71 -0
- package/types/lib/stages/postgen/specVersionCompat.d.ts.map +1 -0
- package/types/lib/stages/pregen/envAudit.d.ts +14 -0
- package/types/lib/stages/pregen/envAudit.d.ts.map +1 -0
- package/types/lib/stages/pregen/pregen.d.ts +59 -0
- package/types/lib/stages/pregen/pregen.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/arborist/index.d.ts +47 -0
- package/types/lib/third-party/arborist/lib/arborist/index.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/arborist/load-actual.d.ts +4 -0
- package/types/lib/third-party/arborist/lib/arborist/load-actual.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/arborist/load-virtual.d.ts +4 -0
- package/types/lib/third-party/arborist/lib/arborist/load-virtual.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/bin-links.d.ts +18 -0
- package/types/lib/third-party/arborist/lib/bin-links.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/calc-dep-flags.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/calc-dep-flags.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/case-insensitive-map.d.ts +9 -0
- package/types/lib/third-party/arborist/lib/case-insensitive-map.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/consistent-resolve.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/consistent-resolve.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/debug.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/debug.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/dep-valid.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/dep-valid.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/edge.d.ts +46 -0
- package/types/lib/third-party/arborist/lib/edge.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/from-path.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/from-path.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/gather-dep-set.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/gather-dep-set.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/index.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/index.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/inventory.d.ts +14 -0
- package/types/lib/third-party/arborist/lib/inventory.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/link.d.ts +18 -0
- package/types/lib/third-party/arborist/lib/link.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/node.d.ts +112 -0
- package/types/lib/third-party/arborist/lib/node.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/npm-extension.d.ts +18 -0
- package/types/lib/third-party/arborist/lib/npm-extension.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/override-resolves.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/override-resolves.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/override-set.d.ts +27 -0
- package/types/lib/third-party/arborist/lib/override-set.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/package-extensions.d.ts +36 -0
- package/types/lib/third-party/arborist/lib/package-extensions.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/printable.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/printable.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/proc-log.d.ts +20 -0
- package/types/lib/third-party/arborist/lib/proc-log.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/realpath.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/realpath.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/relpath.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/relpath.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/shrinkwrap.d.ts +54 -0
- package/types/lib/third-party/arborist/lib/shrinkwrap.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/spec-from-lock.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/spec-from-lock.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/tree-check.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/tree-check.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/validate-npm-package-name.d.ts +13 -0
- package/types/lib/third-party/arborist/lib/validate-npm-package-name.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/version-from-tgz.d.ts +6 -0
- package/types/lib/third-party/arborist/lib/version-from-tgz.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/yarn-lock.d.ts +35 -0
- package/types/lib/third-party/arborist/lib/yarn-lock.d.ts.map +1 -0
- package/types/lib/validator/bomValidator.d.ts +40 -0
- package/types/lib/validator/bomValidator.d.ts.map +1 -0
- package/types/lib/validator/complianceEngine.d.ts +72 -0
- package/types/lib/validator/complianceEngine.d.ts.map +1 -0
- package/types/lib/validator/complianceRules.d.ts +61 -0
- package/types/lib/validator/complianceRules.d.ts.map +1 -0
- package/types/lib/validator/index.d.ts +101 -0
- package/types/lib/validator/index.d.ts.map +1 -0
- package/types/lib/validator/reporters/annotations.d.ts +37 -0
- package/types/lib/validator/reporters/annotations.d.ts.map +1 -0
- package/types/lib/validator/reporters/console.d.ts +34 -0
- package/types/lib/validator/reporters/console.d.ts.map +1 -0
- package/types/lib/validator/reporters/index.d.ts +30 -0
- package/types/lib/validator/reporters/index.d.ts.map +1 -0
- package/types/lib/validator/reporters/json.d.ts +11 -0
- package/types/lib/validator/reporters/json.d.ts.map +1 -0
- package/types/lib/validator/reporters/sarif.d.ts +22 -0
- package/types/lib/validator/reporters/sarif.d.ts.map +1 -0
- package/mod.d.ts +0 -7
- package/mod.js +0 -22
|
@@ -0,0 +1,1430 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { build } from "@cdxgen/cdx-purl";
|
|
5
|
+
|
|
6
|
+
import { DEBUG_MODE } from "../core/activity.js";
|
|
7
|
+
import { DOTNET_CMD } from "../core/env.js";
|
|
8
|
+
import { safeExistsSync, safeSpawnSync } from "../core/fs.js";
|
|
9
|
+
import { isWin } from "../core/paths.js";
|
|
10
|
+
import { readZipEntry } from "../inventory/deps.js";
|
|
11
|
+
import { applyPurl, concreteVersion, nugetPurl } from "../inventory/purl.js";
|
|
12
|
+
import { findLicenseId } from "../inventory/spdx.js";
|
|
13
|
+
import { xml2js } from "../parsers/xml.js";
|
|
14
|
+
import { extractPackageInfoFromHintPath } from "./dotnetutils.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Method to parse .nupkg files
|
|
18
|
+
*
|
|
19
|
+
* @param {String} nupkgFile .nupkg file
|
|
20
|
+
* @returns {Object} Object containing package list and dependencies
|
|
21
|
+
*/
|
|
22
|
+
export async function parseNupkg(nupkgFile) {
|
|
23
|
+
let nuspecData = await readZipEntry(nupkgFile, ".nuspec");
|
|
24
|
+
if (!nuspecData) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
if (nuspecData.charCodeAt(0) === 65533) {
|
|
28
|
+
nuspecData = await readZipEntry(nupkgFile, ".nuspec", "ucs2");
|
|
29
|
+
}
|
|
30
|
+
return parseNuspecData(nupkgFile, nuspecData);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Method to parse .nuspec files
|
|
35
|
+
*
|
|
36
|
+
* @param {String} nupkgFile .nupkg file
|
|
37
|
+
* @param {String} nuspecData Raw nuspec data
|
|
38
|
+
* @returns {Object} Object containing package list and dependencies
|
|
39
|
+
*/
|
|
40
|
+
export function parseNuspecData(nupkgFile, nuspecData) {
|
|
41
|
+
const pkgList = [];
|
|
42
|
+
const pkg = { group: "" };
|
|
43
|
+
let npkg;
|
|
44
|
+
const dependenciesMap = {};
|
|
45
|
+
const addedMap = {};
|
|
46
|
+
try {
|
|
47
|
+
npkg = xml2js(nuspecData, {
|
|
48
|
+
compact: true,
|
|
49
|
+
alwaysArray: false,
|
|
50
|
+
spaces: 4,
|
|
51
|
+
textKey: "_",
|
|
52
|
+
attributesKey: "$",
|
|
53
|
+
commentKey: "value",
|
|
54
|
+
}).package;
|
|
55
|
+
} catch (_e) {
|
|
56
|
+
// If we are parsing with invalid encoding, unicode replacement character is used
|
|
57
|
+
if (nuspecData.charCodeAt(0) === 65533) {
|
|
58
|
+
console.log(`Unable to parse ${nupkgFile} in utf-8 mode`);
|
|
59
|
+
} else {
|
|
60
|
+
console.log(
|
|
61
|
+
"Unable to parse this package. Tried utf-8 and ucs2 encoding.",
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!npkg) {
|
|
66
|
+
return {
|
|
67
|
+
pkgList,
|
|
68
|
+
dependenciesMap,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const m = npkg.metadata;
|
|
72
|
+
pkg.name = m.id._;
|
|
73
|
+
pkg.version = m.version._;
|
|
74
|
+
pkg.description = m.description._;
|
|
75
|
+
applyPurl(pkg, nugetPurl(pkg.name, pkg.version));
|
|
76
|
+
if (m.licenseUrl) {
|
|
77
|
+
pkg.license = findLicenseId(m.licenseUrl._);
|
|
78
|
+
}
|
|
79
|
+
if (m.authors) {
|
|
80
|
+
pkg.author = m.authors._;
|
|
81
|
+
}
|
|
82
|
+
pkg.properties = [
|
|
83
|
+
{
|
|
84
|
+
name: "internal:SrcFile",
|
|
85
|
+
value: nupkgFile,
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
pkg.evidence = {
|
|
89
|
+
identity: {
|
|
90
|
+
field: "purl",
|
|
91
|
+
confidence: 1,
|
|
92
|
+
methods: [
|
|
93
|
+
{
|
|
94
|
+
technique: "binary-analysis",
|
|
95
|
+
confidence: 1,
|
|
96
|
+
value: nupkgFile,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
pkg.scope = "required";
|
|
102
|
+
pkgList.push(pkg);
|
|
103
|
+
if (m?.dependencies?.dependency) {
|
|
104
|
+
const dependsOn = [];
|
|
105
|
+
if (Array.isArray(m.dependencies.dependency)) {
|
|
106
|
+
for (const adep of m.dependencies.dependency) {
|
|
107
|
+
const d = adep.$;
|
|
108
|
+
dependsOn.push(d.id);
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
const d = m.dependencies.dependency.$;
|
|
112
|
+
dependsOn.push(d.id);
|
|
113
|
+
}
|
|
114
|
+
dependenciesMap[pkg["bom-ref"]] = dependsOn;
|
|
115
|
+
} else if (m?.dependencies?.group) {
|
|
116
|
+
let dependencyGroups;
|
|
117
|
+
if (Array.isArray(m.dependencies.group)) {
|
|
118
|
+
dependencyGroups = m.dependencies.group;
|
|
119
|
+
} else {
|
|
120
|
+
dependencyGroups = [m.dependencies.group];
|
|
121
|
+
}
|
|
122
|
+
const dependsOn = [];
|
|
123
|
+
for (const agroup of dependencyGroups) {
|
|
124
|
+
let targetFramework;
|
|
125
|
+
if (agroup?.$?.targetFramework) {
|
|
126
|
+
targetFramework = agroup.$.targetFramework;
|
|
127
|
+
}
|
|
128
|
+
if (agroup?.dependency) {
|
|
129
|
+
let groupDependencies = [];
|
|
130
|
+
// This dependency can be an array or object
|
|
131
|
+
if (Array.isArray(agroup.dependency)) {
|
|
132
|
+
groupDependencies = agroup.dependency;
|
|
133
|
+
} else if (agroup?.dependency?.$) {
|
|
134
|
+
groupDependencies = [agroup.dependency];
|
|
135
|
+
}
|
|
136
|
+
for (let agroupdep of groupDependencies) {
|
|
137
|
+
agroupdep = agroupdep.$;
|
|
138
|
+
const groupPkg = {};
|
|
139
|
+
if (!agroupdep.id) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
groupPkg.name = agroupdep.id;
|
|
143
|
+
if (agroupdep?.version) {
|
|
144
|
+
let versionStr = agroupdep.version;
|
|
145
|
+
// version could have square brackets around them
|
|
146
|
+
if (versionStr.startsWith("[") && versionStr.endsWith("]")) {
|
|
147
|
+
versionStr = versionStr.replace(/[\[\]]/g, "");
|
|
148
|
+
}
|
|
149
|
+
groupPkg.version = versionStr;
|
|
150
|
+
applyPurl(groupPkg, nugetPurl(groupPkg.name, versionStr));
|
|
151
|
+
} else {
|
|
152
|
+
applyPurl(groupPkg, nugetPurl(groupPkg.name));
|
|
153
|
+
}
|
|
154
|
+
groupPkg.scope = "optional";
|
|
155
|
+
groupPkg.properties = [
|
|
156
|
+
{
|
|
157
|
+
name: "internal:SrcFile",
|
|
158
|
+
value: nupkgFile,
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
if (targetFramework) {
|
|
162
|
+
groupPkg.properties.push({
|
|
163
|
+
name: "cdx:dotnet:target_framework",
|
|
164
|
+
value: targetFramework,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
groupPkg.evidence = {
|
|
168
|
+
identity: {
|
|
169
|
+
field: "purl",
|
|
170
|
+
confidence: 0.7,
|
|
171
|
+
methods: [
|
|
172
|
+
{
|
|
173
|
+
technique: "binary-analysis",
|
|
174
|
+
confidence: 1,
|
|
175
|
+
value: nupkgFile,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
pkgList.push(groupPkg);
|
|
181
|
+
if (!addedMap[groupPkg.purl]) {
|
|
182
|
+
dependsOn.push(groupPkg.name);
|
|
183
|
+
addedMap[groupPkg.purl] = true;
|
|
184
|
+
}
|
|
185
|
+
} // for
|
|
186
|
+
} // group dependency block
|
|
187
|
+
dependenciesMap[pkg["bom-ref"]] = dependsOn;
|
|
188
|
+
} // for
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
pkgList,
|
|
192
|
+
dependenciesMap,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Parse a C# packages.config XML file and return a list of NuGet package components.
|
|
198
|
+
*
|
|
199
|
+
* @param {string} pkgData Raw XML string of a packages.config file
|
|
200
|
+
* @param {string} pkgFile Path to the packages.config file, used for evidence properties
|
|
201
|
+
* @param {Object} pkgNameVersions Package name - version map of versions already resolved
|
|
202
|
+
* from more precise manifests (project.assets.json / packages.lock.json), used to
|
|
203
|
+
* backfill templated or missing versions
|
|
204
|
+
* @returns {Object[]} Array of NuGet package objects with purl, name, and version
|
|
205
|
+
*/
|
|
206
|
+
export function parseCsPkgData(pkgData, pkgFile, pkgNameVersions = {}) {
|
|
207
|
+
const pkgList = [];
|
|
208
|
+
if (!pkgData) {
|
|
209
|
+
return pkgList;
|
|
210
|
+
}
|
|
211
|
+
// Remove byte order mark
|
|
212
|
+
if (pkgData.charCodeAt(0) === 0xfeff) {
|
|
213
|
+
pkgData = pkgData.slice(1);
|
|
214
|
+
}
|
|
215
|
+
let packages = xml2js(pkgData, {
|
|
216
|
+
compact: true,
|
|
217
|
+
alwaysArray: true,
|
|
218
|
+
spaces: 4,
|
|
219
|
+
textKey: "_",
|
|
220
|
+
attributesKey: "$",
|
|
221
|
+
commentKey: "value",
|
|
222
|
+
}).packages;
|
|
223
|
+
if (!packages || packages.length === 0) {
|
|
224
|
+
return pkgList;
|
|
225
|
+
}
|
|
226
|
+
packages = packages[0].package;
|
|
227
|
+
for (const i in packages) {
|
|
228
|
+
const p = packages[i].$;
|
|
229
|
+
const pkg = { group: "" };
|
|
230
|
+
pkg.name = p.id;
|
|
231
|
+
pkg.version = p.version;
|
|
232
|
+
// packages.config versions can be imprecise: missing entirely, templated
|
|
233
|
+
// msbuild properties such as $(FooVersion), NuGet ranges such as [1.0,2.0),
|
|
234
|
+
// or wildcards such as 1.0.*. Track such packages at a lower confidence.
|
|
235
|
+
let confidence = 0.7;
|
|
236
|
+
// A bracketed single version such as [4.4.1] pins an exact version
|
|
237
|
+
const exactPin = pkg.version?.match(/^\[([^,[\]()]+)\]$/);
|
|
238
|
+
if (exactPin) {
|
|
239
|
+
pkg.version = exactPin[1];
|
|
240
|
+
}
|
|
241
|
+
// A range such as [1.0,2.0) or a wildcard such as 1.0.* is a declared
|
|
242
|
+
// constraint rather than an installed version. The constraint is recorded
|
|
243
|
+
// so the declaration stays visible, and the version is resolved from a
|
|
244
|
+
// more precise manifest so the purl names the package that is present.
|
|
245
|
+
let declaredRange;
|
|
246
|
+
if (!pkg.version || pkg.version.includes("$(")) {
|
|
247
|
+
confidence = 0.5;
|
|
248
|
+
// Backfill from a version already resolved by a more precise manifest.
|
|
249
|
+
// Concrete versions are never overridden - a disagreement means both
|
|
250
|
+
// versions must be tracked.
|
|
251
|
+
pkg.version = pkgNameVersions[pkg.name] || undefined;
|
|
252
|
+
} else if (/[[\](),*]/.test(pkg.version)) {
|
|
253
|
+
confidence = 0.5;
|
|
254
|
+
if (pkgNameVersions[pkg.name]) {
|
|
255
|
+
declaredRange = pkg.version;
|
|
256
|
+
pkg.version = pkgNameVersions[pkg.name];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
applyPurl(pkg, nugetPurl(pkg.name, pkg.version));
|
|
260
|
+
if (pkgFile) {
|
|
261
|
+
pkg.properties = [
|
|
262
|
+
{
|
|
263
|
+
name: "internal:SrcFile",
|
|
264
|
+
value: pkgFile,
|
|
265
|
+
},
|
|
266
|
+
];
|
|
267
|
+
if (declaredRange) {
|
|
268
|
+
pkg.properties.push({
|
|
269
|
+
name: "cdx:nuget:declared_version_range",
|
|
270
|
+
value: declaredRange,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
pkg.evidence = {
|
|
274
|
+
identity: {
|
|
275
|
+
field: "purl",
|
|
276
|
+
confidence,
|
|
277
|
+
methods: [
|
|
278
|
+
{
|
|
279
|
+
technique: "manifest-analysis",
|
|
280
|
+
confidence,
|
|
281
|
+
value: pkgFile,
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
pkgList.push(pkg);
|
|
288
|
+
}
|
|
289
|
+
return pkgList;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Parse a Directory.Packages.props file and return the package versions it declares
|
|
294
|
+
* centrally via NuGet Central Package Management.
|
|
295
|
+
*
|
|
296
|
+
* @param {String} propsFile Path to a Directory.Packages.props file
|
|
297
|
+
*
|
|
298
|
+
* @returns {Object} Map of lowercased package id to version. NuGet package ids are
|
|
299
|
+
* case-insensitive, so callers must lowercase before looking up.
|
|
300
|
+
*/
|
|
301
|
+
export function parseDirectoryPackagesProps(propsFile) {
|
|
302
|
+
const versions = {};
|
|
303
|
+
let projects;
|
|
304
|
+
try {
|
|
305
|
+
const data = readFileSync(propsFile, { encoding: "utf-8" });
|
|
306
|
+
projects = xml2js(data, {
|
|
307
|
+
compact: true,
|
|
308
|
+
spaces: 4,
|
|
309
|
+
alwaysArray: true,
|
|
310
|
+
textKey: "_",
|
|
311
|
+
attributesKey: "$",
|
|
312
|
+
commentKey: "value",
|
|
313
|
+
}).Project;
|
|
314
|
+
} catch (_e) {
|
|
315
|
+
console.log(`Unable to parse ${propsFile} with utf-8 encoding!`);
|
|
316
|
+
return versions;
|
|
317
|
+
}
|
|
318
|
+
if (!projects?.length) {
|
|
319
|
+
return versions;
|
|
320
|
+
}
|
|
321
|
+
const project = projects[0];
|
|
322
|
+
// A project can keep the file around with central management switched off, in
|
|
323
|
+
// which case the PackageVersion entries are inert and must not be applied. An
|
|
324
|
+
// absent property is treated as enabled, because it is commonly set in
|
|
325
|
+
// Directory.Build.props which is not read here.
|
|
326
|
+
for (const propertyGroup of project.PropertyGroup || []) {
|
|
327
|
+
const managed = propertyGroup.ManagePackageVersionsCentrally?.[0]?._?.[0];
|
|
328
|
+
if (managed && `${managed}`.trim().toLowerCase() === "false") {
|
|
329
|
+
return versions;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
for (const item of project.ItemGroup || []) {
|
|
333
|
+
for (const pv of item.PackageVersion || []) {
|
|
334
|
+
const attrs = pv.$ || {};
|
|
335
|
+
// Update is the documented way to change a version declared by an
|
|
336
|
+
// imported props file, and is as authoritative as Include here.
|
|
337
|
+
const name = attrs.Include || attrs.Update;
|
|
338
|
+
const version = attrs.Version || pv.Version?.[0]?._?.[0];
|
|
339
|
+
if (name && version) {
|
|
340
|
+
versions[name.toLowerCase()] = version;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return versions;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Method to collect the versions declared by NuGet Central Package Management for a
|
|
349
|
+
* given project file, by walking up to the nearest Directory.Packages.props.
|
|
350
|
+
*
|
|
351
|
+
* MSBuild imports the first Directory.Packages.props found while walking up from the
|
|
352
|
+
* project directory, and that file is often at the repository root - above the
|
|
353
|
+
* directory cdxgen was invoked with. The walk therefore deliberately continues past
|
|
354
|
+
* the scan root rather than stopping at it.
|
|
355
|
+
*
|
|
356
|
+
* @param {String} projFile Path to a .csproj like project file
|
|
357
|
+
* @param {Object} cache Optional per-scan cache keyed by props file path, so that a
|
|
358
|
+
* repository with many projects parses each props file once
|
|
359
|
+
*
|
|
360
|
+
* @returns {Object} Map of lowercased package id to version. Empty when the project
|
|
361
|
+
* does not use central package management.
|
|
362
|
+
*/
|
|
363
|
+
export function getCentralPackageVersions(projFile, cache = {}) {
|
|
364
|
+
if (!projFile) {
|
|
365
|
+
return {};
|
|
366
|
+
}
|
|
367
|
+
let dir = dirname(resolve(projFile));
|
|
368
|
+
for (;;) {
|
|
369
|
+
const propsFile = join(dir, "Directory.Packages.props");
|
|
370
|
+
if (safeExistsSync(propsFile)) {
|
|
371
|
+
if (!(propsFile in cache)) {
|
|
372
|
+
cache[propsFile] = parseDirectoryPackagesProps(propsFile);
|
|
373
|
+
}
|
|
374
|
+
return cache[propsFile];
|
|
375
|
+
}
|
|
376
|
+
const parent = dirname(dir);
|
|
377
|
+
if (parent === dir) {
|
|
378
|
+
return {};
|
|
379
|
+
}
|
|
380
|
+
dir = parent;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Method to find all text nodes in PropertyGroup elements in .props files.
|
|
386
|
+
*
|
|
387
|
+
* @param {String} propsFiles .props files in this project
|
|
388
|
+
*
|
|
389
|
+
* @returns {Object} Containing text nodes from PropertyGroup elements and their values
|
|
390
|
+
*/
|
|
391
|
+
export function getPropertyGroupTextNodes(propsFiles) {
|
|
392
|
+
const matches = {};
|
|
393
|
+
for (const f of propsFiles) {
|
|
394
|
+
if (!f) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
let projects;
|
|
398
|
+
try {
|
|
399
|
+
const data = readFileSync(f, { encoding: "utf-8" });
|
|
400
|
+
projects = xml2js(data, {
|
|
401
|
+
compact: true,
|
|
402
|
+
spaces: 4,
|
|
403
|
+
alwaysArray: true,
|
|
404
|
+
textKey: "_",
|
|
405
|
+
attributesKey: "$",
|
|
406
|
+
commentKey: "value",
|
|
407
|
+
}).Project;
|
|
408
|
+
} catch (_e) {
|
|
409
|
+
console.log(`Unable to parse ${f} with utf-8 encoding!`);
|
|
410
|
+
}
|
|
411
|
+
if (!projects || projects.length === 0) {
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
const project = projects[0];
|
|
415
|
+
if (project?.PropertyGroup) {
|
|
416
|
+
for (const propertyGroup of project.PropertyGroup) {
|
|
417
|
+
for (const [key, value] of Object.entries(propertyGroup)) {
|
|
418
|
+
if (value?.length && Object.keys(value[0]).includes("_")) {
|
|
419
|
+
if (key in matches) {
|
|
420
|
+
if (!matches[key].includes(value[0]._[0])) {
|
|
421
|
+
matches[key].push(value[0]._[0]);
|
|
422
|
+
}
|
|
423
|
+
} else {
|
|
424
|
+
matches[key] = [value[0]._[0]];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return matches;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Method to parse .csproj like xml files
|
|
436
|
+
*
|
|
437
|
+
* @param {String} csProjData Raw data
|
|
438
|
+
* @param {String} projFile File name
|
|
439
|
+
* @param {Object} pkgNameVersions Package name - version map object
|
|
440
|
+
* @param {Boolean} msbuildInstalled Whether msbuild is available to resolve properties
|
|
441
|
+
* @param {Object} pkgVersionLabelCandidates Candidate values for msbuild version properties
|
|
442
|
+
* @param {Object} centralVersions Versions declared centrally in Directory.Packages.props,
|
|
443
|
+
* keyed by lowercased package id. See {@link getCentralPackageVersions}.
|
|
444
|
+
*
|
|
445
|
+
* @returns {Object} Containing parent component, package, and dependencies
|
|
446
|
+
*/
|
|
447
|
+
export function parseCsProjData(
|
|
448
|
+
csProjData,
|
|
449
|
+
projFile,
|
|
450
|
+
pkgNameVersions = {},
|
|
451
|
+
msbuildInstalled = false,
|
|
452
|
+
pkgVersionLabelCandidates = {},
|
|
453
|
+
centralVersions = {},
|
|
454
|
+
) {
|
|
455
|
+
const pkgList = [];
|
|
456
|
+
const parentComponent = { type: "application", properties: [] };
|
|
457
|
+
if (!csProjData) {
|
|
458
|
+
return pkgList;
|
|
459
|
+
}
|
|
460
|
+
// Remove byte order mark
|
|
461
|
+
if (csProjData.charCodeAt(0) === 0xfeff) {
|
|
462
|
+
csProjData = csProjData.slice(1);
|
|
463
|
+
}
|
|
464
|
+
const projectTargetFrameworks = [];
|
|
465
|
+
let projects;
|
|
466
|
+
try {
|
|
467
|
+
projects = xml2js(csProjData, {
|
|
468
|
+
compact: true,
|
|
469
|
+
alwaysArray: true,
|
|
470
|
+
spaces: 4,
|
|
471
|
+
textKey: "_",
|
|
472
|
+
attributesKey: "$",
|
|
473
|
+
commentKey: "value",
|
|
474
|
+
}).Project;
|
|
475
|
+
} catch (_e) {
|
|
476
|
+
console.log(`Unable to parse ${projFile} with utf-8 encoding!`);
|
|
477
|
+
}
|
|
478
|
+
if (!projects || projects.length === 0) {
|
|
479
|
+
return pkgList;
|
|
480
|
+
}
|
|
481
|
+
const project = projects[0];
|
|
482
|
+
// First make up a parentcomponent name based on the .csproj file name
|
|
483
|
+
if (projFile) {
|
|
484
|
+
parentComponent.name = basename(projFile).replaceAll(
|
|
485
|
+
/.(cs|fs|vb|ts|plc|hmi)proj$/g,
|
|
486
|
+
"",
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
// Collect details about the parent component
|
|
490
|
+
if (project?.PropertyGroup?.length) {
|
|
491
|
+
for (const apg of project.PropertyGroup) {
|
|
492
|
+
if (
|
|
493
|
+
apg?.AssemblyName &&
|
|
494
|
+
Array.isArray(apg.AssemblyName) &&
|
|
495
|
+
apg.AssemblyName[0]._ &&
|
|
496
|
+
Array.isArray(apg.AssemblyName[0]._)
|
|
497
|
+
) {
|
|
498
|
+
parentComponent.name = apg.AssemblyName[0]._[0];
|
|
499
|
+
} else if (
|
|
500
|
+
apg?.Name &&
|
|
501
|
+
Array.isArray(apg.Name) &&
|
|
502
|
+
apg.Name[0]._ &&
|
|
503
|
+
Array.isArray(apg.Name[0]._)
|
|
504
|
+
) {
|
|
505
|
+
parentComponent.name = apg.Name[0]._[0];
|
|
506
|
+
}
|
|
507
|
+
if (
|
|
508
|
+
apg?.ProductVersion &&
|
|
509
|
+
Array.isArray(apg.ProductVersion) &&
|
|
510
|
+
apg.ProductVersion[0]._ &&
|
|
511
|
+
Array.isArray(apg.ProductVersion[0]._)
|
|
512
|
+
) {
|
|
513
|
+
parentComponent.version = apg.ProductVersion[0]._[0];
|
|
514
|
+
} else if (
|
|
515
|
+
apg?.ProgramVersion &&
|
|
516
|
+
Array.isArray(apg.ProgramVersion) &&
|
|
517
|
+
apg.ProgramVersion[0]._ &&
|
|
518
|
+
Array.isArray(apg.ProgramVersion[0]._)
|
|
519
|
+
) {
|
|
520
|
+
parentComponent.version = apg.ProgramVersion[0]._[0];
|
|
521
|
+
} else if (
|
|
522
|
+
apg?.HmiVersion &&
|
|
523
|
+
Array.isArray(apg.HmiVersion) &&
|
|
524
|
+
apg.HmiVersion[0]._ &&
|
|
525
|
+
Array.isArray(apg.HmiVersion[0]._)
|
|
526
|
+
) {
|
|
527
|
+
parentComponent.version = apg.HmiVersion[0]._[0];
|
|
528
|
+
}
|
|
529
|
+
if (
|
|
530
|
+
apg?.OutputType &&
|
|
531
|
+
Array.isArray(apg.OutputType) &&
|
|
532
|
+
apg.OutputType[0]._ &&
|
|
533
|
+
Array.isArray(apg.OutputType[0]._)
|
|
534
|
+
) {
|
|
535
|
+
const outputType = apg.OutputType[0]._[0];
|
|
536
|
+
if (outputType === "Library") {
|
|
537
|
+
parentComponent.type = "library";
|
|
538
|
+
}
|
|
539
|
+
applyPurl(
|
|
540
|
+
parentComponent,
|
|
541
|
+
nugetPurl(parentComponent.name, parentComponent.version || "latest"),
|
|
542
|
+
);
|
|
543
|
+
// The MSBuild OutputType (Exe, WinExe, …) used to ride along as an
|
|
544
|
+
// `output_type` purl qualifier, which nuget does not define — every such
|
|
545
|
+
// purl was invalid. It is project metadata, so it belongs in properties.
|
|
546
|
+
if (outputType !== "Library") {
|
|
547
|
+
parentComponent.properties = parentComponent.properties || [];
|
|
548
|
+
parentComponent.properties.push({
|
|
549
|
+
name: "cdx:dotnet:output_type",
|
|
550
|
+
value: outputType,
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (
|
|
555
|
+
apg?.ProjectGuid &&
|
|
556
|
+
Array.isArray(apg.ProjectGuid) &&
|
|
557
|
+
apg.ProjectGuid[0]._ &&
|
|
558
|
+
Array.isArray(apg.ProjectGuid[0]._)
|
|
559
|
+
) {
|
|
560
|
+
parentComponent.properties.push({
|
|
561
|
+
name: "cdx:dotnet:project_guid",
|
|
562
|
+
value: apg.ProjectGuid[0]._[0],
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
if (
|
|
566
|
+
apg?.RootNamespace &&
|
|
567
|
+
Array.isArray(apg.RootNamespace) &&
|
|
568
|
+
apg.RootNamespace[0]._ &&
|
|
569
|
+
Array.isArray(apg.RootNamespace[0]._)
|
|
570
|
+
) {
|
|
571
|
+
parentComponent.properties.push({
|
|
572
|
+
name: "internal:Namespaces",
|
|
573
|
+
value: apg.RootNamespace[0]._[0],
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
if (
|
|
577
|
+
apg?.TargetFramework &&
|
|
578
|
+
Array.isArray(apg.TargetFramework) &&
|
|
579
|
+
apg.TargetFramework[0]._ &&
|
|
580
|
+
Array.isArray(apg.TargetFramework[0]._)
|
|
581
|
+
) {
|
|
582
|
+
for (const apgtf of apg.TargetFramework[0]._) {
|
|
583
|
+
projectTargetFrameworks.push(apgtf);
|
|
584
|
+
parentComponent.properties.push({
|
|
585
|
+
name: "cdx:dotnet:target_framework",
|
|
586
|
+
value: apgtf,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
} else if (
|
|
590
|
+
apg?.TargetFrameworkVersion &&
|
|
591
|
+
Array.isArray(apg.TargetFrameworkVersion) &&
|
|
592
|
+
apg.TargetFrameworkVersion[0]._ &&
|
|
593
|
+
Array.isArray(apg.TargetFrameworkVersion[0]._)
|
|
594
|
+
) {
|
|
595
|
+
for (const apgtf of apg.TargetFrameworkVersion[0]._) {
|
|
596
|
+
projectTargetFrameworks.push(apgtf);
|
|
597
|
+
parentComponent.properties.push({
|
|
598
|
+
name: "cdx:dotnet:target_framework",
|
|
599
|
+
value: apgtf,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
} else if (
|
|
603
|
+
apg?.TargetFrameworks &&
|
|
604
|
+
Array.isArray(apg.TargetFrameworks) &&
|
|
605
|
+
apg.TargetFrameworks[0]._ &&
|
|
606
|
+
Array.isArray(apg.TargetFrameworks[0]._)
|
|
607
|
+
) {
|
|
608
|
+
for (const apgtf of apg.TargetFrameworks[0]._) {
|
|
609
|
+
projectTargetFrameworks.push(apgtf);
|
|
610
|
+
parentComponent.properties.push({
|
|
611
|
+
name: "cdx:dotnet:target_framework",
|
|
612
|
+
value: apgtf,
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (
|
|
617
|
+
apg?.AzureFunctionsVersion &&
|
|
618
|
+
Array.isArray(apg.AzureFunctionsVersion) &&
|
|
619
|
+
apg.AzureFunctionsVersion[0]._ &&
|
|
620
|
+
Array.isArray(apg.AzureFunctionsVersion[0]._)
|
|
621
|
+
) {
|
|
622
|
+
parentComponent.properties.push({
|
|
623
|
+
name: "cdx:dotnet:azure_functions_version",
|
|
624
|
+
value: apg.AzureFunctionsVersion[0]._[0],
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
if (
|
|
628
|
+
apg?.Description &&
|
|
629
|
+
Array.isArray(apg.Description) &&
|
|
630
|
+
apg.Description[0]._ &&
|
|
631
|
+
Array.isArray(apg.Description[0]._)
|
|
632
|
+
) {
|
|
633
|
+
parentComponent.description = apg.Description[0]._[0];
|
|
634
|
+
} else if (
|
|
635
|
+
apg?.PackageDescription &&
|
|
636
|
+
Array.isArray(apg.PackageDescription) &&
|
|
637
|
+
apg.PackageDescription[0]._ &&
|
|
638
|
+
Array.isArray(apg.PackageDescription[0]._)
|
|
639
|
+
) {
|
|
640
|
+
parentComponent.description = apg.PackageDescription[0]._[0];
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (project.ItemGroup?.length) {
|
|
645
|
+
for (const i in project.ItemGroup) {
|
|
646
|
+
const item = project.ItemGroup[i];
|
|
647
|
+
// .net core use PackageReference
|
|
648
|
+
for (const j in item.PackageReference) {
|
|
649
|
+
const pref = item.PackageReference[j].$;
|
|
650
|
+
const pkg = { group: "" };
|
|
651
|
+
if (!pref.Include || pref.Include.includes(".csproj")) {
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
pkg.name = pref.Include;
|
|
655
|
+
// Under central package management a PackageReference carries no Version at
|
|
656
|
+
// all, and VersionOverride is the documented way for a project to opt out of
|
|
657
|
+
// the central version, so it wins over everything else. The central version
|
|
658
|
+
// is consulted only after pkgNameVersions, which holds versions already
|
|
659
|
+
// resolved from project.assets.json / packages.lock.json and is therefore
|
|
660
|
+
// more precise than a central declaration that may be a floating range.
|
|
661
|
+
pkg.version =
|
|
662
|
+
pref.VersionOverride ||
|
|
663
|
+
item.PackageReference[j].VersionOverride?.[0]._?.[0] ||
|
|
664
|
+
pref.Version ||
|
|
665
|
+
item.PackageReference[j].Version?.[0]._?.[0] ||
|
|
666
|
+
pkgNameVersions[pkg.name] ||
|
|
667
|
+
centralVersions[pkg.name.toLowerCase()];
|
|
668
|
+
if (pkg.version) {
|
|
669
|
+
const version_label_match = pkg.version.match(/^\$\((.*)\)$/)?.[1];
|
|
670
|
+
if (version_label_match) {
|
|
671
|
+
let version_resolved = false;
|
|
672
|
+
if (msbuildInstalled) {
|
|
673
|
+
const result = safeSpawnSync(
|
|
674
|
+
DOTNET_CMD,
|
|
675
|
+
[
|
|
676
|
+
`msbuild ${projFile} -nologo -getProperty:${version_label_match}`,
|
|
677
|
+
],
|
|
678
|
+
{ shell: isWin },
|
|
679
|
+
);
|
|
680
|
+
if (
|
|
681
|
+
result.status === 0 &&
|
|
682
|
+
!result.error &&
|
|
683
|
+
result.stdout.trim()
|
|
684
|
+
) {
|
|
685
|
+
pkg.version = result.stdout.trim();
|
|
686
|
+
version_resolved = true;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (!version_resolved) {
|
|
690
|
+
if (
|
|
691
|
+
pkgVersionLabelCandidates[version_label_match]?.length === 1
|
|
692
|
+
) {
|
|
693
|
+
// Prioritizing correctness over completeness: reject resolved package version label if it has more than one possible values.
|
|
694
|
+
pkg.version = pkgVersionLabelCandidates[version_label_match][0];
|
|
695
|
+
} else if (DEBUG_MODE) {
|
|
696
|
+
console.log(
|
|
697
|
+
`Could not resolve package version label ${version_label_match} for ${pkg.name}`,
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
// A `Version` attribute holds whatever the project declares, which may
|
|
704
|
+
// be an MSBuild property that did not resolve, a floating range such as
|
|
705
|
+
// `1.0-*`, or a range such as `[1.0,2.0)`. A bracketed single version
|
|
706
|
+
// pins one version and is unwrapped; any other non-concrete form is
|
|
707
|
+
// resolved from project.assets.json / packages.lock.json or central
|
|
708
|
+
// package management so the purl names the version that is installed,
|
|
709
|
+
// with the declaration kept as a property.
|
|
710
|
+
let declaredRange;
|
|
711
|
+
if (pkg.version) {
|
|
712
|
+
const exactPin = pkg.version.match(/^\[([^,[\]()]+)\]$/);
|
|
713
|
+
if (exactPin) {
|
|
714
|
+
pkg.version = exactPin[1];
|
|
715
|
+
} else if (
|
|
716
|
+
pkg.version.includes("$(") ||
|
|
717
|
+
/[*[\](),]/.test(pkg.version)
|
|
718
|
+
) {
|
|
719
|
+
const resolved =
|
|
720
|
+
pkgNameVersions[pkg.name] ||
|
|
721
|
+
centralVersions[pkg.name.toLowerCase()];
|
|
722
|
+
if (resolved) {
|
|
723
|
+
declaredRange = pkg.version;
|
|
724
|
+
pkg.version = resolved;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
// A version that could not be resolved from any source must not be
|
|
729
|
+
// stringified into the purl - `@undefined` is not a version and makes the
|
|
730
|
+
// component unmatchable. Mirrors parseCsPkgData.
|
|
731
|
+
applyPurl(pkg, nugetPurl(pkg.name, pkg.version));
|
|
732
|
+
if (projFile) {
|
|
733
|
+
pkg.properties = [
|
|
734
|
+
{
|
|
735
|
+
name: "internal:SrcFile",
|
|
736
|
+
value: projFile,
|
|
737
|
+
},
|
|
738
|
+
];
|
|
739
|
+
if (declaredRange) {
|
|
740
|
+
pkg.properties.push({
|
|
741
|
+
name: "cdx:nuget:declared_version_range",
|
|
742
|
+
value: declaredRange,
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
pkg.evidence = {
|
|
746
|
+
identity: {
|
|
747
|
+
field: "purl",
|
|
748
|
+
confidence: 0.7,
|
|
749
|
+
methods: [
|
|
750
|
+
{
|
|
751
|
+
technique: "manifest-analysis",
|
|
752
|
+
confidence: 0.7,
|
|
753
|
+
value: projFile,
|
|
754
|
+
},
|
|
755
|
+
],
|
|
756
|
+
},
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
pkgList.push(pkg);
|
|
760
|
+
}
|
|
761
|
+
// .net framework use Reference
|
|
762
|
+
for (const j in item.Reference) {
|
|
763
|
+
const hintPaths = item.Reference[j]?.HintPath;
|
|
764
|
+
let hintPath;
|
|
765
|
+
let hintVersion;
|
|
766
|
+
let assemblyName;
|
|
767
|
+
let assemblyVersion;
|
|
768
|
+
let packageFileName;
|
|
769
|
+
|
|
770
|
+
if (hintPaths && Array.isArray(hintPaths)) {
|
|
771
|
+
const tmpHintPathValues = hintPaths[0]._;
|
|
772
|
+
if (Array.isArray(tmpHintPathValues)) {
|
|
773
|
+
hintPath = tmpHintPathValues[0];
|
|
774
|
+
packageFileName = basename(hintPath);
|
|
775
|
+
if (packageFileName.includes("\\")) {
|
|
776
|
+
packageFileName = packageFileName.split("\\").pop();
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
const pref = item.Reference[j].$;
|
|
781
|
+
const pkg = { group: "" };
|
|
782
|
+
if (!pref.Include || pref.Include.includes(".csproj")) {
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
const incParts = pref.Include.split(",");
|
|
786
|
+
pkg.name = incParts[0];
|
|
787
|
+
pkg.properties = [];
|
|
788
|
+
// Prefer the version from the hint path if available, falling back to assembly version
|
|
789
|
+
if (hintPath) {
|
|
790
|
+
const packageInfo = extractPackageInfoFromHintPath(hintPath);
|
|
791
|
+
if (packageInfo) {
|
|
792
|
+
hintVersion = packageInfo.version;
|
|
793
|
+
// Assembly name is different to package name
|
|
794
|
+
if (packageInfo.name && pkg.name !== packageInfo.name) {
|
|
795
|
+
assemblyName = pkg.name;
|
|
796
|
+
pkg.name = packageInfo.name;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
let declaredAssemblyVersion;
|
|
801
|
+
if (incParts.length > 1 && incParts[1].includes("Version")) {
|
|
802
|
+
const declared = incParts[1].replace("Version=", "").trim();
|
|
803
|
+
// An assembly reference carries the version inline, and that value can
|
|
804
|
+
// be an MSBuild property such as `Version=$(TargetFSharpCoreVersion)`
|
|
805
|
+
// which only a build evaluates. Anything that is not a concrete
|
|
806
|
+
// version is resolved from the manifests that pin one, keeping the
|
|
807
|
+
// declaration as a property.
|
|
808
|
+
if (declared && !concreteVersion(declared)) {
|
|
809
|
+
declaredAssemblyVersion = declared;
|
|
810
|
+
assemblyVersion =
|
|
811
|
+
pkgNameVersions[pkg.name] ||
|
|
812
|
+
centralVersions[pkg.name.toLowerCase()];
|
|
813
|
+
} else {
|
|
814
|
+
assemblyVersion = declared || pkgNameVersions[pkg.name];
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (declaredAssemblyVersion) {
|
|
818
|
+
pkg.properties.push({
|
|
819
|
+
name: "cdx:nuget:declared_version_range",
|
|
820
|
+
value: declaredAssemblyVersion,
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
const version = hintVersion ?? assemblyVersion;
|
|
824
|
+
if (version) {
|
|
825
|
+
pkg.version = version;
|
|
826
|
+
applyPurl(pkg, nugetPurl(pkg.name, version));
|
|
827
|
+
} else {
|
|
828
|
+
applyPurl(pkg, nugetPurl(pkg.name));
|
|
829
|
+
if (
|
|
830
|
+
pkg.name.startsWith("System.") ||
|
|
831
|
+
pkg.name.startsWith("Mono.") ||
|
|
832
|
+
pkg.name.startsWith("Microsoft.")
|
|
833
|
+
) {
|
|
834
|
+
// If this is a System package, then track the target frameworks
|
|
835
|
+
for (const tf of projectTargetFrameworks) {
|
|
836
|
+
pkg.properties.push({
|
|
837
|
+
name: "cdx:dotnet:target_framework",
|
|
838
|
+
value: tf,
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
pkg["bom-ref"] = pkg.purl;
|
|
844
|
+
if (assemblyName) {
|
|
845
|
+
pkg.properties.push({
|
|
846
|
+
name: "cdx:dotnet:assembly_name",
|
|
847
|
+
value: assemblyName,
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
if (hintVersion && assemblyVersion) {
|
|
851
|
+
pkg.properties.push({
|
|
852
|
+
name: "cdx:dotnet:assembly_version",
|
|
853
|
+
value: assemblyVersion,
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
if (projFile) {
|
|
857
|
+
pkg.properties.push({
|
|
858
|
+
name: "internal:SrcFile",
|
|
859
|
+
value: projFile,
|
|
860
|
+
});
|
|
861
|
+
pkg.evidence = {
|
|
862
|
+
identity: {
|
|
863
|
+
field: "purl",
|
|
864
|
+
confidence: hintVersion ? 0.7 : 0.3,
|
|
865
|
+
methods: [
|
|
866
|
+
{
|
|
867
|
+
technique: "manifest-analysis",
|
|
868
|
+
confidence: hintVersion ? 0.7 : 0.3,
|
|
869
|
+
value: projFile,
|
|
870
|
+
},
|
|
871
|
+
],
|
|
872
|
+
},
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
if (hintPath) {
|
|
876
|
+
// The same component could be referred by a slightly different name.
|
|
877
|
+
// Use the hint_path to figure out the aliases in such cases.
|
|
878
|
+
// Example:
|
|
879
|
+
// <Reference Include="Microsoft.AI.Agent.Intercept, Version=2.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
|
880
|
+
// <HintPath>..\packages\Microsoft.ApplicationInsights.Agent.Intercept.2.0.6\lib\net45\Microsoft.AI.Agent.Intercept.dll</HintPath>
|
|
881
|
+
// </Reference>
|
|
882
|
+
// cdxgen would create two components Microsoft.AI.Agent.Intercept@2.0.6.0 and Microsoft.ApplicationInsights.Agent.Intercept@2.0.6
|
|
883
|
+
// They're The Same Picture meme goes here
|
|
884
|
+
pkg.properties.push({
|
|
885
|
+
name: "cdx:dotnet:hint_path",
|
|
886
|
+
value: hintPath,
|
|
887
|
+
});
|
|
888
|
+
pkg.properties.push({
|
|
889
|
+
name: "internal:PackageFiles",
|
|
890
|
+
value: packageFileName,
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
pkgList.push(pkg);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
// If the parent still lacks a purl, add one based on the name and version
|
|
898
|
+
if (parentComponent && !parentComponent.purl && parentComponent.name) {
|
|
899
|
+
applyPurl(
|
|
900
|
+
parentComponent,
|
|
901
|
+
nugetPurl(parentComponent.name, parentComponent.version || "latest"),
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
if (parentComponent?.purl) {
|
|
905
|
+
parentComponent["bom-ref"] = parentComponent.purl;
|
|
906
|
+
}
|
|
907
|
+
let dependencies = [];
|
|
908
|
+
if (parentComponent?.["bom-ref"]) {
|
|
909
|
+
dependencies = [
|
|
910
|
+
{
|
|
911
|
+
ref: parentComponent.purl,
|
|
912
|
+
dependsOn: [...new Set(pkgList.map((p) => p["bom-ref"]))].sort(),
|
|
913
|
+
},
|
|
914
|
+
];
|
|
915
|
+
}
|
|
916
|
+
return {
|
|
917
|
+
pkgList,
|
|
918
|
+
parentComponent,
|
|
919
|
+
dependencies,
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Parse a .NET project.assets.json file and return the package list and dependency tree.
|
|
925
|
+
*
|
|
926
|
+
* Extracts NuGet packages and their transitive dependency relationships from the
|
|
927
|
+
* `libraries` and `targets` sections of a project.assets.json file produced by
|
|
928
|
+
* the .NET restore process.
|
|
929
|
+
*
|
|
930
|
+
* @param {string} csProjData Raw JSON string of the project.assets.json file
|
|
931
|
+
* @param {string} assetsJsonFile Path to the project.assets.json file, used for evidence properties
|
|
932
|
+
* @returns {{ pkgList: Object[], dependenciesList: Object[] }}
|
|
933
|
+
*/
|
|
934
|
+
export function parseCsProjAssetsData(csProjData, assetsJsonFile) {
|
|
935
|
+
// extract name, operator, version from .NET package representation
|
|
936
|
+
// like "NLog >= 4.5.0"
|
|
937
|
+
function extractNameOperatorVersion(inputStr) {
|
|
938
|
+
if (!inputStr) {
|
|
939
|
+
return null;
|
|
940
|
+
}
|
|
941
|
+
const extractNameOperatorVersion = /([\w.-]+)\s*([><=!]+)\s*(.*)/;
|
|
942
|
+
let match = inputStr.match(extractNameOperatorVersion);
|
|
943
|
+
if (match) {
|
|
944
|
+
return {
|
|
945
|
+
name: match[1],
|
|
946
|
+
operator: match[2],
|
|
947
|
+
version: match[3],
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
match = inputStr.split(" ");
|
|
951
|
+
if (match && match.length === 3) {
|
|
952
|
+
return {
|
|
953
|
+
name: match[1],
|
|
954
|
+
operator: match[2],
|
|
955
|
+
version: match[3],
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
return null;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
const pkgList = [];
|
|
962
|
+
const dependenciesList = [];
|
|
963
|
+
let rootPkg = {};
|
|
964
|
+
// This tracks the resolved version
|
|
965
|
+
const pkgNameVersionMap = {};
|
|
966
|
+
const pkgAddedMap = {};
|
|
967
|
+
|
|
968
|
+
if (!csProjData) {
|
|
969
|
+
return { pkgList, dependenciesList };
|
|
970
|
+
}
|
|
971
|
+
csProjData = JSON.parse(csProjData);
|
|
972
|
+
let purlString;
|
|
973
|
+
if (csProjData.project?.restore?.projectName) {
|
|
974
|
+
purlString = build({
|
|
975
|
+
type: "nuget",
|
|
976
|
+
namespace: "" || null,
|
|
977
|
+
name: csProjData.project?.restore?.projectName,
|
|
978
|
+
version: csProjData.project.version || "latest" || null,
|
|
979
|
+
});
|
|
980
|
+
rootPkg = {
|
|
981
|
+
group: "",
|
|
982
|
+
name: csProjData.project.restore.projectName,
|
|
983
|
+
version: csProjData.project.version || "latest",
|
|
984
|
+
type: "application",
|
|
985
|
+
purl: purlString,
|
|
986
|
+
"bom-ref": decodeURIComponent(purlString),
|
|
987
|
+
};
|
|
988
|
+
pkgList.push(rootPkg);
|
|
989
|
+
}
|
|
990
|
+
const rootPkgDeps = new Set();
|
|
991
|
+
// create root pkg deps
|
|
992
|
+
if (csProjData.targets && csProjData.projectFileDependencyGroups) {
|
|
993
|
+
for (const frameworkTarget in csProjData.projectFileDependencyGroups) {
|
|
994
|
+
for (const dependencyName of csProjData.projectFileDependencyGroups[
|
|
995
|
+
frameworkTarget
|
|
996
|
+
]) {
|
|
997
|
+
const nameOperatorVersion = extractNameOperatorVersion(dependencyName);
|
|
998
|
+
if (nameOperatorVersion == null) {
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
const targetNameVersion = `${nameOperatorVersion.name}/${nameOperatorVersion.version}`;
|
|
1002
|
+
let nameToUse = nameOperatorVersion.name;
|
|
1003
|
+
// Due to the difference in casing, we might arrive this case where a simple lookup doesn't succeed.
|
|
1004
|
+
// Instead of skipping, let's work harder to find a match.
|
|
1005
|
+
if (!csProjData.targets[frameworkTarget][targetNameVersion]) {
|
|
1006
|
+
let matchFound = false;
|
|
1007
|
+
for (const fkeys of Object.keys(
|
|
1008
|
+
csProjData.targets[frameworkTarget],
|
|
1009
|
+
)) {
|
|
1010
|
+
const tmpParts = fkeys.split("/");
|
|
1011
|
+
const tname = tmpParts[0];
|
|
1012
|
+
const tversion = tmpParts[1];
|
|
1013
|
+
if (
|
|
1014
|
+
tname.toLowerCase() === nameOperatorVersion.name.toLowerCase() &&
|
|
1015
|
+
tversion === nameOperatorVersion.version.replace("-*", "")
|
|
1016
|
+
) {
|
|
1017
|
+
nameToUse = tname;
|
|
1018
|
+
matchFound = true;
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
if (!matchFound) {
|
|
1023
|
+
if (DEBUG_MODE) {
|
|
1024
|
+
console.log(
|
|
1025
|
+
"Unable to match",
|
|
1026
|
+
dependencyName,
|
|
1027
|
+
"with a target name. The dependency tree will be imprecise.",
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
const dpurl = decodeURIComponent(
|
|
1035
|
+
build({
|
|
1036
|
+
type: "nuget",
|
|
1037
|
+
namespace: "" || null,
|
|
1038
|
+
name: nameToUse,
|
|
1039
|
+
version: nameOperatorVersion.version || null,
|
|
1040
|
+
}),
|
|
1041
|
+
);
|
|
1042
|
+
rootPkgDeps.add(dpurl);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (purlString && rootPkgDeps.size) {
|
|
1046
|
+
dependenciesList.push({
|
|
1047
|
+
ref: purlString,
|
|
1048
|
+
dependsOn: Array.from(rootPkgDeps).sort(),
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
if (csProjData.libraries && csProjData.targets) {
|
|
1054
|
+
const lib = csProjData.libraries;
|
|
1055
|
+
// Pass 1: Construct pkgList alone and track name and resolved version
|
|
1056
|
+
for (const framework in csProjData.targets) {
|
|
1057
|
+
for (const rootDep of Object.keys(csProjData.targets[framework])) {
|
|
1058
|
+
// if (rootDep.startsWith("runtime")){
|
|
1059
|
+
// continue;
|
|
1060
|
+
// }
|
|
1061
|
+
const [name, version] = rootDep.split("/");
|
|
1062
|
+
const dpurl = build({
|
|
1063
|
+
type: "nuget",
|
|
1064
|
+
namespace: "" || null,
|
|
1065
|
+
name: name,
|
|
1066
|
+
version: version || null,
|
|
1067
|
+
});
|
|
1068
|
+
const pkg = {
|
|
1069
|
+
group: "",
|
|
1070
|
+
name: name,
|
|
1071
|
+
version: version,
|
|
1072
|
+
description: "",
|
|
1073
|
+
type: csProjData.targets[framework][rootDep].type,
|
|
1074
|
+
purl: dpurl,
|
|
1075
|
+
"bom-ref": decodeURIComponent(dpurl),
|
|
1076
|
+
};
|
|
1077
|
+
if (lib[rootDep]) {
|
|
1078
|
+
if (lib[rootDep].sha512) {
|
|
1079
|
+
pkg["_integrity"] = `sha512-${lib[rootDep].sha512}`;
|
|
1080
|
+
} else if (lib[rootDep].sha256) {
|
|
1081
|
+
pkg["_integrity"] = `sha256-${lib[rootDep].sha256}`;
|
|
1082
|
+
}
|
|
1083
|
+
if (lib[rootDep].files && Array.isArray(lib[rootDep].files)) {
|
|
1084
|
+
const dllFiles = new Set();
|
|
1085
|
+
lib[rootDep].files.forEach((f) => {
|
|
1086
|
+
if (
|
|
1087
|
+
f.endsWith(".dll") ||
|
|
1088
|
+
f.endsWith(".exe") ||
|
|
1089
|
+
f.endsWith(".so")
|
|
1090
|
+
) {
|
|
1091
|
+
dllFiles.add(basename(f));
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
pkg.properties = [
|
|
1095
|
+
{
|
|
1096
|
+
name: "internal:SrcFile",
|
|
1097
|
+
value: assetsJsonFile,
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
name: "internal:PackageFiles",
|
|
1101
|
+
value: Array.from(dllFiles).join(", "),
|
|
1102
|
+
},
|
|
1103
|
+
];
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (assetsJsonFile) {
|
|
1107
|
+
pkg.evidence = {
|
|
1108
|
+
identity: {
|
|
1109
|
+
field: "purl",
|
|
1110
|
+
confidence: 1,
|
|
1111
|
+
methods: [
|
|
1112
|
+
{
|
|
1113
|
+
technique: "manifest-analysis",
|
|
1114
|
+
confidence: 1,
|
|
1115
|
+
value: assetsJsonFile,
|
|
1116
|
+
},
|
|
1117
|
+
],
|
|
1118
|
+
},
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
pkgList.push(pkg);
|
|
1122
|
+
pkgNameVersionMap[name + framework] = version;
|
|
1123
|
+
pkgAddedMap[name] = true;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
// Pass 2: Fix the dependency tree
|
|
1127
|
+
for (const framework in csProjData.targets) {
|
|
1128
|
+
for (const rootDep of Object.keys(csProjData.targets[framework])) {
|
|
1129
|
+
const depList = new Set();
|
|
1130
|
+
const [name, version] = rootDep.split("/");
|
|
1131
|
+
const dpurl = decodeURIComponent(
|
|
1132
|
+
build({
|
|
1133
|
+
type: "nuget",
|
|
1134
|
+
namespace: "" || null,
|
|
1135
|
+
name: name,
|
|
1136
|
+
version: version || null,
|
|
1137
|
+
}),
|
|
1138
|
+
);
|
|
1139
|
+
const dependencies =
|
|
1140
|
+
csProjData.targets[framework][rootDep].dependencies;
|
|
1141
|
+
if (dependencies) {
|
|
1142
|
+
for (const p of Object.keys(dependencies)) {
|
|
1143
|
+
// This condition is not required for assets json that are well-formed.
|
|
1144
|
+
if (!pkgNameVersionMap[p + framework]) {
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
const dversion = pkgNameVersionMap[p + framework];
|
|
1148
|
+
const ipurl = build({
|
|
1149
|
+
type: "nuget",
|
|
1150
|
+
namespace: "" || null,
|
|
1151
|
+
name: p,
|
|
1152
|
+
version: dversion || null,
|
|
1153
|
+
});
|
|
1154
|
+
depList.add(ipurl);
|
|
1155
|
+
if (!pkgAddedMap[p]) {
|
|
1156
|
+
pkgList.push({
|
|
1157
|
+
group: "",
|
|
1158
|
+
name: p,
|
|
1159
|
+
version: dversion,
|
|
1160
|
+
description: "",
|
|
1161
|
+
purl: ipurl,
|
|
1162
|
+
"bom-ref": decodeURIComponent(ipurl),
|
|
1163
|
+
});
|
|
1164
|
+
pkgAddedMap[p] = true;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
dependenciesList.push({
|
|
1169
|
+
ref: dpurl,
|
|
1170
|
+
dependsOn: Array.from(depList).sort(),
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return {
|
|
1176
|
+
pkgList,
|
|
1177
|
+
dependenciesList,
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* Parse a .NET packages.lock.json file and return the package list, dependency tree,
|
|
1183
|
+
* and list of direct/root dependencies.
|
|
1184
|
+
*
|
|
1185
|
+
* @param {string} csLockData Raw JSON string of the packages.lock.json file
|
|
1186
|
+
* @param {string} pkgLockFile Path to the packages.lock.json file, used for evidence properties
|
|
1187
|
+
* @returns {{ pkgList: Object[], dependenciesList: Object[], rootList: Object[] }}
|
|
1188
|
+
*/
|
|
1189
|
+
export function parseCsPkgLockData(csLockData, pkgLockFile) {
|
|
1190
|
+
const pkgList = [];
|
|
1191
|
+
const dependenciesList = [];
|
|
1192
|
+
const rootList = [];
|
|
1193
|
+
let pkg = null;
|
|
1194
|
+
if (!csLockData) {
|
|
1195
|
+
return {
|
|
1196
|
+
pkgList,
|
|
1197
|
+
dependenciesList,
|
|
1198
|
+
rootList,
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
const assetData = JSON.parse(csLockData);
|
|
1202
|
+
if (!assetData?.dependencies) {
|
|
1203
|
+
return {
|
|
1204
|
+
pkgList,
|
|
1205
|
+
dependenciesList,
|
|
1206
|
+
rootList,
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
for (const aversion of Object.keys(assetData.dependencies)) {
|
|
1210
|
+
for (const alib of Object.keys(assetData.dependencies[aversion])) {
|
|
1211
|
+
const libData = assetData.dependencies[aversion][alib];
|
|
1212
|
+
const purl = build({
|
|
1213
|
+
type: "nuget",
|
|
1214
|
+
namespace: "" || null,
|
|
1215
|
+
name: alib,
|
|
1216
|
+
version: libData.resolved || null,
|
|
1217
|
+
});
|
|
1218
|
+
pkg = {
|
|
1219
|
+
group: "",
|
|
1220
|
+
name: alib,
|
|
1221
|
+
version: libData.resolved,
|
|
1222
|
+
purl,
|
|
1223
|
+
"bom-ref": decodeURIComponent(purl),
|
|
1224
|
+
_integrity: libData.contentHash
|
|
1225
|
+
? `sha512-${libData.contentHash}`
|
|
1226
|
+
: undefined,
|
|
1227
|
+
properties: [
|
|
1228
|
+
{
|
|
1229
|
+
name: "internal:SrcFile",
|
|
1230
|
+
value: pkgLockFile,
|
|
1231
|
+
},
|
|
1232
|
+
],
|
|
1233
|
+
evidence: {
|
|
1234
|
+
identity: {
|
|
1235
|
+
field: "purl",
|
|
1236
|
+
confidence: 1,
|
|
1237
|
+
methods: [
|
|
1238
|
+
{
|
|
1239
|
+
technique: "manifest-analysis",
|
|
1240
|
+
confidence: 1,
|
|
1241
|
+
value: pkgLockFile,
|
|
1242
|
+
},
|
|
1243
|
+
],
|
|
1244
|
+
},
|
|
1245
|
+
},
|
|
1246
|
+
};
|
|
1247
|
+
pkgList.push(pkg);
|
|
1248
|
+
if (["Direct", "Project"].includes(libData.type)) {
|
|
1249
|
+
rootList.push(pkg);
|
|
1250
|
+
}
|
|
1251
|
+
const dependsOn = new Set();
|
|
1252
|
+
if (libData.dependencies) {
|
|
1253
|
+
for (let adep of Object.keys(libData.dependencies)) {
|
|
1254
|
+
let adepResolvedVersion = libData.dependencies[adep];
|
|
1255
|
+
const aversionNoRuntime = aversion.split("/")[0];
|
|
1256
|
+
// Try to get the resolved version of the dependency. See #930 and #937
|
|
1257
|
+
if (assetData.dependencies[aversion]?.[adep]?.resolved) {
|
|
1258
|
+
adepResolvedVersion =
|
|
1259
|
+
assetData.dependencies[aversion][adep].resolved;
|
|
1260
|
+
} else if (
|
|
1261
|
+
aversion.includes("/") &&
|
|
1262
|
+
assetData.dependencies[aversionNoRuntime]?.[adep]?.resolved
|
|
1263
|
+
) {
|
|
1264
|
+
adepResolvedVersion =
|
|
1265
|
+
assetData.dependencies[aversionNoRuntime][adep].resolved;
|
|
1266
|
+
} else if (
|
|
1267
|
+
(assetData.dependencies[aversion]?.[adep.toLowerCase()] &&
|
|
1268
|
+
assetData.dependencies[aversion][adep.toLowerCase()].type ===
|
|
1269
|
+
"Project") ||
|
|
1270
|
+
(assetData.dependencies[aversionNoRuntime]?.[adep.toLowerCase()] &&
|
|
1271
|
+
assetData.dependencies[aversionNoRuntime][adep.toLowerCase()]
|
|
1272
|
+
.type === "Project")
|
|
1273
|
+
) {
|
|
1274
|
+
adepResolvedVersion = undefined;
|
|
1275
|
+
adep = adep.toLowerCase();
|
|
1276
|
+
} else if (DEBUG_MODE) {
|
|
1277
|
+
console.warn(
|
|
1278
|
+
`Unable to find the resolved version for ${adep} ${aversion}. Using ${adepResolvedVersion} which may be incorrect.`,
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
const adpurl = build({
|
|
1282
|
+
type: "nuget",
|
|
1283
|
+
namespace: "" || null,
|
|
1284
|
+
name: adep,
|
|
1285
|
+
version: adepResolvedVersion || null,
|
|
1286
|
+
});
|
|
1287
|
+
dependsOn.add(decodeURIComponent(adpurl));
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
dependenciesList.push({
|
|
1291
|
+
ref: decodeURIComponent(purl),
|
|
1292
|
+
dependsOn: [...dependsOn].sort(),
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
return {
|
|
1297
|
+
pkgList,
|
|
1298
|
+
dependenciesList,
|
|
1299
|
+
rootList,
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Parse a Paket dependency manager lock file (paket.lock) and return the package list
|
|
1305
|
+
* and dependency tree.
|
|
1306
|
+
*
|
|
1307
|
+
* @param {string} paketLockData Raw text contents of the paket.lock file
|
|
1308
|
+
* @param {string} pkgLockFile Path to the paket.lock file, used for evidence properties
|
|
1309
|
+
* @returns {{ pkgList: Object[], dependenciesList: Object[] }}
|
|
1310
|
+
*/
|
|
1311
|
+
export function parsePaketLockData(paketLockData, pkgLockFile) {
|
|
1312
|
+
const pkgList = [];
|
|
1313
|
+
const dependenciesList = [];
|
|
1314
|
+
const dependenciesMap = {};
|
|
1315
|
+
const pkgNameVersionMap = {};
|
|
1316
|
+
let group = null;
|
|
1317
|
+
let pkg = null;
|
|
1318
|
+
if (!paketLockData) {
|
|
1319
|
+
return { pkgList, dependenciesList };
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
const packages = paketLockData.split("\n");
|
|
1323
|
+
const groupRegex = /^GROUP\s(\S*)$/;
|
|
1324
|
+
const pkgRegex = /^\s{4}([\w.-]+) \(((?=.*?\.)[\w.-]+)\)/;
|
|
1325
|
+
const depRegex = /^\s{6}([\w.-]+) \([><= \w.-]+\)/;
|
|
1326
|
+
|
|
1327
|
+
// Gather all packages
|
|
1328
|
+
packages.forEach((l) => {
|
|
1329
|
+
let match = l.match(groupRegex);
|
|
1330
|
+
if (match) {
|
|
1331
|
+
group = match[1];
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
match = l.match(pkgRegex);
|
|
1336
|
+
if (match) {
|
|
1337
|
+
const name = match[1];
|
|
1338
|
+
const version = match[2];
|
|
1339
|
+
const purl = build({
|
|
1340
|
+
type: "nuget",
|
|
1341
|
+
namespace: "" || null,
|
|
1342
|
+
name: name,
|
|
1343
|
+
version: version || null,
|
|
1344
|
+
});
|
|
1345
|
+
pkg = {
|
|
1346
|
+
group: "",
|
|
1347
|
+
name,
|
|
1348
|
+
version,
|
|
1349
|
+
purl,
|
|
1350
|
+
"bom-ref": decodeURIComponent(purl),
|
|
1351
|
+
properties: [
|
|
1352
|
+
{
|
|
1353
|
+
name: "internal:SrcFile",
|
|
1354
|
+
value: pkgLockFile,
|
|
1355
|
+
},
|
|
1356
|
+
],
|
|
1357
|
+
evidence: {
|
|
1358
|
+
identity: {
|
|
1359
|
+
field: "purl",
|
|
1360
|
+
confidence: 1,
|
|
1361
|
+
methods: [
|
|
1362
|
+
{
|
|
1363
|
+
technique: "manifest-analysis",
|
|
1364
|
+
confidence: 1,
|
|
1365
|
+
value: pkgLockFile,
|
|
1366
|
+
},
|
|
1367
|
+
],
|
|
1368
|
+
},
|
|
1369
|
+
},
|
|
1370
|
+
};
|
|
1371
|
+
pkgList.push(pkg);
|
|
1372
|
+
dependenciesMap[purl] = new Set();
|
|
1373
|
+
pkgNameVersionMap[name + group] = version;
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
|
|
1377
|
+
let purl = null;
|
|
1378
|
+
group = null;
|
|
1379
|
+
|
|
1380
|
+
// Construct the dependency tree
|
|
1381
|
+
packages.forEach((l) => {
|
|
1382
|
+
let match = l.match(groupRegex);
|
|
1383
|
+
if (match) {
|
|
1384
|
+
group = match[1];
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
match = l.match(pkgRegex);
|
|
1389
|
+
if (match) {
|
|
1390
|
+
const pkgName = match[1];
|
|
1391
|
+
const pkgVersion = match[2];
|
|
1392
|
+
purl = decodeURIComponent(
|
|
1393
|
+
build({
|
|
1394
|
+
type: "nuget",
|
|
1395
|
+
namespace: "" || null,
|
|
1396
|
+
name: pkgName,
|
|
1397
|
+
version: pkgVersion || null,
|
|
1398
|
+
}),
|
|
1399
|
+
);
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
match = l.match(depRegex);
|
|
1404
|
+
if (match) {
|
|
1405
|
+
const depName = match[1];
|
|
1406
|
+
const depVersion = pkgNameVersionMap[depName + group];
|
|
1407
|
+
const dpurl = decodeURIComponent(
|
|
1408
|
+
build({
|
|
1409
|
+
type: "nuget",
|
|
1410
|
+
namespace: "" || null,
|
|
1411
|
+
name: depName,
|
|
1412
|
+
version: depVersion || null,
|
|
1413
|
+
}),
|
|
1414
|
+
);
|
|
1415
|
+
dependenciesMap[purl].add(dpurl);
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
|
|
1419
|
+
for (const ref in dependenciesMap) {
|
|
1420
|
+
dependenciesList.push({
|
|
1421
|
+
ref: ref,
|
|
1422
|
+
dependsOn: Array.from(dependenciesMap[ref]).sort(),
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
return {
|
|
1427
|
+
pkgList,
|
|
1428
|
+
dependenciesList,
|
|
1429
|
+
};
|
|
1430
|
+
}
|