You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SBOMs from Ubuntu with purls seam not to work with Google OSV #4445
Hello together,
I've noticed that in DependencyTrack in version 4.12.1 supports fetching vulnerabilities from Google's OSV service. So wanted to test DependencyTrack with an SBOM containing PURLs i can also use for CVE-fetching via Google API. As example i choose the ubuntu package atftp in version 0.7.git20120829-3.1~0.18.04.1 which has the known CVE'S CVE-2020-6097, CVE-2021-46671 and CVE-2021-41054. But DependencyTrack reports no issues at all.
While looking for a solution i found #1374. Also this problem is caused by a insuffient regex in version parsing. While fixing this bug i developed a theory about how to parse versions, including semantic versioning 2.0.0 and debian versions in general (also see in the issue).
My plan is to develop an enhanced parsing algorithm based on the current one.
For testing I thought about picking random version pairs (because there are so many) from a list of all ubuntu version numbers (they are a superset of debian version numbers and are ~130000 single entries so ~8.5 billion possible pairs), compare each with the enhanced algorithm and dpkg --compare-versions and check if the verdict is in all tested cases the same. From the most representative samples i want to create unittests.
Same i want to do with semantic version pairs (but from what list?) and with a "offical" (which one?) comparing tool.
Further it would be great if this could be done also with version numbers from other ecosystems on Google OSV. But also here would be the question from which version lists and with what offical comparision tool.
Hi @ALL,
i got a working comparison algorithm for generic version parsing with an a test for debian/ubuntu versions.
It works in following steps:
Ecosystem needs to be defined, meaning the sort priority of version number elements. I use three lists for that. In list1 are the elements which sort lower than the empty string (in debian : 1.0.0rc1 < 1.0.0), which sort same as empty string (#: 1.0.0#build1 = 1.0.0) and which sort higher than empty string (in debian anything else), so i got:
while (matcher.find()) {
for (int i = 1; i <= this.eco.getElements().size(); i++) {
if (matcher.group(i) != null) {
String value = matcher.group(i);
if(debug) {
System.out.print(" '"+value+"' ");
}
fields.add(new Token(i - 1, value));
break;
}
}
}
3.Compare one-by-one: First check priority, then check value. if value is a numeric add leading zeros that both strings got same length. Stop on first difference:
The algorithm it tested with the mentioned testdata set with 130000 version pairs and i discovered some corner cases which are not covered by other implementations:
Some packages use as a version number the datetime in the format YYYYMMDDhhmm which exceeds Integer and crashes many implementations.
Some version number have more than one dash, e.g. 1.0-0-1. According to debian the last dash is the splitter between original version and debian version, so original version should be 1.0-0 and debian version 1. The problem is now that assuming the original version as a semver than the sorting order is 1.0-0 < 1.0 (since - sorts before empty version in semver), but in fact it is sorted as debian version 1.0-0 > 1.0. For accieving the same in in debian order you need the write 1.0~0 . So in general all Debian-Packages should replace - from the original version number with ~ to preserve the version order. Do this consequently, all debian version should contain one dash maximal, but so in fact we need to handle the 2+ dash cases, even if they should IMHO considered be as faulty
The epoch which defaults to 0 if not set
To circumvent these problems i did the design as followed:
Do not parse numbers at all. For comparing it is suffient to pad the number with the less digits with leading zeros to the length of the longer number and do an alphabetic sort then. So the number of the digits maximum allowed is the maximum allowed numbers of characters in a string.
Search for the last dash before tokenizing in the version string an replace it by a \n, assign the \n the next higher priority to EndOfString. This will cause the the versions to be parsed separated and avoids a very complex parser which needs to do a lot of look-ahead to find the last dash.
Just search for epoch separator :, if not set add '0:' to the front. Also this helps to keep the tokenizer simple.
👋 We're very much enjoying DT. Thanks for your efforts in building such a great tool!
We're also experiencing issues with identifying vulnerabilities against Ubuntu packages and it'd be great to see this issue addressed as it'd allow us to move entirely to DT to provide vulnerability detection.
Tangentially, during our investigations that have lead us to this issue, we've identified an upstream issue here relating to invalid PURLs being published to OSV from Canonical. These look like they'll be addressed quickly.
@nickrmc83 I think this effort could be greatly accelerated by assisting @Andre-85 in reviewing and testing their implementation against realistic datasets. Waiting for me to have capacity to do so will delay this, I fear.
@Andre-85 Once you have something you're comfortable with sharing, we could ask others in the community (i.e. via Slack) to help here. We could publish container images to Docker Hub to make it easier for folks to kick the tires. Let me know if I can help facilitate anything.
I'm happy to provide some test cases and real-world data that can be used to verify @Andre-85's changes. It's unlikely I'll be able to commit to thoroughly testing a new version outside of a quick validation for at least a couple of months.
Hi @ALL,
thank you very much for your support offers! Right now I'm fitting my new algorithm in the DependencyTrack-Code and formatting my test code as regular unittests. As soon as this is finished I would this pack this in a container (this i can do by myself) and publish them for testing and discussing (here i could need help).
@nickrmc83 What kind of test data can you provide and for which ecosystem? Right now my testdata are random version numbers picked from a file (one per line in a file ubuntu_versions.txt). With these random version numbers I run the algorithm (right now its not in the unittest format of course) and compare it with the official tool.
#!/usr/bin/python3
import random
import pathlib
import subprocess
import sys
operators = { 255:"<<", 0:"=", 1:">>" }
def run_dpkg(version1, operator, version2):
return subprocess.run(['dpkg', '--compare-versions', version1, operator, version2], check=False, shell=False).returncode
def run_java_vers(version1, version2):
return operators[subprocess.run(['java','vers', version1, version2], check=False, shell=False).returncode]
testset_path = pathlib.Path("tests").joinpath("testsets","ubuntu_versions.txt")
#operators = [ "<<", "=", ">>" ]
# Read all lines from the file
if testset_path.exists():
testset = testset_path.read_text().splitlines() # Read lines and split by newline
# Select two random lines
if len(testset) >= 2:
while True:
versions = random.choices(testset, k=2) # Randomly pick 2 lines without replacement
for op in operators.values():
code = run_dpkg(versions[0], op, versions[1])
if code == 0:
relation = run_java_vers(versions[0], versions[1])
check = (relation == op)
print("Run: "+versions[0]+" "+op+" "+versions[1]+" "+str(check))
if not check:
sys.exit(0)
else:
print("The file doesn't have enough lines to select two.")
else:
print(f"File '{testset_path}' does not exist.")
But a testset with a file with version1 RELATION version2 per line would also be ok.
@Andre-85 the relatively simple test data I can provide would be a real-world SBOM and associated PURLs and a list of CVEs we'd expect to see. This may allow for confirmation for end-to-end functionality as opposed to your Debian and Ubuntu version parsing logic.
@nickrmc83 This would great if you could send this testdata to me. Even more interesting it would be to have testdata which is for other Ecosystems than Debian or Ubuntu. The issue you filed (canonical/ubuntu-security-notices#4) affects also DependencyTrack abilities i guess?
@nickrmc83 This would great if you could send this testdata to me. Even more interesting it would be to have testdata which is for other Ecosystems than Debian or Ubuntu. The issue you filed (canonical/ubuntu-security-notices#4) affects also DependencyTrack abilities i guess?
I can share an SBOM for Debian and Ubuntu only. Whilst the SBOMs I'll share are non-sensitive and will have any redactions made, I'd prefer to DM them to you.
You can compare the SBOMs I provide against findings identified by other tools using the same input. We've been using grype to this point.
I'm not sure how impacted dependency-track is by the Canonical issue, I didn't dive in deep on the impact, but I imagine if DT depends on qualifiers from OSV-published PURLs, there's a chance it would include either false-positive or false-negatives as a result.
Activity
valentijnscholten commentedon Dec 9, 2024
The correct link (I assume) is: google/osv.dev#2842 :-)
Andre-85 commentedon Dec 10, 2024
I updated to Version 4.12.2 but still the same
Andre-85 commentedon Dec 10, 2024
While looking for a solution i found #1374. Also this problem is caused by a insuffient regex in version parsing. While fixing this bug i developed a theory about how to parse versions, including semantic versioning 2.0.0 and debian versions in general (also see in the issue).
My plan is to develop an enhanced parsing algorithm based on the current one.
For testing I thought about picking random version pairs (because there are so many) from a list of all ubuntu version numbers (they are a superset of debian version numbers and are ~130000 single entries so ~8.5 billion possible pairs), compare each with the enhanced algorithm and dpkg --compare-versions and check if the verdict is in all tested cases the same. From the most representative samples i want to create unittests.
Same i want to do with semantic version pairs (but from what list?) and with a "offical" (which one?) comparing tool.
Further it would be great if this could be done also with version numbers from other ecosystems on Google OSV. But also here would be the question from which version lists and with what offical comparision tool.
Andre-85 commentedon Jan 2, 2025
Hi @ALL,
i got a working comparison algorithm for generic version parsing with an a test for debian/ubuntu versions.
It works in following steps:
: 1.0.0rc1 < 1.0.0), which sort same as empty string (#: 1.0.0#build1 = 1.0.0) and which sort higher than empty string (in debian anything else), so i got:which equivalent to ~ < # = "" < \d+ < [a-z]+ < + < - < . < :, and what the debian version algorithm does: https://salsa.debian.org/dpkg-team/dpkg/-/blob/main/scripts/Dpkg/Version.pm?ref_type=heads#L351
2. Tokenize: Concat all the list elements by logical or with in accending order. Matched group number is Token sort priority, the match is the Token value:
3.Compare one-by-one: First check priority, then check value. if value is a numeric add leading zeros that both strings got same length. Stop on first difference:
Andre-85 commentedon Jan 2, 2025
The algorithm it tested with the mentioned testdata set with 130000 version pairs and i discovered some corner cases which are not covered by other implementations:
To circumvent these problems i did the design as followed:
Andre-85 commentedon Jan 2, 2025
In the next days i will create an fork and add my algorithm. For who's interessted, the algorithm so far:
nickrmc83 commentedon Jan 8, 2025
👋 We're very much enjoying DT. Thanks for your efforts in building such a great tool!
We're also experiencing issues with identifying vulnerabilities against Ubuntu packages and it'd be great to see this issue addressed as it'd allow us to move entirely to DT to provide vulnerability detection.
Tangentially, during our investigations that have lead us to this issue, we've identified an upstream issue here relating to invalid PURLs being published to OSV from Canonical. These look like they'll be addressed quickly.
nscuro commentedon Jan 8, 2025
@nickrmc83 I think this effort could be greatly accelerated by assisting @Andre-85 in reviewing and testing their implementation against realistic datasets. Waiting for me to have capacity to do so will delay this, I fear.
@Andre-85 Once you have something you're comfortable with sharing, we could ask others in the community (i.e. via Slack) to help here. We could publish container images to Docker Hub to make it easier for folks to kick the tires. Let me know if I can help facilitate anything.
nickrmc83 commentedon Jan 9, 2025
I'm happy to provide some test cases and real-world data that can be used to verify @Andre-85's changes. It's unlikely I'll be able to commit to thoroughly testing a new version outside of a quick validation for at least a couple of months.
Andre-85 commentedon Jan 9, 2025
Hi @ALL,
thank you very much for your support offers! Right now I'm fitting my new algorithm in the DependencyTrack-Code and formatting my test code as regular unittests. As soon as this is finished I would this pack this in a container (this i can do by myself) and publish them for testing and discussing (here i could need help).
@nickrmc83 What kind of test data can you provide and for which ecosystem? Right now my testdata are random version numbers picked from a file (one per line in a file ubuntu_versions.txt). With these random version numbers I run the algorithm (right now its not in the unittest format of course) and compare it with the official tool.
But a testset with a file with version1 RELATION version2 per line would also be ok.
nickrmc83 commentedon Jan 10, 2025
@Andre-85 the relatively simple test data I can provide would be a real-world SBOM and associated PURLs and a list of CVEs we'd expect to see. This may allow for confirmation for end-to-end functionality as opposed to your Debian and Ubuntu version parsing logic.
Andre-85 commentedon Jan 12, 2025
@nickrmc83 This would great if you could send this testdata to me. Even more interesting it would be to have testdata which is for other Ecosystems than Debian or Ubuntu. The issue you filed (canonical/ubuntu-security-notices#4) affects also DependencyTrack abilities i guess?
nickrmc83 commentedon Jan 12, 2025
I can share an SBOM for Debian and Ubuntu only. Whilst the SBOMs I'll share are non-sensitive and will have any redactions made, I'd prefer to DM them to you.
You can compare the SBOMs I provide against findings identified by other tools using the same input. We've been using
grypeto this point.I'm not sure how impacted dependency-track is by the Canonical issue, I didn't dive in deep on the impact, but I imagine if DT depends on qualifiers from OSV-published PURLs, there's a chance it would include either false-positive or false-negatives as a result.
37 remaining items
Consider OS distro during vulnerability matching
Consider OS distro during vulnerability matching
Consider OS distro during vulnerability matching
Consider OS distro during vulnerability matching
Consider OS distro during vulnerability matching
Consider OS distro during vulnerability matching
Consider OS distro during vulnerability matching
Consider OS distro during vulnerability matching
github-actions commentedon Apr 2, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Consider OS distro during vulnerability matching