Skip to content

Commit b82fdc4

Browse files
committed
Migrate from VULCOID to VCID #811
Use uuid instead of base36 Reference: #811 Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 9f89bca commit b82fdc4

7 files changed

Lines changed: 67 additions & 28 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 4.0.4 on 2022-09-05 11:40
2+
3+
from django.db import migrations
4+
from django.db import models
5+
import vulnerabilities.models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('vulnerabilities', '0019_alter_vulnerabilityreference_options'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='vulnerability',
17+
name='vulnerability_id',
18+
field=models.CharField(blank=True, default=vulnerabilities.models.get_vcid, help_text='Unique identifier for a vulnerability in the external representation. It is prefixed with VCID-', max_length=45, unique=True),
19+
),
20+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.db import migrations
2+
from django.db.models import Q
3+
4+
from vulnerabilities.models import get_vcid
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('vulnerabilities', '0020_alter_vulnerability_vulnerability_id'),
11+
]
12+
13+
def save_vulnerability_id(apps, schema_editor):
14+
Vulnerabilities = apps.get_model("vulnerabilities", "Vulnerability")
15+
for vulnerability in Vulnerabilities.objects.filter(~Q(vulnerability_id__startswith="VCID-")):
16+
vulnerability.vulnerability_id = get_vcid()
17+
vulnerability.save()
18+
19+
operations = [
20+
migrations.RunPython(save_vulnerability_id, migrations.RunPython.noop)
21+
]

vulnerabilities/models.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from django.core.validators import MinValueValidator
1919
from django.db import models
2020
from django.dispatch import receiver
21-
from django.utils.http import int_to_base36
2221
from packageurl import PackageURL
2322
from packageurl.contrib.django.models import PackageURLMixin
2423
from rest_framework.authtoken.models import Token
@@ -32,6 +31,10 @@
3231
logger = logging.getLogger(__name__)
3332

3433

34+
def get_vcid():
35+
return f"VCID-{uuid.uuid4()}"
36+
37+
3538
class Vulnerability(models.Model):
3639
"""
3740
A software vulnerability with minimal information. Unique identifiers are
@@ -41,9 +44,10 @@ class Vulnerability(models.Model):
4144
vulnerability_id = models.CharField(
4245
unique=True,
4346
blank=True,
44-
max_length=20,
47+
max_length=45,
48+
default=get_vcid,
4549
help_text="Unique identifier for a vulnerability in the external representation. "
46-
"It is prefixed with VULCOID-",
50+
"It is prefixed with VCID-",
4751
)
4852

4953
summary = models.TextField(
@@ -59,12 +63,6 @@ class Vulnerability(models.Model):
5963
through="PackageRelatedVulnerability",
6064
)
6165

62-
def save(self, *args, **kwargs):
63-
super().save(*args, **kwargs)
64-
if not self.vulnerability_id:
65-
self.vulnerability_id = f"VULCOID-{int_to_base36(self.id).upper()}"
66-
super().save(update_fields=["vulnerability_id"])
67-
6866
@property
6967
def vulnerable_to(self):
7068
"""

vulnerabilities/templates/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@
8484
<div class="dropdown-menu dropdown-instructions-width" id="dropdown-menu4" role="menu">
8585
<div class="dropdown-content dropdown-instructions-box-shadow">
8686
<div class="dropdown-item">
87-
<div>Search for comprehensive information for a <span class="inline-code">VULCOID</span> (VulnerableCode Database ID). <span class="is-italic">(Only the first of these methods requires that the input be all uppercase.)</span>
87+
<div>Search for comprehensive information for a <span class="inline-code">VCID</span> (VulnerableCode ID). <span class="is-italic">(Only the first of these methods requires that the input be all uppercase.)</span>
8888
<ul>
8989
<li>
90-
Search for a specific <span class="inline-code">VULCOID</span> (e.g., "VULCOID-1").
90+
Search for a specific <span class="inline-code">VCID</span> (e.g., "VCID-fe0c3d75-204c-4e5d-a7f7-b89f1605e6a1").
9191
</li>
9292
<li>
93-
Search for all <span class="inline-code">VULCOID</span>s that are associated with a specific <span class="inline-code">CVE</span> (e.g., "CVE-2009-3898") or <span class="inline-code">GHSA</span> (e.g., "GHSA-2qrg-x229-3v8q").
93+
Search for all <span class="inline-code">VCID</span>s that are associated with a specific <span class="inline-code">CVE</span> (e.g., "CVE-2009-3898") or <span class="inline-code">GHSA</span> (e.g., "GHSA-2qrg-x229-3v8q").
9494
</li>
9595
<li>
96-
Search for "CVE" or "GHSA" -- this will return all <span class="inline-code">VULCOID</span>s that are associated with one or more <span class="inline-code">CVE</span>s or <span class="inline-code">GHSA</span>s, respectively.
96+
Search for "CVE" or "GHSA" -- this will return all <span class="inline-code">VCID</span>s that are associated with one or more <span class="inline-code">CVE</span>s or <span class="inline-code">GHSA</span>s, respectively.
9797
</li>
9898
</ul>
9999
</div>

