Production-grade guide to license compliance scanning covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.
License compliance scanning generates a machine-readable inventory of the software licenses accompanying your project's dependencies, then evaluates that inventory against organizational policy. It matters when you need to verify that embedded open source components satisfy legal obligations—copyleft detection for redistribution compliance, prohibited-license blocking for corporate policy, or audit trail generation for M&A due diligence. Unlike vulnerability scanning, which identifies security flaws in code, license scanning identifies the legal conditions under which that code may be used, modified, or distributed. The scan typically operates on a project directory, a container image, or a repository checkout, producing a Software Bill of Materials (SBOM) that lists each package, its version, and every license declaration attached to it.
The standard entry point is a tool that walks the dependency graph and outputs a structured inventory. syft, the Software Bill of Materials generator maintained by Anchore/Chainguard, is one widely deployed option. The basic invocation scans the current directory and writes a JSON SBOM to standard output:
syft . -o json > sbom.json
The same command produces CycloneDX or SPDX output with a format flag:
syft . -o cyclonedx > sbom.cdx.json
syft . -o spdx > sbom.spdx.json
Each package entry in the JSON includes a name, version, and an array under licenses. A typical package fragment looks like:
{
"name": "react",
"version": "18.2.0",
"licenses": [
{ "identifier": "MIT", "type": "MIT" }
]
}
For a Node.js project with a package.json, the same command resolves node_modules and produces entries for every direct and transitive dependency. For a Python project with a requirements.txt or pyproject.toml, syft reads the lockfile if present (poetry.lock, pipenv.lock) and generates corresponding entries. When no lockfile exists, syft still attempts resolution but may report unknown for versions that cannot be uniquely determined.
Filtering the SBOM to a single package is straightforward with jq:
jq '.packages[] | select(.name == "react")' sbom.json
To extract only the license identifiers across all packages:
jq -r '.packages[].licenses[].identifier' sbom.json | sort -u
This produces a deduplicated list such as MIT, Apache-2.0, GPL-3.0-only, ISC, etc.
Once the SBOM exists, the reader’s next task is usually policy evaluation: “which packages carry copyleft licenses?” or “which packages use a license on our prohibited list?” The SBOM format encodes licenses as identifiers drawn from the SPDX license list, so matching is a matter of string comparison against a known set.
A typical compliance filter in jq might look for any license containing “GPL”:
jq -r '.packages[].licenses[].identifier | select(test("GPL"))' sbom.json | sort -u
This returns identifiers like GPL-3.0-only, GPL-2.0-or-later, AGPL-3.0, etc. The test("GPL") regular expression matches any identifier with “GPL” as a substring, which covers the majority of copyleft variants.
For a more precise check—detecting only strong copyleft, excluding “or later” variants—you can anchor the pattern:
jq -r '.packages[].licenses[].identifier | select(test("GPL-[0-9]+-only"))' sbom.json | sort -u
This filters to GPL-2.0-only, GPL-3.0-only, and similar, excluding GPL-2.0-or-later or GPL-3.0-or-later.
Inverted screening—identifying packages with permissive licenses only—is equally direct:
jq -r '.packages[].licenses[].identifier | select(test("MIT|BSD|Apache-2.0|ISC"))' sbom.json | sort -u
Readers should note that jq's test operator uses POSIX extended regular expressions; flags like (?i) for case-insensitivity are not supported natively, so the pattern must account for the exact capitalization used in the SPDX identifier list.
When the SBOM includes a licenseConcluded field at the document level—some SBOM tools populate this with a synthesized conclusion—you can check it independently:
jq '.licenseConcluded' sbom.json
This might return "GPL-3.0-only" or "MIT" or "NOASSERTION" if the tool could not determine a single conclusion.
Integrating license compliance into a continuous integration pipeline ensures that policy violations block merges before code reaches production. A minimal GitHub Actions step using syft might look like this:
name: License Compliance Check
on: [pull_request]
jobs:
license-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Generate SBOM
run: syft . -o json > sbom.json
- name: Check for prohibited licenses
run: |
prohibited="GPL-3.0-only AGPL-3.0-only"
for lic in $prohibited; do
if jq -e ".packages[].licenses[].identifier | index(\"$lic\")" sbom.json > /dev/null 2>&1; then
echo "Prohibited license $lic detected"
exit 1
fi
done
The jq -e exit-status flag causes the step to fail if the identified license string appears in any package's license array. The loop iterates over a hard-coded list of prohibited identifiers; each iteration tests whether index finds that string within the per-package license arrays. If any match, jq -e returns exit code 1, the if branch prints a message, and the job exits with failure, blocking the pull request.
An alternative approach uses trivy, which includes license scanning as part of its container and filesystem scanning. The command:
trivy fs . --license
scans the local filesystem and reports license information alongside vulnerability results. The exit code reflects whether any licenses matched configured severity or type thresholds, though the exact behavior depends on the version and configuration. Readers should verify the exit-code semantics for their installed version, as they vary between releases.
For Git pre-commit hooks, syft can be invoked from a shell script checked into .git/hooks/pre-commit. A simplified version:
#!/bin/sh
sbom=$(syft . -o json)
if echo "$sbom" | jq -e '.packages[].licenses[].identifier | index("GPL-3.0-only")' > /dev/null 2>&1; then
echo "Blocking commit: GPL-3.0-only license detected"
exit 1
fi
exit 0
This script runs on every git commit, generating an SBOM and checking for the presence of a strong copyleft license. If found, the commit is rejected with a message. Note that this approach adds a few seconds to each commit; teams often reserve the full SBOM generation for CI runs and use a lighter-weight check in the hook.
Several behaviors catch teams off guard. First, license expressions that combine multiple terms with + or OR can produce unexpected matches. An identifier like GPL-3.0-only OR MIT is treated as a single string by most jq patterns; a simple select(test("GPL")) will match it, but a strict select(index("GPL-3.0-only")) will not, because the OR MIT suffix is part of the same string. Disambiguating requires parsing the expression, which lies outside the scope of simple identifier matching.
Second, packages declared under NOASSERTION or with no license field at all are easy to overlook. An SBOM may list a package with an empty licenses array, or with a single entry { "identifier": "NOASSERTION", "type": "NOASSERTION" }. Policy that assumes every package has an explicit license will silently ignore these entries, potentially missing packages that should be subject to review.
Third, transitive dependencies can inflate the SBOM beyond what the team expects. A project with a handful of direct dependencies may pull in hundreds of transitive packages, each with its own license declarations. The jq filters shown earlier scale to this cardinality without performance issues, but the resulting license list may be voluminous, and the manual review burden can be significant.
Fourth, SBOM format inconsistencies cause filter breakage. CycloneDX and SPDX representations of the same license may differ in casing, ordering of fields, or nested structure. A filter written against a CycloneDX SBOM may fail on an SPDX output from a different tool. Maintaining a single canonical format for policy evaluation—or normalizing between formats with a conversion step—reduces friction.
Fifth, license exceptions and supplementary declarations are common in large codebases. A package may carry GPL-3.0 WITH Classpath-exception-2.0, where the exception modifies the effective permissions. Most basic jq patterns treat this as a single identifier GPL-3.0 WITH Classpath-exception-2.0; a select(test("GPL")) match is correct, but a policy that simply blocks GPL-3.0-only will not catch this variant. Resolving the effective license often requires parsing the exception text, which most off-the-shelf scanners do not automate.
Finally, SBOM generation tools may omit packages that are not managed through a recognized package manager. Hand-rolled scripts, vendored code, or binaries installed outside a package manager’s manifest may not appear in the output. A scan that reports “no licenses found” does not guarantee compliance; it may simply reflect an incomplete dependency inventory. Verifying SBOM completeness against dep, pip list, go mod graph, or equivalent project-specific manifests is a recommended practice before relying on the scan results for compliance decisions.
This page was rewritten on 12 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy