@cdxgen/cdx-hbom

中文文档
0.8.0发布于 2026/11/06MITES Module零依赖构建来源已验证近 30 天下载 76.6万

Dependency-free hardware bill of materials discovery library.

原始使用文档
文档目录15 节
  1. Install
  2. npm
  3. JSR
  4. CLI
  5. Library usage
  6. Reading command diagnostics from the library
  7. CycloneDX 2.0 output
  8. Native enrichment currently covered
  9. Dry-run and trace support
  10. Linux
  11. Darwin arm64
  12. Windows ( win32/amd64 , win32/arm64 )
  13. Permissions
  14. Development
  15. License

cdx-hbom

cdx-hbom is a small, dependency-free Hardware Bill of Materials (HBOM) collector for CycloneDX BOM tools.

It currently supports following OS hosts:

  • darwin/arm64 (Apple Silicon Macs)
  • linux/amd64
  • linux/arm64
  • win32/amd64
  • win32/arm64

Install

npm

npm install @cdxgen/cdx-hbom

JSR

npx jsr add @cdxgen/cdx-hbom

CLI

Generate a hardware inventory for the current host:

npx @cdxgen/cdx-hbom --pretty > host-hbom.json

Common options:

  • --pretty pretty-print the JSON output
  • --dry-run block command execution and trace planned collection activity
  • --platform <value> override platform detection
  • --arch <value> override architecture detection
  • --sensitive include raw identifiers instead of redacted defaults
  • --no-command-enrichment disable optional command-based enrichment (Linux commands; on macOS the per-interface ifconfig and pmset calls are skipped; on Windows only the windows-cim-platform batch runs)
  • --privileged collect sources that need elevated rights. On Linux this enables privileged enrichment and explicit non-interactive sudo -n retries for documented permission-sensitive commands that opt in (currently drm_info). On Windows it adds the windows-cim-privileged batch (TPM, BitLocker, storage reliability counters, Confirm-SecureBootUEFI), which only administrators can read; cdx-hbom never elevates itself, so run it from an elevated session to get that data and expect permission-denied diagnostics otherwise
  • --plist-enrichment enable additional Darwin plist-based enrichment
  • --strict fail instead of returning partial results when enrichment fails
  • --spec-version <value> CycloneDX version to emit: 1.7 (default) or 2.0. The 2.0 output is described in CycloneDX 2.0 output
  • --timeout <ms> set per-command timeout

Examples:

npx @cdxgen/cdx-hbom --pretty
npx @cdxgen/cdx-hbom --privileged --pretty > host-hbom.json
npx @cdxgen/cdx-hbom --plist-enrichment --pretty > mac-hbom.json
npx @cdxgen/cdx-hbom --spec-version 2.0 --pretty > host-hbom-2.0.json

Library usage

import {
  collectHardware,
  createCollectorTrace,
  buildHardwareFromSources,
  getCollectorTrace,
  getCommandPlan,
} from "@cdxgen/cdx-hbom";

const trace = createCollectorTrace();

const bom = await collectHardware({
  dryRun: true,
  includePlistEnrichment: true,
  trace,
});

const collectedTrace = getCollectorTrace(bom) ?? trace;
console.log(collectedTrace.activities);

const plan = getCommandPlan({ platform: "linux", architecture: "amd64" });

// Some plan entries are templates; their final arguments are resolved per
// device or interface at runtime when live collection expands the plan.

const rebuilt = buildHardwareFromSources({
  platform: "linux",
  architecture: "amd64",
  sources: {
    osRelease: { NAME: "Ubuntu", VERSION_ID: "24.04" },
    cpuInfo: [{ processor: "0", "model name": "AMD Ryzen 7" }],
  },
});

Reading command diagnostics from the library

cdx-hbom keeps JSON output on the BOM itself and records optional command issues in the attached collector trace and BOM evidence properties.

import {
  collectHardware,
  createCollectorTrace,
  getCollectorTrace,
} from "@cdxgen/cdx-hbom";

const trace = createCollectorTrace();

const bom = await collectHardware({
  platform: "linux",
  architecture: "amd64",
  includeCommandEnrichment: true,
  includePrivilegedEnrichment: true,
  allowPartial: true,
  trace,
});

const collectedTrace = getCollectorTrace(bom) ?? trace;
const commandDiagnostics = collectedTrace.activities.filter(
  (entry) =>
    entry.kind === "command-diagnostic" || entry.kind === "command-warning",
);