vulnerabilities/templates/vulnerabilities.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
<div class="dropdown-menu dropdown-instructions-width" id="dropdown-menu4" role="menu">
2222
<div class="dropdown-content dropdown-instructions-box-shadow">
2323
<div class="dropdown-item">
24-
<div>Search for comprehensive information for a <span class="inline-code">VULCOID</span> (VulnerableCode Database ID). <span class="is-italic">(Only the first of these methods requires that the input be all uppercase.)</span>
24+
<div>Search for comprehensive information for a <span class="inline-code">VCID</span> (VulnerableCode ID). <span class="is-italic">(Only the first of these methods requires that the input be all uppercase.)</span>
2525
<ul>
2626
<li>
27-
Search for a specific <span class="inline-code">VULCOID</span> (e.g., "VULCOID-1").
27+
Search for a specific <span class="inline-code">VCID</span> (e.g., "VCID-fe0c3d75-204c-4e5d-a7f7-b89f1605e6a1").
2828
</li>
2929
<li>
30-
Search for all <span class="inline-code">VULCOID</span>s that are associated with a specific <span class="inline-code">CVE</span> (e.g., "CVE-2009-3898") or <span class="inline-code">GHSA</span> (e.g., "GHSA-2qrg-x229-3v8q").
30+
Search for all <span class="inline-code">VCID</span>s that are associated with a specific <span class="inline-code">CVE</span> (e.g., "CVE-2009-3898") or <span class="inline-code">GHSA</span> (e.g., "GHSA-2qrg-x229-3v8q").
3131
</li>
3232
<li>
33-
Search for "CVE" or "GHSA" -- this will return all <span class="inline-code">VULCOID</span>s that are associated with one or more <span class="inline-code">CVE</span>s or <span class="inline-code">GHSA</span>s, respectively.
33+
Search for "CVE" or "GHSA" -- this will return all <span class="inline-code">VCID</span>s that are associated with one or more <span class="inline-code">CVE</span>s or <span class="inline-code">GHSA</span>s, respectively.
3434
</li>
3535
</ul>
3636
</div>

vulnerabilities/templates/vulnerability.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
<div class="dropdown-menu dropdown-instructions-width" id="dropdown-menu4" role="menu">
2222
<div class="dropdown-content dropdown-instructions-box-shadow">
2323
<div class="dropdown-item">
24-
<div>Search for comprehensive information for a <span class="inline-code">VULCOID</span> (VulnerableCode Database ID). <span class="is-italic">(Only the first of these methods requires that the input be all uppercase.)</span>
24+
<div>Search for comprehensive information for a <span class="inline-code">VCID</span> (VulnerableCode ID). <span class="is-italic">(Only the first of these methods requires that the input be all uppercase.)</span>
2525
<ul>
2626
<li>
27-
Search for a specific <span class="inline-code">VULCOID</span> (e.g., "VULCOID-1").
27+
Search for a specific <span class="inline-code">VCID</span> (e.g., "VCID-fe0c3d75-204c-4e5d-a7f7-b89f1605e6a1").
2828
</li>
2929
<li>
30-
Search for all <span class="inline-code">VULCOID</span>s that are associated with a specific <span class="inline-code">CVE</span> (e.g., "CVE-2009-3898") or <span class="inline-code">GHSA</span> (e.g., "GHSA-2qrg-x229-3v8q").
30+
Search for all <span class="inline-code">VCID</span>s that are associated with a specific <span class="inline-code">CVE</span> (e.g., "CVE-2009-3898") or <span class="inline-code">GHSA</span> (e.g., "GHSA-2qrg-x229-3v8q").
3131
</li>
3232
<li>
33-
Search for "CVE" or "GHSA" -- this will return all <span class="inline-code">VULCOID</span>s that are associated with one or more <span class="inline-code">CVE</span>s or <span class="inline-code">GHSA</span>s, respectively.
33+
Search for "CVE" or "GHSA" -- this will return all <span class="inline-code">VCID</span>s that are associated with one or more <span class="inline-code">CVE</span>s or <span class="inline-code">GHSA</span>s, respectively.
3434
</li>
3535
</ul>
3636
</div>

