Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata filtering for tool in sbom #113

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

plugins {
id 'java-gradle-plugin'
id 'com.gradle.plugin-publish' version '0.12.0'
Expand All @@ -18,7 +17,6 @@ dependencies {
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
}
compile 'commons-codec:commons-codec:1.15'
compile 'commons-io:commons-io:2.8.0'
compile 'org.apache.maven:maven-core:3.5.0'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severe OSS Vulnerability:

pkg:maven/org.apache.maven/[email protected]

0 Critical, 1 Severe, 1 Moderate, 0 Unknown vulnerabilities have been found across 1 dependencies

Components
    pkg:maven/com.google.guava/[email protected]
      SEVERE Vulnerabilities (1)

        [CVE-2018-10237] Deserialization of Untrusted Data

        Unbounded memory allocation in Google Guava 11.0 through 24.x before 24.1.1 allows remote attackers to conduct denial of service attacks against servers that depend on this library and deserialize attacker-provided data, because the AtomicDoubleArray class (when serialized with Java serialization) and the CompoundOrdering class (when serialized with GWT serialization) perform eager allocation without appropriate checks on what a client has sent and whether the data size is reasonable.

        CVSS Score: 5.9

        CVSS Vector: CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H

      MODERATE Vulnerabilities (1)

        [CVE-2020-8908] A temp directory creation vulnerability exists in all versions of Guava, allowin...

        A temp directory creation vulnerability exists in all versions of Guava, allowing an attacker with access to the machine to potentially access data in a temporary directory created by the Guava API com.google.common.io.Files.createTempDir(). By default, on unix-like systems, the created directory is world-readable (readable by an attacker with access to the system). The method in question has been marked @deprecated in versions 30.0 and later and should not be used. For Android developers, we recommend choosing a temporary directory API provided by Android, such as context.getCacheDir(). For other Java developers, we recommend migrating to the Java 7 API java.nio.file.Files.createTempDirectory() which explicitly configures permissions of 700, or configuring the Java runtime's java.io.tmpdir system property to point to a location whose permissions are appropriately configured.

        CVSS Score: 3.3

        CVSS Vector: CVSS:3.0/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N

(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)


testImplementation gradleTestKit()
Expand All @@ -37,6 +35,22 @@ tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

def pluginProperties = [
'vendor': 'CycloneDX',
'name': 'CycloneDX Gradle plugin',
'version': project.version,
'groupId': project.group,
'artifactId': project.name,
] as Properties

def filterPluginProperties = tasks.register('filterPluginProperties', Copy) {
destinationDir = file("$buildDir/resources/filter")
inputs.properties pluginProperties
from('src/main/filter')
expand(pluginProperties)
}
sourceSets.main.resources.srcDirs filterPluginProperties

pluginBundle {
website = 'https://cyclonedx.org'
vcsUrl = 'https://github.com/CycloneDX/cyclonedx-gradle-plugin.git'
Expand Down
7 changes: 7 additions & 0 deletions src/main/filter/cyclonedx-gradle-plugin.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Automatically populated by Gradle build - do not modify
vendor=${vendor}
name=${name}
version=${version}
groupId=${groupId}
artifactId=${artifactId}
timestamp=${System.currentTimeMillis()}
39 changes: 17 additions & 22 deletions src/main/java/org/cyclonedx/gradle/CycloneDxTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.github.packageurl.MalformedPackageURLException;
import com.github.packageurl.PackageURL;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -55,6 +54,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -279,9 +280,9 @@ protected Metadata createMetadata() {
private Properties readPluginProperties() {
final Properties props = new Properties();
try {
props.load(this.getClass().getClassLoader().getResourceAsStream("plugin.properties"));
props.load(this.getClass().getClassLoader().getResourceAsStream("cyclonedx-gradle-plugin.properties"));
} catch (NullPointerException | IOException e) {
getLogger().warn("Unable to load plugin.properties", e);
getLogger().warn("cyclonedx-gradle-plugin.properties", e);
}
return props;
}
Expand Down Expand Up @@ -395,15 +396,15 @@ private void writeXMLBom(final CycloneDxSchema.Version schemaVersion, final Bom
final String bomString = bomGenerator.toXmlString();
final File bomFile = new File(buildDir, "reports/bom.xml");
getLogger().info(MESSAGE_WRITING_BOM_XML);
FileUtils.write(bomFile, bomString, StandardCharsets.UTF_8, false);
Files.createDirectories(bomFile.getParentFile().toPath());
Files.write(bomFile.toPath(), bomString.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
getLogger().info(MESSAGE_VALIDATING_BOM);
final Parser bomParser = new XmlParser();
try {
if (!bomParser.isValid(bomFile, schemaVersion)) {
throw new GradleException(MESSAGE_VALIDATION_FAILURE);
}
} catch (Exception e) { // Changed to Exception.
// Gradle will erroneously report "exception IOException is never thrown in body of corresponding try statement"
} catch (IOException e) {
throw new GradleException(MESSAGE_VALIDATION_FAILURE, e);
}
}
Expand All @@ -413,37 +414,31 @@ private void writeJSONBom(final CycloneDxSchema.Version schemaVersion, final Bom
final String bomString = bomGenerator.toJsonString();
final File bomFile = new File(buildDir, "reports/bom.json");
getLogger().info(MESSAGE_WRITING_BOM_JSON);
FileUtils.write(bomFile, bomString, StandardCharsets.UTF_8, false);
Files.createDirectories(bomFile.getParentFile().toPath());
Files.write(bomFile.toPath(), bomString.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
getLogger().info(MESSAGE_VALIDATING_BOM);
final Parser bomParser = new JsonParser();
try {
if (!bomParser.isValid(bomFile, schemaVersion)) {
throw new GradleException(MESSAGE_VALIDATION_FAILURE);
}
} catch (Exception e) { // Changed to Exception.
// Gradle will erroneously report "exception IOException is never thrown in body of corresponding try statement"
} catch (IOException e) {
throw new GradleException(MESSAGE_VALIDATION_FAILURE, e);
}
}

private boolean getBooleanParameter(String parameter, boolean defaultValue) {
final Project project = super.getProject();
if (project.hasProperty(parameter)) {
final Object o = project.getProperties().get(parameter);
if (o instanceof String) {
return Boolean.parseBoolean((String)o);
}
final Object o = super.getProject().findProperty(parameter);
if (o instanceof String) {
return Boolean.parseBoolean((String) o);
}
return defaultValue;
}

private String getStringParameter(String parameter, String defaultValue) {
final Project project = super.getProject();
if (project.hasProperty(parameter)) {
final Object o = project.getProperties().get(parameter);
if (o instanceof String) {
return (String)o;
}
final Object o = super.getProject().findProperty(parameter);
if (o instanceof String) {
return (String) o;
}
return defaultValue;
}
Expand All @@ -456,7 +451,7 @@ private CycloneDxSchema.Version schemaVersion() {
final Project project = super.getProject();
final String version;
if (project.hasProperty("cyclonedx.schemaVersion")) {
version = (String)project.getProperties().get("cyclonedx.schemaVersion");
version = (String) project.property("cyclonedx.schemaVersion");
} else {
version = getStringParameter("schemaVersion", CycloneDxSchema.Version.VERSION_13.getVersionString());
}
Expand Down
7 changes: 0 additions & 7 deletions src/main/resources/plugin.properties

This file was deleted.