synfinner / KEVin

The missing API for the CISA Known Exploited Vulnerabilities Catalog. This repository contains the source running at kevin.gtfkd.com
https://kevin.gtfkd.com/
7 stars 0 forks source link

Vuln sort order is inccorect #196

Closed synfinner closed 2 months ago

synfinner commented 2 months ago

When sorting vulnerabilities by days, it is not sticking to the sort order of newest to oldest.

This is caused by introduction of:

greenlets.append(spawn(self.query_database, field, cutoff_date, page, per_page))

We should be sending:

greenlets.append(spawn(self.query_database, field, cutoff_date, page, per_page, sort_order=-1))

And refactor the query database function to:

def query_database(self, field, cutoff_date, page, per_page, sort_order=1):
         """Query the database for recent vulnerabilities with pagination."""
         skip = (page - 1) * per_page  # Calculate how many documents to skip
         recent_vulnerabilities = all_vulns_collection.find(
             {field: {"$gt": cutoff_date}}
          ).sort(field, sort_order).skip(skip).limit(per_page)  # Apply sorting and pagination

This was the sort is being sent and respected.

synfinner commented 2 months ago

Merged commit that fixes this issue