docs: describe package digests and their sources (#11674)

This commit is contained in:
Nikita Pivkin authored and GitHub committed 2026-11-27 10:13:26 +00:00
1 parent f94c2ef220
commit e7c7720564
5 files changed
+105 -3

No files matched your search

+44 -2
View File
@@ -338,6 +338,43 @@ $ trivy image -f json -o results.json alpine:latest
"Target": "alpine:latest (alpine 3.20.3)",
"Class": "os-pkgs",
"Type": "alpine",
"Packages": [
{
"ID": "libssl3@3.3.2-r0",
"Name": "libssl3",
"Identifier": {
"PURL": "pkg:apk/alpine/libssl3@3.3.2-r0?arch=aarch64\u0026distro=3.20.3",
"UID": "c063faeb15a10ea8"
},
"Version": "3.3.2-r0",
"Arch": "aarch64",
"SrcName": "openssl",
"SrcVersion": "3.3.2-r0",
"Licenses": [
"Apache-2.0"
],
"Maintainer": "Natanael Copa \u003cncopa@alpinelinux.org\u003e",
"DependsOn": [
"libcrypto3@3.3.2-r0",
"musl@1.2.5-r0"
],
"Layer": {
"DiffID": "sha256:651d9022c23486dfbd396c13db293af6845731cbd098a5f5606db4bc9f5573e8"
},
"Digest": "sha1:5dd7435b217a4f82c2320879582d7c266a9c4b20",
"Digests": [
{
"Digest": "sha1:5dd7435b217a4f82c2320879582d7c266a9c4b20",
"Source": "apk-installed-db"
}
],
"InstalledFiles": [
"lib/libssl.so.3",
"usr/lib/libssl.so.3"
],
"AnalyzedBy": "apk"
}
],
"Vulnerabilities": [
{
"VulnerabilityID": "CVE-2024-9143",
@@ -345,7 +382,7 @@ $ trivy image -f json -o results.json alpine:latest
"PkgName": "libcrypto3",
"PkgIdentifier": {
"PURL": "pkg:apk/alpine/libcrypto3@3.3.2-r0?arch=aarch64\u0026distro=3.20.3",
"UID": "f705555b49cd2259"
"UID": "6046f49632a11363"
},
"InstalledVersion": "3.3.2-r0",
"FixedVersion": "3.3.2-r1",
@@ -397,7 +434,7 @@ $ trivy image -f json -o results.json alpine:latest
"PkgName": "libssl3",
"PkgIdentifier": {
"PURL": "pkg:apk/alpine/libssl3@3.3.2-r0?arch=aarch64\u0026distro=3.20.3",
"UID": "c4a39ef718e71832"
"UID": "c063faeb15a10ea8"
},
"InstalledVersion": "3.3.2-r0",
"FixedVersion": "3.3.2-r1",
@@ -454,6 +491,11 @@ $ trivy image -f json -o results.json alpine:latest
`VulnerabilityID`, `PkgName`, `InstalledVersion`, and `Severity` in `Vulnerabilities` are always filled with values, but other fields might be empty.
The `Digests` field of each package in `Packages` holds the [package digests](../supply-chain/package-digests.md).
!!! warning
The `Digest` field of a package is deprecated. Use `Digests` instead. `Digest` holds a single value without its source and is not filled for digests from newer sources, such as `go-module-h1`.
### SARIF
| Scanner | Supported |
|:----------------:|:---------:|
+1 -1
View File
@@ -131,7 +131,7 @@ It possibly produces false positives.
See [the caveat](#stdlib-vulnerabilities) for details.
## Module Checksums
Trivy records the h1 checksum of a Go module as a SHA-256 digest of the package with the `go-module-h1` source. For a replaced module, Trivy reports the replacement and its checksum. The h1 checksum is a SHA-256 hash over the list of the module files and their SHA-256 hashes, so it does not match the SHA-256 of the module zip file. See [go.sum files](https://go.dev/ref/mod#go-sum-files) for details.
Trivy records the h1 checksum of a Go module as a SHA-256 [digest](../../supply-chain/package-digests.md) of the package with the `go-module-h1` source. For a replaced module, Trivy reports the replacement and its checksum. The h1 checksum is a SHA-256 hash over the list of the module files and their SHA-256 hashes, so it does not match the SHA-256 of the module zip file. See [go.sum files](https://go.dev/ref/mod#go-sum-files) for details.
For Go modules, Trivy takes the checksum from the `go.sum` file next to `go.mod`. A module gets no checksum if `go.sum` has only its `/go.mod` line, because that line covers only the `go.mod` file of the module.
@@ -0,0 +1,20 @@
# Package Digests
Trivy reports the digests it collects for a package. Each digest has an algorithm, a value and a source. The source tells where Trivy got the value and which bytes the value covers. Two digests with the same algorithm can cover different bytes.
| Source | Algorithm | Where the value comes from | What the value covers |
|---|---|---|---|
| `rpm-sigmd5` | MD5 | The `SIGMD5` tag of the RPM database | The header and the payload of the `.rpm` file, without the signature header |
| `dpkg-available-sha256` | SHA-256 | The `SHA256` field of `/var/lib/dpkg/available` | The whole `.deb` file |
| `apk-installed-db` | SHA-1, or MD5 in old databases | The `C:` field of `/lib/apk/db/installed` or `/usr/lib/apk/db/installed` | The compressed control section of the `.apk` file |
| `java-archive` | SHA-1 | Trivy computes it | The whole JAR, WAR, EAR or PAR file, including a nested one |
| `file-content` | SHA-1 | Trivy computes it | The metadata file that Trivy read, such as `METADATA`, `PKG-INFO`, `package.json`, a `.gemspec` file or a conda meta file. It does not cover the package archive. |
| `go-module-h1` | SHA-256 | The `go.sum` file or the build info of a Go binary | The list of the module files and their SHA-256 hashes. It does not match the SHA-256 of the module zip file. See [Module Checksums](../coverage/language/golang.md#module-checksums). |
| `sbom` | As stated in the SBOM | An SBOM that Trivy scanned, found in the target or fetched with `--sbom-sources`, for a hash without a `SourcedDigest` record | Unknown |
| `unknown` | Any | A JSON report of an older Trivy version, such as one passed to `trivy convert` | Unknown |
Trivy computes `java-archive` and `file-content` digests only for the SBOM formats: `cyclonedx`, `spdx` and `spdx-json`. Trivy does not verify any of the digests.
A package has no digest when its source has no value for the installed version. For example, `/var/lib/dpkg/available` is not updated when a package is upgraded, so an upgraded Debian or Ubuntu package often has no `dpkg-available-sha256` digest.
See [JSON](../configuration/reporting.md#json) and [SBOM](sbom.md#package-digests) for how the digests appear in each format.
+39
View File
@@ -1740,6 +1740,45 @@ $ trivy image --format spdx-json --output result.spdx alpine:3.15
</details>
### Package Digests
Trivy writes the [package digests](package-digests.md) to CycloneDX `hashes` and SPDX `checksums`. These fields cannot hold the source of a digest, so Trivy writes it to the `aquasecurity:trivy:SourcedDigest` property in CycloneDX and to the `SourcedDigest` annotation in SPDX. The value has the `<source>:<algorithm>:<value>` form and refers to the hash with the same value. A hash without such a property has no known source.
```json
"hashes": [
{
"alg": "SHA-1",
"content": "237db0da53131e4548cb1181337fa0f420299e1f"
}
],
"properties": [
{
"name": "aquasecurity:trivy:SourcedDigest",
"value": "file-content:sha1:237db0da53131e4548cb1181337fa0f420299e1f"
}
]
```
In SPDX, if a package was read from its own file, such as a JAR or a metadata file, Trivy puts the digests of the package on the file element that the package contains, for example the `java-archive` and `file-content` digests. The `SourcedDigest` annotations stay on the package. Packages from lock files and binaries, such as `go.mod` or a Go binary, and OS packages have their digests in the package `checksums`. The annotation holds the value in `comment` after the `SourcedDigest: ` prefix.
```json
"checksums": [
{
"algorithm": "SHA1",
"checksumValue": "b1d943abdafd90a5481993600d7ea690f64c6871"
}
],
"annotations": [
{
"annotator": "Tool: trivy-dev",
"annotationDate": "2026-11-26T07:33:39Z",
"annotationType": "OTHER",
"comment": "SourcedDigest: apk-installed-db:sha1:b1d943abdafd90a5481993600d7ea690f64c6871"
}
]
```
When Trivy reads an SBOM, it restores the sources from these properties. The restored source is what the SBOM claims, and Trivy does not verify it. A hash without a property gets the `sbom` source.
## Scanning
### SBOM as Target
+1
View File
@@ -136,6 +136,7 @@ nav:
- Others: guide/configuration/others.md
- Supply Chain:
- SBOM: guide/supply-chain/sbom.md
- Package Digests: guide/supply-chain/package-digests.md
- Attestation:
- SBOM: guide/supply-chain/attestation/sbom.md
- Cosign Vulnerability Scan Record: guide/supply-chain/attestation/vuln.md