Skip to content

Commit dc40ea8

Browse files
committed
Add API support for Patch/PackageCommitPatch
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent 6ea0ced commit dc40ea8

3 files changed

Lines changed: 109 additions & 2 deletions

File tree

vulnerabilities/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
from vulnerabilities.severity_systems import EPSS
7474
from vulnerabilities.severity_systems import SCORING_SYSTEMS
7575
from vulnerabilities.utils import compute_patch_checksum
76+
from vulnerabilities.utils import generate_commit_url
77+
from vulnerabilities.utils import generate_patch_url
7678
from vulnerabilities.utils import normalize_list
7779
from vulnerabilities.utils import normalize_purl
7880
from vulnerabilities.utils import normalize_text
@@ -2857,6 +2859,20 @@ class PackageCommitPatch(models.Model):
28572859
patch_text = models.TextField(blank=True, null=True)
28582860
patch_checksum = models.CharField(max_length=128, blank=True, null=True)
28592861

2862+
@property
2863+
def commit_url(self):
2864+
"""
2865+
Generates Commit URL using the VCS URL and Commit Hash.
2866+
"""
2867+
return generate_commit_url(self.vcs_url, self.commit_hash)
2868+
2869+
@property
2870+
def patch_url(self):
2871+
"""
2872+
Generates Patch URL using the VCS URL and Commit Hash.
2873+
"""
2874+
return generate_patch_url(self.vcs_url, self.commit_hash)
2875+
28602876
def save(self, *args, **kwargs):
28612877
if self.patch_text:
28622878
self.patch_checksum = compute_patch_checksum(self.patch_text)

vulnerabilities/templates/advisory_detail.html

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,16 @@
8080
</a>
8181
</li>
8282
{% endif %}
83-
83+
84+
<li data-tab="patch-url">
85+
<a>
86+
<span>
87+
{% with pcp_length=package_commit_patches|length %}
88+
Patches: ({{ advisory.patches.count|add:pcp_length }})
89+
{% endwith %}
90+
</span>
91+
</a>
92+
</li>
8493
<!-- <li data-tab="history">
8594
<a>
8695
<span>
@@ -436,7 +445,6 @@
436445
</tr>
437446
{% endfor %}
438447
</div>
439-
440448

441449
<div class="tab-div content" data-content="epss">
442450
{% if epss_data %}
@@ -503,6 +511,28 @@
503511
{% endif %}
504512
</div>
505513

514+
<div class="tab-div content" data-content="patch-url">
515+
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
516+
<thead>
517+
<tr>
518+
<th style="width: 250px;"> Patch URL </th>
519+
</tr>
520+
</thead>
521+
{% for patch in patches %}
522+
<tr>
523+
<td class="wrap-strings"><a href="{{ patch.patch_url }}" target="_blank">{{ patch.patch_url }}<i
524+
class="fa fa-external-link fa_link_custom"></i></a></td>
525+
</tr>
526+
{% empty %}
527+
<tr>
528+
<td colspan="2">
529+
There are no known patches.
530+
</td>
531+
</tr>
532+
{% endfor %}
533+
</table>
534+
</div>
535+
506536
<div class="tab-div content" data-content="severities-vectors">
507537
{% for severity_vector in severity_vectors %}
508538
{% if severity_vector.vector.version == '2.0' %}

vulnerabilities/templates/advisory_package_details.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,67 @@
6060
</div>
6161
</div>
6262
</section>
63+
<section class="section pt-0">
64+
<div class="details-container">
65+
<article class="panel is-info panel-header-only">
66+
<div class="panel-heading py-2 is-size-6">
67+
Vulnerable and Fixing Package Commit Patch details for Advisory:
68+
<span class="tag is-white custom">
69+
{{ advisoryv2.advisory_id }}
70+
</span>
71+
</div>
72+
</article>
73+
74+
<div id="tab-content">
75+
<table class="table vcio-table width-100-pct mt-2">
76+
<thead>
77+
<tr>
78+
<th style="width: 50%;">Introduced in</th>
79+
<th>Fixed by</th>
80+
</tr>
81+
</thead>
82+
<tbody>
83+
{% for impact in advisoryv2.impacted_packages.all %}
84+
85+
{% for pkg_commit_patch in impact.introduced_by_package_commit_patches.all %}
86+
<tr>
87+
<td>
88+
<a href="{{ pkg_commit_patch.patch_url }}" target="_self">
89+
{{ pkg_commit_patch.vcs_url }}@{{ pkg_commit_patch.commit_hash }}
90+
</a>
91+
<br />
92+
<a href="{{ pkg_commit_patch.patch_url }}" target="_self">{{ pkg_commit_patch.patch_url }}</a>
93+
</td>
94+
<td></td>
95+
</tr>
96+
{% endfor %}
97+
98+
{% for pkg_commit_patch in impact.fixed_by_package_commit_patches.all %}
99+
<tr>
100+
<td></td>
101+
<td>
102+
<a href="{{ pkg_commit_patch.commit_url }}" target="_self">
103+
{{ impact.base_purl }}@{{ pkg_commit_patch.commit_hash }}
104+
</a>
105+
<br />
106+
<a href="{{ pkg_commit_patch.patch_url }}" target="_self">{{ pkg_commit_patch.patch_url }}</a>
107+
</td>
108+
</tr>
109+
{% endfor %}
110+
111+
{% empty %}
112+
<tr>
113+
<td colspan="2">
114+
This vulnerability is not known to affect any package commits.
115+
</td>
116+
</tr>
117+
{% endfor %}
118+
</tbody>
119+
</table>
120+
</div>
121+
122+
</div>
123+
</section>
63124
{% endif %}
64125

65126
<script src="{% static 'js/main.js' %}" crossorigin="anonymous"></script>

0 commit comments

Comments
 (0)