Skip to content

Commit f366a01

Browse files
committed
Drop go support from gitlab and github
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 5127d0b commit f366a01

18 files changed

Lines changed: 45 additions & 40 deletions

vulnerabilities/importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
from vulnerabilities.severity_systems import ScoringSystem
4949
from vulnerabilities.utils import classproperty
5050
from vulnerabilities.utils import evolve_purl
51+
from vulnerabilities.utils import get_reference_id
52+
from vulnerabilities.utils import is_cve
5153
from vulnerabilities.utils import nearest_patched_package
5254

5355
logger = logging.getLogger(__name__)

vulnerabilities/importers/github.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
from vulnerabilities.package_managers import VERSION_API_CLASSES_BY_PACKAGE_TYPE
4747
from vulnerabilities.package_managers import GoproxyVersionAPI
4848
from vulnerabilities.package_managers import VersionAPI
49-
from vulnerabilities.utils import AffectedPackage as LegacyAffectedPackage, resolve_version_range
49+
from vulnerabilities.package_managers import get_api_package_name
50+
from vulnerabilities.utils import AffectedPackage as LegacyAffectedPackage
5051
from vulnerabilities.utils import get_affected_packages_by_patched_package
5152
from vulnerabilities.utils import get_item
5253
from vulnerabilities.utils import nearest_patched_package
53-
from vulnerabilities.package_managers import get_api_package_name
54+
from vulnerabilities.utils import resolve_version_range
5455

5556
logger = logging.getLogger(__name__)
5657

@@ -124,7 +125,7 @@
124125
"COMPOSER": "composer",
125126
"PIP": "pypi",
126127
"RUBYGEMS": "gem",
127-
"GO": "golang",
128+
# "GO": "golang",
128129
}
129130