for (const entry of commandDiagnostics) {
  if (entry.issue === "missing-command") {
    console.error(
      `Install hint for ${entry.command}: ${entry.hint ?? "see package docs"}`,
    );
  }

  if (entry.issue === "permission-denied") {
    console.error(
      `Privilege hint for ${entry.command}: ${entry.hint ?? "retry with --privileged"}`,
    );
  }
}

You can also read serialized command diagnostics from the BOM root by inspecting cdx:hbom:evidence:commandDiagnostic* properties.

CycloneDX 2.0 output

collectHardware({ specVersion: "2.0" }) and --spec-version 2.0 emit the CycloneDX 2.0 draft (CycloneDX/specification 2.0-dev at ea8c3605829d1da13339a0790b6da73548e42a6b). The collectors still build the 1.7 document; the 2.0 envelope is derived from it, so the 1.7 output does not change. In the 2.0 document:

  • the host component is inventories[0].subject and the other components are inventories[0].components; every bom-ref becomes refId
  • the tool entry carries version (left out when the package version cannot be read, for example in a bundle without package.json) and refId: "pkg:npm/@cdxgen/cdx-hbom" (the 1.7 tool entry stays { type, name })
  • manufacturer becomes a parties[] entry with the manufacturer role
  • cdx:hbom:hardwareClass becomes classification.category, and cdx:hbom:pciClassCode / cdx:hbom:usbClass become classification.codes entries ({ standard: "PCI-SIG class code" | "USB-IF class code", value })
  • the per-unit identifiers (serial-number, asset-tag, mac-address, imei) are emitted only when collection ran with includeSensitiveIdentifiers / --sensitive and the value is not a redaction marker. model-number names a product rather than a unit, so it is emitted whenever its value is not a redaction marker. A redaction marker is an empty value or one that starts with redacted or withheld, compared without case and surrounding whitespace (redacted, redacted:<last4>, redacted-serial, Withheld)
  • identifiers are asserted by the party-cdx-hbom party (role asserter, system kind automation, with system.ref set to the refId of the cdx-hbom tool entry, or no ref when the metadata has no such entry), which is declared in definitions.parties only when an identifier references it
  • boardLocation is not emitted: boardLocation.designators is reserved for PCB reference designators such as U5 or R12, so firmware slot labels such as DIMM3 stay in cdx:hbom:* properties
  • every cdx:hbom:* property is kept

Tools that render their own 2.0 documents, such as cdxgen, can reuse the mapping through the @cdxgen/cdx-hbom/cdx20 export:

import { mapCdx20HardwareComponent } from "@cdxgen/cdx-hbom/cdx20";

const { component, partyRefIds } = mapCdx20HardwareComponent(hbomComponent, {
  partyRefId: "party-cdxgen", // a declared party, never a tool refId
  includeSensitiveIdentifiers: false, // default; true only for --sensitive runs
});
// Existing identifiers (for example purl identities) are kept and the hardware
// identities are appended. Declare every refId in partyRefIds in
// definitions.parties.

The field-by-field table is in docs/hardware-properties.md.

Native enrichment currently covered

cdx-hbom uses a fixed command registry and array-based process spawning, but upstream wrappers and integrators are responsible for any stricter command allowlisting, PATH hardening, or execution policy controls around the collector process.

Dry-run and trace support

  • dryRun: true blocks command execution inside cdx-hbom itself instead of relying on a caller-side fallback.
  • getCommandPlan() exposes the static command registry, including template entries whose concrete arguments are resolved per device or interface at runtime.
  • Successful file reads and directory discovery, plus completed/blocked/failed command attempts, are recorded in the collector trace.
  • Pass trace: createCollectorTrace() to collect activity into a caller-owned ledger, or read it later via getCollectorTrace(bom).
  • The attached trace is non-enumerable, so JSON.stringify(bom) still emits a normal CycloneDX document.