vulnerabilities/tests/test_fix_api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_api_with_single_vulnerability(self):
5959
).data
6060
assert response == {
6161
"url": f"http://testserver/api/vulnerabilities/{self.vulnerability.id}",
62-
"vulnerability_id": f"VULCOID-{int_to_base36(self.vulnerability.id).upper()}",
62+
"vulnerability_id": self.vulnerability.vulnerability_id,
6363
"summary": "test",
6464
"aliases": [],
6565
"fixed_packages": [
@@ -84,7 +84,7 @@ def test_api_with_single_vulnerability_with_filters(self):
8484
).data
8585
assert response == {
8686
"url": f"http://testserver/api/vulnerabilities/{self.vulnerability.id}",
87-
"vulnerability_id": f"VULCOID-{int_to_base36(self.vulnerability.id).upper()}",
87+
"vulnerability_id": self.vulnerability.vulnerability_id,
8888
"summary": "test",
8989
"aliases": [],
9090
"fixed_packages": [
@@ -182,7 +182,7 @@ def test_api_with_single_vulnerability_and_fixed_package(self):
182182
"affected_by_vulnerabilities": [
183183
{
184184
"url": f"http://testserver/api/vulnerabilities/{self.vuln1.id}",
185-
"vulnerability_id": f"VULCOID-{int_to_base36(self.vuln1.id).upper()}",
185+
"vulnerability_id": self.vuln1.vulnerability_id,
186186
"summary": "test-vuln1",
187187
"references": [],
188188
"fixed_packages": [],
@@ -191,7 +191,7 @@ def test_api_with_single_vulnerability_and_fixed_package(self):
191191
"fixing_vulnerabilities": [
192192
{
193193
"url": f"http://testserver/api/vulnerabilities/{self.vuln.id}",
194-
"vulnerability_id": f"VULCOID-{int_to_base36(self.vuln.id).upper()}",
194+
"vulnerability_id": self.vuln.vulnerability_id,
195195
"summary": "test-vuln",
196196
"references": [],
197197
"fixed_packages": [
@@ -206,7 +206,7 @@ def test_api_with_single_vulnerability_and_fixed_package(self):
206206
"unresolved_vulnerabilities": [
207207
{
208208
"url": f"http://testserver/api/vulnerabilities/{self.vuln1.id}",
209-
"vulnerability_id": f"VULCOID-{int_to_base36(self.vuln1.id).upper()}",
209+
"vulnerability_id": self.vuln1.vulnerability_id,
210210
"summary": "test-vuln1",
211211
"references": [],
212212
"fixed_packages": [],
@@ -228,7 +228,7 @@ def test_api_with_single_vulnerability_and_vulnerable_package(self):
228228
"affected_by_vulnerabilities": [
229229
{
230230
"url": f"http://testserver/api/vulnerabilities/{self.vuln.id}",
231-
"vulnerability_id": f"VULCOID-{int_to_base36(self.vuln.id).upper()}",
231+
"vulnerability_id": self.vuln.vulnerability_id,
232232
"summary": "test-vuln",
233233
"references": [],
234234
"fixed_packages": [
@@ -244,7 +244,7 @@ def test_api_with_single_vulnerability_and_vulnerable_package(self):
244244
"unresolved_vulnerabilities": [
245245
{
246246
"url": f"http://testserver/api/vulnerabilities/{self.vuln.id}",
247-
"vulnerability_id": f"VULCOID-{int_to_base36(self.vuln.id).upper()}",
247+
"vulnerability_id": self.vuln.vulnerability_id,
248248
"summary": "test-vuln",
249249
"references": [],
250250
"fixed_packages": [

0 commit comments

Comments
 (0)