Skip to content

Commit 1a6f6a5

Browse files
committed
Add XSLT to add VEX references to SBOM
The XSLT adds an external reference of type 'vulnerability-assertion' to all the components in the `org.apache.logging.log4j` group. It also adds a `serialNumber` and converts the SBOM to version 1.5. Part of #1707.
1 parent eda71b3 commit 1a6f6a5

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

src/tools/add-sbom-references.xslt

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache license, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the license for the specific language governing permissions and
16+
~ limitations under the license.
17+
-->
18+
<!--
19+
To add external references run
20+
java -cp Xalan_bin_distribution_jars org.apache.xalan.xslt.Process \
21+
-IN pom.xml \
22+
-OUT pom.xml.out \
23+
-XSL this.file.xslt \
24+
-PARAM sbom.serialNumber e87ab1a5-3d29-48d5-82fa-211b7e913851
25+
-PARAM vdr.serialNumber 2496f0fa-91af-48cc-869f-ef1e03c97018
26+
-PARAM vdr.url https://logging.apache.org/log4j/vulnerabilities
27+
-->
28+
<xsl:stylesheet version="1.0"
29+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
30+
xmlns="http://cyclonedx.org/schema/bom/1.5"
31+
xmlns:xalan="http://xml.apache.org/xalan"
32+
xmlns:cdx14="http://cyclonedx.org/schema/bom/1.4"
33+
xmlns:cdx15="http://cyclonedx.org/schema/bom/1.5"
34+
exclude-result-prefixes="xalan cdx14 cdx15">
35+
<xsl:param name="sbom.serialNumber"/>
36+
<xsl:param name="vdr.serialNumber"/>
37+
<xsl:param name="vdr.url"/>
38+
<xsl:output method="xml"
39+
version="1.0"
40+
encoding="UTF-8"
41+
indent="yes"
42+
xalan:indent-amount="2"
43+
xalan:line-separator="&#10;"/>
44+
<!-- Fixes the license formatting -->
45+
<xsl:template match="/">
46+
<xsl:text>&#10;</xsl:text>
47+
<xsl:apply-templates />
48+
</xsl:template>
49+
<!-- Standard copy template -->
50+
<xsl:template match="@*|node()">
51+
<xsl:copy>
52+
<xsl:apply-templates select="@*" />
53+
<xsl:apply-templates />
54+
</xsl:copy>
55+
</xsl:template>
56+
<xsl:template match="cdx14:*">
57+
<xsl:element name="{local-name()}" namespace="http://cyclonedx.org/schema/bom/1.5">
58+
<xsl:apply-templates select="@*" />
59+
<xsl:apply-templates />
60+
</xsl:element>
61+
</xsl:template>
62+
<!-- Main element -->
63+
<xsl:template match="cdx14:bom">
64+
<bom>
65+
<xsl:attribute name="version">
66+
<xsl:value-of select="1"/>
67+
</xsl:attribute>
68+
<xsl:attribute name="serialNumber">
69+
<xsl:value-of select="$sbom.serialNumber"/>
70+
</xsl:attribute>
71+
<xsl:apply-templates select="cdx14:metadata|cdx14:components"/>
72+
<externalReferences>
73+
<reference>
74+
<xsl:attribute name="type">vulnerability-assertion</xsl:attribute>
75+
<url>
76+
<xsl:text>urn:cdx:</xsl:text>
77+
<xsl:value-of select="$vdr.serialNumber"/>
78+
</url>
79+
</reference>
80+
<reference>
81+
<xsl:attribute name="type">vulnerability-assertion</xsl:attribute>
82+
<url>
83+
<xsl:value-of select="$vdr.url"/>
84+
</url>
85+
</reference>
86+
</externalReferences>
87+
<xsl:apply-templates select="cdx14:dependencies"/>
88+
</bom>
89+
</xsl:template>
90+
<xsl:template match="cdx14:externalReferences[preceding-sibling::cdx14:group/text() = 'org.apache.logging.log4j']">
91+
<xsl:apply-templates/>
92+
<reference>
93+
<xsl:attribute name="type">vulnerability-assertion</xsl:attribute>
94+
<url>
95+
<xsl:text>urn:cdx:</xsl:text>
96+
<xsl:value-of select="$vdr.serialNumber"/>
97+
</url>
98+
</reference>
99+
<reference>
100+
<xsl:attribute name="type">vulnerability-assertion</xsl:attribute>
101+
<url>
102+
<xsl:value-of select="$vdr.url"/>
103+
</url>
104+
</reference>
105+
</xsl:template>
106+
</xsl:stylesheet>

0 commit comments

Comments
 (0)