* fix(python): find license files under .dist-info/licenses (PEP 639)
PEP 639 (Metadata-Version 2.4) places license files in a licenses/
subdirectory of .dist-info. When a package declares no License or
License-Expression, the RECORD fallback only considered files directly
in .dist-info, so these packages were reported with no license.
Accept RECORD entries anywhere under .dist-info/licenses/ as license
file candidates as well.
See #4292
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tore Martin Hagen <tore@kosli.com>
* fix(python): resolve every declared License-File, including under licenses/
License-File may appear several times, but it was parsed as a single
value, so only the last entry was kept. Its path was also joined to the
metadata directory only, while PEP 639 (Metadata-Version 2.4) makes it
relative to .dist-info/licenses/. Packages without a RECORD entry for the
file therefore got no license.
Keep every License-File entry, and look each one up in the metadata
directory and then under licenses/. Entries whose names don't look like
license files (e.g. AUTHORS) are skipped, as the RECORD fallback already
does, so they don't show up as unidentified licenses.
Also cover isDistInfoLicenseCandidate with a table test, and use real
hashes in the PEP 639 fixture's RECORD.
See #4292
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tore Martin Hagen <tore@kosli.com>
---------
Signed-off-by: Tore Martin Hagen <tore@kosli.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(binary): name ppc64 snippets in the snippet tool
getPlatformElf had no case for EM_PPC64, so write-snippet put ppc64le
snippets in a linux-unknown-... directory. Map EM_PPC64 to ppc64le, or to
ppc64 for big-endian files, so the julia ppc64le snippets in the next
commit get the right platform name.
Refs #5061
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: 26wv <202799601+26wv@users.noreply.github.com>
* fix(binary): detect julia on linux/arm64, ppc64le and 1.9.0 betas
The julia classifier found no package in the official julia images for
linux/arm64 and linux/ppc64le, or for 1.9.0-beta2/beta3.
In libjulia-internal.so the version string sits between other read-only
strings. On arm64 and ppc64le those strings are separated by runs of NULs
rather than a single NUL (e.g. `1.11.6\0\0branch\0\0` on ppc64le), and in
1.9.0-beta2/beta3 the version comes right before `__init__`. The julia
patterns expected single NULs and fixed neighbours, so none matched.
Replace the first two patterns with one that anchors only on the token
after the version (`branch`, `verify_methods` or `__init__`) and accepts
one or more NULs before it. Its major version is a single digit because on
ppc64le 1.9.0-beta3 a run of ASCII '0's precedes the version, which a
`[0-9]+` major would swallow.
Let the 1.9.0-alpha1 and 1.8.5 patterns accept NUL runs after the version.
On arm64 the 1.9.0-alpha1 version is not next to a NUL-delimited
`verify_methods` and another string sits before `BigInt`, so that pattern
now anchors on the NUL before the version and allows one string before
`BigInt`.
In the older julia classifier, which finds libjulia.so through the julia
executable, let the `julia version` pattern accept NUL runs too and add the
same BigInt pattern, so 1.0-1.5 are detected on arm64 and ppc64le. That
classifier only runs against full binaries, so these cases were checked by
scanning the official images rather than with new test cases.
Add config.yaml entries (per-platform digests) and tool-generated snippets
for 1.12.4 arm64, 1.11.6 ppc64le, 1.10.4 arm64, 1.9.0-beta2/beta3 amd64,
1.9.0-beta3 ppc64le, 1.8.5 arm64 and 1.9.0-alpha1 arm64, plus test cases
for them and for the existing 1.13.0-beta3 amd64 snippet, which only the
removed `branch` pattern matched.
Fixes#5061
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: 26wv <202799601+26wv@users.noreply.github.com>
The bun-binary classifier's first pattern accepted an optional "v", so in
compiled executables that embed text such as "bun 1.0.0 to 1.3.9" before
the runtime banner it reported the old version. Match the "Bun v1.2.3"
banner first, then "bun-1.2.3", and keep "bun 1.2.3" as the last fallback.
Fixes#5553
Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
namePattern required at least two characters, so a pinned line like
"q==2.7" (the format pip freeze writes) didn't match and the package was
dropped from the SBOM. PEP 508 allows one-character names (q, a, j and
others exist on PyPI).
Signed-off-by: protonnegativo <protonnegativo@users.noreply.github.com>
Co-authored-by: protonnegativo <protonnegativo@users.noreply.github.com>
The ffmpeg-library classifier fell back to the Lavc/Lavf idents when a library had no "FFmpeg version" string. Those idents carry the libavcodec/libavformat API version, not the FFmpeg release, which produced versions such as ffmpeg@62.28.102 with a matching ffmpeg CPE. Only use the FFmpeg release string, as the libswresample classifier already does.
Fixes#5548
Signed-off-by: Rudra184 <bhattrudra235@gmail.com>
Test_safeFileModeConvert declared two cases as int(math.MaxInt32) + 1 and
int(math.MinInt32) - 1. Those are constants that do not fit in an int where int
is 32 bits wide, so the package did not compile on 386.
On such a platform no int value lies outside the int32 range, so the two cases
cannot be built there. They now come from int64 variables, appended only where
int is wider than int32, which keeps both cases on 64-bit.
Signed-off-by: Juan Manuel Méndez Rey <juan.mendezr@proton.me>
Motivation: when gsha256sum, sha256sum and shasum are all absent but openssl
is available, install.sh fails checksum verification. The fallback ran
`openssl -dst openssl dgst -sha256`, which is an invalid command, and would
also have failed on `cut -d ' ' -f a`, an invalid field argument. The
installer exits 1 and installs nothing; checksum verification is not bypassed.
Approach: call `openssl dgst -sha256 "$TARGET"` and take the digest as the
last space-separated token of its "SHA256(file)= <digest>" output
(also "SHA2-256(...)" on OpenSSL 3.x), using POSIX parameter expansion.
Validation: added test_hash_sha256_openssl in test/install/0_checksums_test.sh,
which overrides is_command so only openssl is found and checks the digest of
the fixture archive (file and stdin). Running `sh 0_checksums_test.sh` in
test/install fails on the test before the change ("Invalid command '-dst'")
and passes after. Run on macOS with the system openssl only; the full
installer run from the issue and the container-based make targets were not run.
Report: https://github.com/anchore/syft/issues/5520
Assisted-by: claude-sonnet-5-5 (via Claude Code)
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Co-authored-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
* feat(executable): capture GNU ELF build IDs
Capture GNU ELF build IDs in Syft JSON so consumers can correlate
otherwise unidentified binaries with known artifacts or build records.
Read GNU build-ID notes from .note.gnu.build-id, with a 64 KiB read limit.
Validate the note owner and type before recording the identifier.
Add focused extraction and JSON round-trip tests and update the schema.
Signed-off-by: Mario Corchero <mcorcherojim@bloomberg.net>
* chore: bump JSON schema to 16.1.13 for executable identifiers
16.1.12 landed on main for coordinate fullPath, so the identifiers
addition moves to the next version.
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* feat(executable): capture go build IDs from .note.go.buildid
The go linker only writes a GNU build ID with -B or when linking
externally, so most pure-Go binaries had no identifier. Every go ELF
carries .note.go.buildid, captured as kind `go-build-id` in the form
`go tool buildid` prints.
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* docs(executable): describe identifiers generically
Identifier field docs (and the published schema) now give GNU hex and
Go build IDs as examples instead of stating every value is a GNU build
ID in lowercase hex, so the contract holds as more kinds are added.
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* fix(executable): keep identifier notes inside elfutil bounds
Register `.note.gnu.build-id` and `.note.go.buildid` in elfutil's
sectionsReadByName as that list asks, and never open a compressed
identifier note. Real ones are SHF_ALLOC and cannot be compressed, so
this drops the only decompression path into these reads.
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* test(executable): check identifiers from real linker output
Cross-compiles a tiny go program with `-B` so the test sees a GNU
build ID and a go build ID written by an actual linker and read through
the cataloger entrypoint.
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
---------
Signed-off-by: Mario Corchero <mcorcherojim@bloomberg.net>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
* perf: keep only the image squash when scanning with the squashed scope
- stereoscope builds a squashed tree for every layer, each a full copy of the one below, so memory
grows with layers x files. The squashed scope only ever reads the top one.
- new `GetSourceConfig.WithImageSquashOnly(bool)` (and `sourceproviders.Config` field) reads images
with stereoscope's `image.WithImageSquashOnly`, scoped to that one read
- the CLI turns it on when `--scope squashed` (the default)
- an image source read this way returns an error from `FileResolver` for `all-layers` and
`deep-squashed` instead of panicking on the missing layer squashes
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* chore(deps): temporarily pin stereoscope to anchore/stereoscope#731
Replaces stereoscope with the PR head on the contributor fork so this builds. Drop the replace and
bump to a released version once that PR merges.
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* chore(deps): bump stereoscope to main for WithImageSquashOnly
Drops the temporary replace to the contributor fork now that anchore/stereoscope#731 has merged.
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* revert: drop the squash-only image read and bump stereoscope
stereoscope is replacing `image.WithImageSquashOnly` with lazy layer squashes, where every layer keeps a usable squash. That removes the need for `GetSourceConfig.WithImageSquashOnly` and the scope guard in `FileResolver`, so both go.
- bumps stereoscope to `feat/lazy-layer-squashes` (anchore/stereoscope `43c8f7e`), pending that PR merging
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* perf: build lower layer squashes only when a scan reads them
The image source provider now reads images with `image.WithLazyLayerSquashes`: the image squash is built during the read, and each lower layer's squash only when something reads it. A squashed scan never does, so it skips a full file tree copy per layer.
- squashed scans: faster, much less memory on images with many layers
- `scan`/`attest` with all-layers or deep-squashed stay eager (an internal ctx flag), since eager squashing overlaps with fetching and indexing and is faster when every layer gets read
- library callers going through `syft.GetSource` get lazy for every scope, since the scope isn't known when the image is read. All-layers is still correct, just slower
- no public API change
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* pull in stereoscope@main
Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>
---------
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>
Co-authored-by: Will Murphy <willmurphyscode@users.noreply.github.com>
* fix: generate terraform-provider-specific CPEs for terraform lock packages
The terraform-lock-cataloger sets Language to Go, which causes the Go CPE
heuristic to generate application-level CPEs for terraform providers. For
example, registry.terraform.io/grafana/grafana produces the same CPE as
the Grafana application itself, leading grype to flag providers with
unrelated CVEs.
This adds terraform-specific vendor/product candidate functions that
generate CPEs matching the NVD convention for terraform providers
(e.g. terraform-provider-grafana instead of grafana), with terraform
as the target software qualifier.
Signed-off-by: Tim Olshansky <456103+timols@users.noreply.github.com>
* fix: align terraform provider CPEs with NVD terraform_provider convention
NVD records terraform providers with a fixed "terraform_provider" product
and the provider type in target_sw, e.g.
cpe:2.3:a:hashicorp:terraform_provider:*:*:*:*:*:vault:*:*
Generate <namespace>:terraform_provider:<version>:...:<type> instead of
<namespace>:terraform-provider-<type>:<version>:...:terraform, which never
appears in NVD.
Signed-off-by: Tim Olshansky <456103+timols@users.noreply.github.com>
---------
Signed-off-by: Tim Olshansky <456103+timols@users.noreply.github.com>
A msrc-kb package's name is an MSRC product ID and its version a KB
number, so the generic generator produced CPEs such as
cpe:2.3:a:12437:12437:935509:*:*:*:*:*:*:*. A KB is a patch rather than
a product and has no CPE representation; these packages are matched
against MSRC data by name and version. Skip generation for them, as is
already done for ML model packages. The dictionary lookup already
returns nothing for this type.
Signed-off-by: juanjsebgarcia <github@juangarcia.co.uk>
* build source PURL from metadata and gate it to CycloneDX 1.6+
- the source PURL is built from package metadata instead of editing the binary PURL: only `distro` (plus `epoch` and `rpmmod` for rpm) is carried over, subpath is dropped, and the ref is skipped when the PURL type does not match the metadata ecosystem
- one emission rule for all ecosystems: only when the source name or version differs from the binary, so self-sourced rpm and alpm packages no longer get a redundant ref
- source RPM names must end in `.src.rpm` or `.nosrc.rpm`, and `nosrc` maps to `arch=nosrc`
- `source-distribution` refs are dropped when encoding below spec 1.6, since cyclonedx-go does not downgrade them (CycloneDX/cyclonedx-go#291)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* limit source-distribution refs to deb and rpm
- apk origins and alpm pkgbases are build recipes, not published source packages, and their names are usually also real binary packages, so a `source-distribution` ref there would point at a binary package. They keep relying on the `upstream` PURL qualifier.
- document why this is an external reference rather than `pedigree.ancestors`, with links to the CycloneDX spec discussion (CycloneDX/specification#612)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
---------
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* fix: stop unbounded recursion decoding self-referencing CycloneDX metadata
SafeTensorsModelInfo and GGUFFileHeader both carry a Parts field that is a
slice of their own type. When a CycloneDX component with that metadata is
decoded from properties, the slice decoder tries element 0, which decodes a
struct whose Parts slice tries element 0 one level deeper, and so on. The
recursion never finds a base case, building longer property-name prefixes
on every level, so memory grows until the process is killed (seen in
grype on any machine-learning-model component written by syft).
Return early from struct decoding when no property is named by the prefix
or nested below it: none of the fields could be decoded anyway, and the
recursion is now bounded by the depth of the properties that exist.
Refs anchore/grype#3767
Signed-off-by: Vamshidher Reddy Jannapu Reddy <v.jannapu@gmail.com>
* perf: look up nested CycloneDX property names in a sorted index
The struct check added in the previous commit scanned every property of a
component for every struct it decoded. Decoding a slice of structs, such as
a package's locations, does that once per element, so a component with n
properties took O(n^2): 20,000 location properties took 5.3s to decode
instead of 18ms, a cost that an untrusted SBOM can choose.
Sort the property names once per Decode/DecodeInto call and binary-search
them instead. The result of each check is unchanged; decoding is back to
O(n log n) (27ms for the same 20,000 properties).
Refs anchore/grype#3767
Signed-off-by: Vamshidher Reddy Jannapu Reddy <v.jannapu@gmail.com>
---------
Signed-off-by: Vamshidher Reddy Jannapu Reddy <v.jannapu@gmail.com>