130131
GITHUB_ECOSYSTEM_BY_PACKAGE_TYPE = {
@@ -207,8 +208,7 @@ def get_purl(pkg_type: str, github_name: str) -> Optional[PackageURL]:
207208

208209
if pkg_type == "composer":
209210
if "/" not in github_name:
210-
logger.error(f"get_purl: Invalid composer package name {github_name}")
211-
return
211+
return PackageURL(type=pkg_type, name=github_name)
212212
vendor, _, name = github_name.partition("/")
213213
return PackageURL(type=pkg_type, namespace=vendor, name=name)
214214

vulnerabilities/importers/gitlab.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
from univers.version_range import from_gitlab_native
4141
from univers.versions import Version
4242

43-
from vulnerabilities.helpers import AffectedPackage as LegacyAffectedPackage
44-
from vulnerabilities.helpers import get_affected_packages_by_patched_package
45-
from vulnerabilities.helpers import nearest_patched_package
46-
from vulnerabilities.helpers import resolve_version_range
4743
from vulnerabilities.importer import AdvisoryData
4844
from vulnerabilities.importer import AffectedPackage
4945
from vulnerabilities.importer import Importer
@@ -56,19 +52,25 @@
5652
from vulnerabilities.package_managers import GoproxyVersionAPI
5753
from vulnerabilities.package_managers import VersionAPI
5854
from vulnerabilities.package_managers import get_api_package_name
55+
from vulnerabilities.utils import AffectedPackage as LegacyAffectedPackage
56+
from vulnerabilities.utils import build_description
57+
from vulnerabilities.utils import get_affected_packages_by_patched_package
58+
from vulnerabilities.utils import nearest_patched_package
59+
from vulnerabilities.utils import resolve_version_range
5960

6061
logger = logging.getLogger(__name__)
6162

6263

6364
PURL_TYPE_BY_GITLAB_SCHEME = {
65+
# "conan": "conan",
6466
"gem": "gem",
65-
"go": "golang",
67+
# Entering issue to parse go package names https://github.com/nexB/vulnerablecode/issues/742
68+
# "go": "golang",
6669
"maven": "maven",
6770
"npm": "npm",
6871
"nuget": "nuget",
69-
"pypi": "pypi",
7072
"packagist": "composer",
71-
# "conan": "conan",
73+
"pypi": "pypi",
7274
}
7375

7476

@@ -125,7 +127,7 @@ def get_purl(package_slug):
125127
name = parts[1]
126128
return PackageURL(type=purl_type, name=name)
127129
# if package slug is of the form:
128-
# "nuget/github/user/abc/NuGet.Core"
130+
# "nuget/github.com/beego/beego/v2/nuget"
129131
if len(parts) >= 3:
130132
name = parts[-1]
131133
namespace = "/".join(parts[1:-1])
@@ -187,11 +189,11 @@ def parse_gitlab_advisory(file):
187189

188190
# refer to schema here https://gitlab.com/gitlab-org/advisories-community/-/blob/main/ci/schema/schema.json
189191
aliases = gitlab_advisory.get("identifiers")
190-
summary = ". ".join([gitlab_advisory.get("title"), gitlab_advisory.get("description")])
192+
summary = build_description(gitlab_advisory.get("title"), gitlab_advisory.get("description"))
191193
urls = gitlab_advisory.get("urls")
192194
references = [Reference.from_url(u) for u in urls]
193195
date_published = dateparser.parse(gitlab_advisory.get("pubdate"))
194-
date_published = pytz.utc.localize(date_published)
196+
date_published = date_published.replace(tzinfo=pytz.UTC)
195197
package_slug = gitlab_advisory.get("package_slug")
196198
purl: PackageURL = get_purl(package_slug=package_slug)
197199
if not purl:

vulnerabilities/package_managers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,13 @@ def get_api_package_name(purl: PackageURL) -> str:
710710
>>> get_api_package_name(PackageURL(type="composer", namespace="foo", name="bar"))
711711
'foo/bar'
712712
"""
713+
if not purl.name:
714+
return None
715+
if purl.type in ("nuget", "pypi", "gem") or not purl.namespace:
716+
return purl.name
713717
if purl.type == "maven":
714718
return f"{purl.namespace}:{purl.name}"
715-
716-
if purl.type == "composer":
719+
if purl.type in ("composer", "golang", "npm"):
717720
return f"{purl.namespace}/{purl.name}"
718721

719-
if purl.type in ("nuget", "pypi", "gem", "golang", "npm"):
720-
return purl.name
721-
722722
logger.error(f"get_api_package_name: Unknown PURL {purl!r}")

vulnerabilities/tests/test_data/gitlab/composer-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"aliases": [
33
"GMS-2018-26"
44
],
5-
"summary": "Incorrect header injection check. amphp/http isn't properly protected against HTTP header injection.",
5+
"summary": "Incorrect header injection check\namphp/http isn't properly protected against HTTP header injection.",
66
"affected_packages": [
77
{
88
"package": {

vulnerabilities/tests/test_data/gitlab/composer-improver-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"GMS-2018-26"
66
],
77
"confidence": 100,
8-
"summary": "Incorrect header injection check. amphp/http isn't properly protected against HTTP header injection.",
8+
"summary": "Incorrect header injection check\namphp/http isn't properly protected against HTTP header injection.",
99
"affected_purls": [],
1010
"fixed_purl": {
1111
"type": "composer",

vulnerabilities/tests/test_data/gitlab/gem-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"aliases": [
33
"OSVDB-112347"
44
],
5-
"summary": "Object Injection. A flaw in Active Job that can allow string arguments to be deserialized as if they were Global IDs. This may allow a remote attacker to inject arbitrary objects.",
5+
"summary": "Object Injection\nA flaw in Active Job that can allow string arguments to be deserialized as if they were Global IDs. This may allow a remote attacker to inject arbitrary objects.",
66
"affected_packages": [
77
{
88
"package": {

vulnerabilities/tests/test_data/gitlab/gem-improver-expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"OSVDB-112347"
66
],
77
"confidence": 100,
8-
"summary": "Object Injection. A flaw in Active Job that can allow string arguments to be deserialized as if they were Global IDs. This may allow a remote attacker to inject arbitrary objects.",
8+
"summary": "Object Injection\nA flaw in Active Job that can allow string arguments to be deserialized as if they were Global IDs. This may allow a remote attacker to inject arbitrary objects.",
99
"affected_purls": [
1010
{
1111
"type": "gem",
@@ -38,7 +38,7 @@
3838
"OSVDB-112347"
3939
],
4040
"confidence": 100,
41-
"summary": "Object Injection. A flaw in Active Job that can allow string arguments to be deserialized as if they were Global IDs. This may allow a remote attacker to inject arbitrary objects.",
41+
"summary": "Object Injection\nA flaw in Active Job that can allow string arguments to be deserialized as if they were Global IDs. This may allow a remote attacker to inject arbitrary objects.",
4242
"affected_purls": [
4343
{
4444
"type": "gem",

vulnerabilities/tests/test_data/gitlab/maven-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"CVE-2021-41269",
44
"GHSA-p9m8-27x8-rg87"
55
],
6-
"summary": "Improper Control of Generation of Code ('Code Injection'). cron-utils is a Java library to define, parse, validate, migrate crons as well as get human readable descriptions for them. leading to unauthenticated Remote Code Execution (RCE) vulnerability. Versions up to are susceptible to this vulnerability.",
6+
"summary": "Improper Control of Generation of Code ('Code Injection')\ncron-utils is a Java library to define, parse, validate, migrate crons as well as get human readable descriptions for them. leading to unauthenticated Remote Code Execution (RCE) vulnerability. Versions up to are susceptible to this vulnerability.",
77
"affected_packages": [
88
{
99
"package": {

vulnerabilities/tests/test_data/gitlab/maven-improver-expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"GHSA-p9m8-27x8-rg87"
77
],
88
"confidence": 100,
9-
"summary": "Improper Control of Generation of Code ('Code Injection'). cron-utils is a Java library to define, parse, validate, migrate crons as well as get human readable descriptions for them. leading to unauthenticated Remote Code Execution (RCE) vulnerability. Versions up to are susceptible to this vulnerability.",
9+
"summary": "Improper Control of Generation of Code ('Code Injection')\ncron-utils is a Java library to define, parse, validate, migrate crons as well as get human readable descriptions for them. leading to unauthenticated Remote Code Execution (RCE) vulnerability. Versions up to are susceptible to this vulnerability.",
1010
"affected_purls": [
1111
{
1212
"type": "maven",
@@ -108,7 +108,7 @@
108108
"GHSA-p9m8-27x8-rg87"
109109
],
110110
"confidence": 100,
111-
"summary": "Improper Control of Generation of Code ('Code Injection'). cron-utils is a Java library to define, parse, validate, migrate crons as well as get human readable descriptions for them. leading to unauthenticated Remote Code Execution (RCE) vulnerability. Versions up to are susceptible to this vulnerability.",
111+
"summary": "Improper Control of Generation of Code ('Code Injection')\ncron-utils is a Java library to define, parse, validate, migrate crons as well as get human readable descriptions for them. leading to unauthenticated Remote Code Execution (RCE) vulnerability. Versions up to are susceptible to this vulnerability.",
112112
"affected_purls": [],
113113
"fixed_purl": {
114114
"type": "maven",

0 commit comments

Comments
 (0)