fix(license): strip plus operator from SPDX exception identifiers#10394
fix(license): strip plus operator from SPDX exception identifiers#10394ogulcanaydogan wants to merge 1 commit intoaquasecurity:mainfrom
Conversation
The '+' (or-later) operator is only valid after a license identifier, not after an exception identifier per the SPDX spec. Trivy was generating invalid expressions like 'GPL-3.0-only WITH autoconf-exception+' because NormalizeForSPDX did not strip HasPlus from the right side of WITH clauses. This also caused the SPDX exception lookup to fail since the map keys don't include '+'. Fixes aquasecurity#7838
|
Hello @ogulcanaydogan
Can you reproduce this case? We added logic for searching SPDX license IDs and expressions from official lists. trivy/pkg/sbom/spdx/marshal_test.go Lines 1611 to 1625 in 33b9d8e |
|
Hi @DmitriyLewen — thanks for looking into this and for the pointer to the test cases! You're right. I tried to reproduce but couldn't get
The test case at marshal_test.go L1611-1625 confirms this behavior — non-SPDX exceptions get properly classified as It seems the bug from the original issue (Oct 2024) has been implicitly fixed by the SPDX expression normalization logic added since then. I'll close this PR. Thanks for the review! |
Description
Fixes invalid SPDX license expressions where the
+(or-later) operator was appended to exception identifiers inWITHclauses.Per the SPDX spec (Annex D), the
+operator is only valid after a license identifier, not an exception identifier. Trivy was generating expressions likeGPL-3.0-only WITH autoconf-exception+, which is invalid.Root Cause
In
NormalizeForSPDX, when handlingWITHexpressions, the right-hand side (exception) was not having itsHasPlusflag stripped. This caused two problems:spdxExceptionskeys don't include+.String()output included the invalid+suffix on the exceptionChanges
pkg/licensing/expression/expression.go: StripHasPlusfrom exceptionSimpleExprinNormalizeForSPDXwhen handlingWITHclauses. Also return the stripped expression even when the exception is not in the SPDX list.pkg/licensing/expression/expression_test.go: Add test cases for exception with+, exception with+(Bison), and exception without+(unchanged).Reproduction
Fixes #7838