Linux

  • /proc and /sys baseline discovery
  • CPU, memory, storage, PCI, USB, DRM display, audio, MMC/SDIO, and network inventory
  • USB device topology showing the hub hierarchy, with per-device driver, lanes, and interface drivers
  • USB-C connectors, electronically marked cables, and the peer on the far end from /sys/class/typec, with decoded data rate, current, delivery wattage, advertised power profiles, alternate modes, and charging verdicts
  • USB-C peers correlated to their enumerated USB device and power delivery node, and live charging readouts from the UCSI power supply when available
  • hwmon, thermal zones, TPM, and NVMe controller enrichment
  • optional command enrichment via lscpu, lsblk, ip, lsmem, hostnamectl, lspci, lsusb, ethtool, cpupower, drm_info, upower, fwupdmgr, boltctl, mmcli, and edid-decode
  • command diagnostics for missing utilities, partial support, and permission-sensitive enrichments

If you want to improve Linux enrichment coverage by installing the optional host tools, see linux-troubleshooting.md.

Darwin arm64

  • system_profiler hardware, storage, display, Wi-Fi, USB, audio, camera, Bluetooth, Thunderbolt, and power data
  • networksetup hardware-port mapping
  • live ifconfig network-interface enrichment
  • optional plist enrichment via diskutil, diskutil apfs list -plist, and ioreg

Windows (win32/amd64, win32/arm64)

Windows inventory comes from CIM/WMI classes and a few registry keys, read by the built-in Windows PowerShell 5.1 (%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe) running one fixed, single-line script per batch. The platform value emitted in the BOM is windows; --platform windows and --platform win32 both route to it. A Node os-module baseline (processor, memory, OS release) is always produced, so a host where PowerShell is blocked still yields a valid BOM.

The command ids and their sources (the list is checked against the registry by a test, and getCommandPlan({ platform: "win32" }) returns the full command lines):

  • windows-cim-platform: root/cimv2: Win32_ComputerSystem, Win32_ComputerSystemProduct, Win32_BIOS, Win32_BaseBoard, Win32_SystemEnclosure, Win32_Processor, Win32_PhysicalMemory, Win32_PhysicalMemoryArray, Win32_OperatingSystem; root/wmi: MS_SystemInformation
  • windows-cim-storage-network: root/Microsoft/Windows/Storage: MSFT_PhysicalDisk; root/cimv2: Win32_DiskDrive, Win32_Volume, Win32_NetworkAdapter; root/StandardCimv2: MSFT_NetAdapter, MSFT_NetAdapterHardwareInfoSettingData
  • windows-cim-display-media: root/cimv2: Win32_VideoController, Win32_SoundDevice, Win32_PnPEntity; root/wmi: WmiMonitorID, WmiMonitorBasicDisplayParams, WmiMonitorConnectionParams
  • windows-pnp-devices: root/cimv2: Win32_PnPEntity, Win32_PnPSignedDriver; Get-PnpDevice -PresentOnly and Get-PnpDeviceProperty (DEVPKEY_Device_Parent, DEVPKEY_Device_LocationPaths, DEVPKEY_Device_DriverVersion, DEVPKEY_Device_DriverProvider, DEVPKEY_Device_DriverDate, DEVPKEY_Device_BusReportedDeviceDesc, DEVPKEY_Device_BusNumber, DEVPKEY_Device_Address)
  • windows-cim-trust: root/Microsoft/Windows/DeviceGuard: Win32_DeviceGuard; root/cimv2: Win32_Battery; registry HKLM:\SYSTEM\CurrentControlSet\Control\SecureBoot\State (UEFISecureBootEnabled); registry subkeys of HKLM:\SYSTEM\CurrentControlSet\Control\FirmwareResources (LastAttemptStatus, LastAttemptVersion, Version)
  • windows-cim-privileged: root/cimv2/Security/MicrosoftTpm: Win32_Tpm; root/cimv2/Security/MicrosoftVolumeEncryption: Win32_EncryptableVolume; root/Microsoft/Windows/Storage: MSFT_StorageReliabilityCounter; cmdlet Confirm-SecureBootUEFI

Component coverage: host metadata, processor, memory and memory modules, board, firmware (BIOS) and chassis; storage (Win32_DiskDrive enriched from MSFT_PhysicalDisk) and volumes; network and wireless adapters; display adapters and monitors; audio controllers and endpoints; cameras; USB controllers and devices, PCI devices and Bluetooth radios and devices with driver versions and signing and a parent/child dependencies graph; TPM, firmware (ESRT) devices and batteries; and a host security posture (virtualization-based security, code integrity, Secure Boot, BitLocker per volume with --privileged). Property names are documented in docs/hardware-properties.md.

Option semantics on Windows:

  • --privileged adds the windows-cim-privileged batch (TPM, BitLocker, storage reliability counters, Confirm-SecureBootUEFI). Those classes deny non-administrators; cdx-hbom never elevates, never calls sudo.exe and never prompts, so run it from an elevated session to get the data. Without elevation the batch records permission-denied diagnostics and the run still succeeds.
  • --no-command-enrichment keeps only windows-cim-platform (and the Node baseline).
  • --dry-run produces the Node baseline only and traces every planned PowerShell command as blocked.
  • --plist-enrichment does not apply to Windows.
  • --timeout <ms> overrides the per-batch timeouts (60 s per CIM batch, 90 s for windows-pnp-devices).
  • When powershell.exe cannot start (missing, blocked by AppLocker, WDAC or the command allowlist) or runs in Constrained Language Mode, the device inventory comes from pnputil /enum-devices /connected /relations /drivers and a windows-fallback partial-support diagnostic is recorded. pnputil labels are localized, so a non-English host gets the Node baseline only. The fallback command is not in the command plan; an allowlist must name pnputil.exe to permit it.
  • Command allowlist entries match Windows commands case-insensitively (POWERSHELL.EXE allows powershell.exe); POSIX commands match exactly.

Permissions, PowerShell restrictions, EDR allowlisting, slow providers and the x64-on-ARM64 case are covered in windows-troubleshooting.md.

Permissions

Short answer: run cdx-hbom as a normal local user. That gives nearly the whole hardware inventory on every supported OS. Elevation (administrator or root) adds a few security- and health-related details. cdx-hbom never prompts for a password and never elevates on Windows; on Linux, --privileged retries a few documented commands with non-interactive sudo -n.

PlatformNormal user, local sessionAdministrator or rootNon-admin over SSH or WinRM
macOS (Apple Silicon)Full inventory; every collector command runs as a normal userNothing extraNot measured; expected same as local
Linux/proc and /sys baseline plus the optional tools that are installed--privileged runs dmidecode and retries drm_info with non-interactive sudo -n (see linux-troubleshooting.md)Not measured; expected same as local
WindowsNearly everything; see the measured matrix in windows-troubleshooting.md--privileged adds TPM details, BitLocker status, the firmware-confirmed Secure Boot state and disk reliability countersEvery WMI query is denied; only the baseline (processors and memory) is produced, with one permission-denied diagnostic that says why. Granting the account WMI "Remote Enable" on five namespaces restores most of the local inventory (see the troubleshooting page)

On Windows one more detail depends on state rather than rights: disk bus type, media type and health (MSFT_PhysicalDisk) reach a standard user only while the Storage Spaces SMP service (smphost) is already running. This is explained in the troubleshooting page.

Privacy defaults on every platform: serial numbers, UUIDs, MAC addresses and PnP instance segments are redacted to redacted:<last 4>; host names, user names and domain names are never collected. Pass --sensitive only when raw identifiers are needed.

Development

npm test

License

MIT

版本与发布记录

@cdxgen/cdx-hbom 共发布 9 个版本,首次发布于 2026/05/13;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.8.0latest2026/11/062 天前
0.7.02026/10/2119 天前
0.6.02026/10/2019 天前
0.5.12026/06/154 个月前
0.5.02026/05/145 个月前
0.4.02026/05/145 个月前

关于 @cdxgen/cdx-hbom 的常见问题

@cdxgen/cdx-hbom 是什么?

Dependency-free hardware bill of materials discovery library.

如何安装 @cdxgen/cdx-hbom?

在项目目录运行 npm install @cdxgen/cdx-hbom,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 cdx-hbom,可以用 npx cdx-hbom 直接运行。

@cdxgen/cdx-hbom 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cdxgen__cdx-hbom 是否存在。

@cdxgen/cdx-hbom 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cdxgen/cdx-hbom 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cdxgen/cdx-hbom 可以商用吗?

@cdxgen/cdx-hbom 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cdxgen/cdx-hbom 的下载量有多少?

根据 npm 官方下载统计,@cdxgen/cdx-hbom 在 2026/10/10 – 2026/11/08 这 30 天内被下载 766,053 次,日均约 25,535 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cdxgen/cdx-hbom 还在维护吗?

最新版本 0.8.0 发布于 2026/11/06(2 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/05/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。