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

#103: security warning for CVEs in file tool/edition/security #119

Open
wants to merge 61 commits into
base: main
Choose a base branch
from

Conversation

MattesMrzik
Copy link
Contributor

@MattesMrzik MattesMrzik commented Oct 25, 2023

Closes #103: Before installing a ToolCommandlet, warn the user if the selected version is listed in ulrs///security.json indicating that this version has a CVE and ask if the user wants to stay with the current or select a safe version.

@tobka777 tobka777 linked an issue Oct 26, 2023 that may be closed by this pull request
@MattesMrzik MattesMrzik self-assigned this Oct 26, 2023
@MattesMrzik MattesMrzik changed the title closes #103: security warning for CVEs in file tool/edition/security #103: security warning for CVEs in file tool/edition/security Oct 28, 2023
Copy link
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

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

@MattesMrzik Great that you found and reused UrlSecurityFile and you found the exact way to access and use it. 👍
I left some review comments to give some further direction and also you need to consider that we also have an existing security file for git.
As we do not have a commandlet for git we would either have to add GitCommandlet as global tool commandlet and also find a way to download the latest version of git without using ide-urls as cloning or pulling it already requires git or we keep that as a per-requisite of IDEasy but then have to find the right place in our code-base where to determine the currently installed git version and to do the security check. My perfect vision would be to have a GitCommandlet and even extend our git clone/pull method to check if git is already available and otherwise run the GitCommandlet to install it. However creating a GitCommandlet would cause a dependency to #113 so feel free to first ignore git so we can add it in a later PR.
Also we should find an additional tool version that we want to warn about (my suggestion would be gradle - see https://www.cvedetails.com/cve/CVE-2016-6199/) so we also have something to test this feature.

@MattesMrzik MattesMrzik removed their assignment Nov 27, 2023
@MattesMrzik
Copy link
Contributor Author

I've got a question:
This CVE is for the tool terraform. It defines the affected version like this: Up to (including) 1.12.0. IDEasy only provides version up to 1.6.5. So to mark these versions as vulnerable the VersionIdentifier.compareVersion(other) is used to determine, that 1.12.0. is greater than 1.6.5. This is fine in this case but. In case of this CVE the affected versions are defined by: up to excluding 202107-1C. Which is greater than 1.6.5. as determined by VersionIdentifier.compareVersion(other). This might not be the correct interpretation. What to do about cases like this? How might I recognize them and add a flag that this guess is unsafe?

@hohwille
Copy link
Member

I've got a question: This CVE is for the tool terraform. It defines the affected version like this: Up to (including) 1.12.0. IDEasy only provides version up to 1.6.5. So to mark these versions as vulnerable the VersionIdentifier.compareVersion(other) is used to determine, that 1.12.0. is greater than 1.6.5. This is fine in this case but. In case of this CVE the affected versions are defined by: up to excluding 202107-1C. Which is greater than 1.6.5. as determined by VersionIdentifier.compareVersion(other). This might not be the correct interpretation. What to do about cases like this? How might I recognize them and add a flag that this guess is unsafe?

You are reaching the point why I said that the CVE database is a valuable source but we should not build a completely automated process but still need some manual process involved.
For the first one see anchore/grype#1377
For the second (NVD is currently down so I consulted GHSA-6cgg-f8v8-8rxw) it is a similar problem: the CVEs is not about our terraform edition but about the enterprise edition that we do not even support (yet).
If the CVE database does not properly distinguish this via CPE then in this point it is again useless for an automated process.
We have to be creative to sort such garbage out from the interesting CVEs. The most simple approach is to start a hardcoded Set of CVEs to ignore or better would be to have a look at all the attributes of the CVE and see if there is something we missed in the matching but could be used to distinguish the editions. If nothing can be found in this case maybe a regex could help to match version and see if it is a year/month based one.

 ignore cves list, remove some analyzers, more test for version ranges like >, some cpe vendors and products to updaters
Extended the VersionRange to also model open boundaries that do not include the specified value. Also wrote tests for this class.
…implement-version-security-checks

# Conflicts:
#	cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java
#	cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeContextTest.java
…e-with-open-intervals' into feature/devonfw#103-implement-version-security-checks

# Conflicts:
#	cli/src/test/java/com/devonfw/tools/ide/version/VersionRangeTest.java
@coveralls
Copy link
Collaborator

coveralls commented Dec 19, 2023

Pull Request Test Coverage Report for Build 8100325177

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 255 unchanged lines in 21 files lost coverage.
  • Overall coverage increased (+0.3%) to 57.381%

Files with Coverage Reduction New Missed Lines %
com/devonfw/tools/ide/tool/dotnet/DotNetUrlUpdater.java 1 0.0%
com/devonfw/tools/ide/tool/jmc/JmcUrlUpdater.java 2 0.0%
com/devonfw/tools/ide/tool/mvn/MvnUrlUpdater.java 2 0.0%
com/devonfw/tools/ide/tool/pip/PipUrlUpdater.java 2 42.86%
com/devonfw/tools/ide/tool/terraform/TerraformUrlUpdater.java 2 0.0%
com/devonfw/tools/ide/tool/vscode/VsCodeUrlUpdater.java 2 0.0%
com/devonfw/tools/ide/tool/quarkus/QuarkusUrlUpdater.java 3 0.0%
com/devonfw/tools/ide/version/VersionRange.java 3 89.77%
com/devonfw/tools/ide/tool/androidstudio/AndroidStudioUrlUpdater.java 6 80.95%
com/devonfw/tools/ide/tool/GlobalToolCommandlet.java 6 0.0%
Totals Coverage Status
Change from base Build 8061873366: 0.3%
Covered Lines: 4116
Relevant Lines: 6921

💛 - Coveralls

if a single warning affects all versions, it is ignored
also SecurityRiskInteraction returns configured version and latest version when possible.

conversion between cpe and ulr version more rebust by using map and inverse function where map fails.

Added asciidoc
 - changed pom.xml
 - getCpeEdition now has argument, since there is only a single UrlUpdater for multiple editions of a tool
 - some cleanup
added dependencyManagement to root pom.xml
added owasp version property to root pom.xml
renamed security artifact to ide-security
…ty-checks

# Conflicts:
#	cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeContextTest.java
#	cli/src/test/resources/ide-projects/basic/_ide/urls/mvn/mvn/security.json
added missing answers param to newContext
fixed pom versions
applied reformat
renamed retrievePath to getPath
renamed addPath to setPath
removed warnings from security json
@jan-vcapgemini
Copy link
Contributor

I've detected some more issues with the dependency checks which need to be addressed first.
F.e. intellij url folders are not working with the CPE edition check.

added missing CPE vendors/products
adjusted getCpeVendor and getCpeProduct to return the tool name instead of an empty string
removed unused urlEdition param from getCpeEdition
added workaround for intellij #1378
fixed NPE's (added checks for missing UrlUpdaters)
Comment on lines 14 to 22
/**
* User answer to install the latest of all safe versions.
*/
LATEST_SAFE,

/**
* User answer to use the latest safe version.
*/
SAFE_LATEST,
Copy link
Member

Choose a reason for hiding this comment

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

Sorry to say so but this is absolutely confusing. While there is LATEST_SAFE the JavaDoc of SAFE_LATEST says "use the latest safe version". The difference of these two options is totally unclear.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've renamed the constant to LATEST now instead and adjusted the javadoc.

Copy link
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

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

Just to give some update on this PR.
@jan-vcapgemini thank you so much for taking over and improving this PR.
It is already in a good state.
However, again we tend to create too big PRs and do too much in one go.
It would have been much simpler to first log a FAT WARNING if a unsecure version is used.
Here we already have complex user-interaction, etc.

Also I first would like to see a PR to ide-urls with the result of the tool so we can first discuss if the outcome really makes sense. And also without such security.json files the feature is not adding any value.

…ty-checks

# Conflicts:
#	cli/pom.xml
#	cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
#	cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java
#	cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeContextTest.java
#	documentation/LICENSE.adoc
added missing answers to IdeTestContext
renamed SAFE_LATEST to LATEST
@hohwille hohwille removed this from the release:2024.03.001 milestone Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request security CVEs or other vulnerabilities urls ide-urls repo and related processes and features
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

Implement version security checks
5 participants