Skip to content

Commit

Permalink
Merge branch 'main' into 1228-fixed-affected-version-matching #1228
Browse files Browse the repository at this point in the history
Reference: #1228

Signed-off-by: John M. Horan [email protected]
  • Loading branch information
johnmhoran committed Nov 28, 2023
2 parents 0ec7d6c + d3f314d commit 7a512c2
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ Release notes
=============


Version v33.6.3
----------------

- We updated RTD build configuration.
- We added importer for OSS-Fuzz.
- We removed vulnerabilities with empty aliases.
- We fixed search encoding issue https://github.com/nexB/vulnerablecode/issues/1336.
- We added middleware to ban "bytedance" user-agent.


Version v33.6.2
----------------

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = vulnerablecode
version = 33.6.2
version = 33.6.3
license = Apache-2.0 AND CC-BY-SA-4.0

# description must be on ONE line https://github.com/pypa/setuptools/issues/1390
Expand Down
5 changes: 3 additions & 2 deletions vulnerabilities/improvers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#

from vulnerabilities.improvers import valid_versions
from vulnerabilities.improvers import vulnerability_status

# from vulnerabilities.improvers import vulnerability_status

IMPROVERS_REGISTRY = [
valid_versions.GitHubBasicImprover,
Expand All @@ -24,7 +25,7 @@
valid_versions.DebianOvalImprover,
valid_versions.UbuntuOvalImprover,
valid_versions.OSSFuzzImprover,
vulnerability_status.VulnerabilityStatusImprover,
# vulnerability_status.VulnerabilityStatusImprover,
]

IMPROVERS_REGISTRY = {x.qualified_name: x for x in IMPROVERS_REGISTRY}
18 changes: 18 additions & 0 deletions vulnerabilities/middleware/ban_user_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# VulnerableCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/vulnerablecode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#

from django.http import HttpResponseNotFound
from django.utils.deprecation import MiddlewareMixin


class BanUserAgent(MiddlewareMixin):
def process_request(self, request):
user_agent = request.META.get("HTTP_USER_AGENT", None)
if user_agent and "bytedance" in user_agent:
return HttpResponseNotFound(404)
8 changes: 4 additions & 4 deletions vulnerabilities/templates/includes/pagination.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<nav class="pagination is-centered is-small" aria-label="pagination">
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}&search={{ search }}" class="pagination-previous">Previous</a>
<a href="?page={{ page_obj.previous_page_number }}&search={{ search|urlencode }}" class="pagination-previous">Previous</a>
{% else %}
<a class="pagination-previous" disabled>Previous</a>
{% endif %}

{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}&search={{ search }}" class="pagination-next">Next</a>
<a href="?page={{ page_obj.next_page_number }}&search={{ search|urlencode }}" class="pagination-next">Next</a>
{% else %}
<a class="pagination-next" disabled>Next</a>
{% endif %}

<ul class="pagination-list">
{% if page_obj.number != 1%}
<li>
<a href="?page=1&search={{ search }}" class="pagination-link" aria-label="Goto page 1">1</a>
<a href="?page=1&search={{ search|urlencode }}" class="pagination-link" aria-label="Goto page 1">1</a>
</li>
{% if page_obj.number > 2 %}
<li>
Expand All @@ -32,7 +32,7 @@
</li>
{% endif %}
<li>
<a href="?page={{ page_obj.paginator.num_pages }}&search={{ search }}" class="pagination-link" aria-label="Goto page {{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages }}</a>
<a href="?page={{ page_obj.paginator.num_pages }}&search={{ search|urlencode }}" class="pagination-link" aria-label="Goto page {{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages }}</a>
</li>
{% endif %}
</ul>
Expand Down
6 changes: 6 additions & 0 deletions vulnerabilities/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,9 @@ def test_with_invalid_cpes(self):
content_type="application/json",
).json()
assert response == {"Error": "Invalid CPE: CVE-2022-2022"}


class TesBanUserAgent(TestCase):
def test_ban_request_with_bytedance_user_agent(self):
response = self.client.get(f"/api/packages", format="json", HTTP_USER_AGENT="bytedance")
assert 404 == response.status_code
2 changes: 1 addition & 1 deletion vulnerablecode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import warnings
from pathlib import Path

__version__ = "33.6.2"
__version__ = "33.6.3"


def command_line():
Expand Down
1 change: 1 addition & 0 deletions vulnerablecode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"vulnerabilities.middleware.ban_user_agent.BanUserAgent",
)

ROOT_URLCONF = "vulnerablecode.urls"
Expand Down

0 comments on commit 7a512c2

Please sign in to comment.