Files
searxng/searx/engines/nvd.py
Onev 9e25585aec [refactor] engines: use datetime.fromisoformat instead of datetime.strptime where possible (#6394)
Refactor engines that parse ISO 8601 dates with strptime to use
fromisoformat instead. In most cases this is a direct replacement of
strptime(text, "format") with fromisoformat(text).

For engines where the source has a trailing "Z" that strptime consumed
as a literal (e.g. "%Y-%m-%dT%H:%M:%S.%fZ" in huggingface.py), add
rstrip("Z") to keep the output naive and preserve the existing behavior.

In sogou.py the date is extracted with a regular expression, which can
yield strings like "2026-7-11". strptime accepts this via its format
string, but fromisoformat does not. To preserve the existing behavior
and satisfy the format fromisoformat expects, add zero-padding for the
month and day.

Closes: #6098
---------
Signed-off-by: OneVth <onebrotravel@gmail.com>
2026-07-13 17:46:56 +02:00

69 lines
2.0 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""National Vulnerability Database (it)"""
from urllib.parse import urlencode
from datetime import datetime
from searx.result_types import EngineResults
about = {
"website": 'https://nvd.nist.gov',
"wikidata_id": "Q6979334",
"official_api_documentation": None,
"use_official_api": False,
"require_api_key": False,
"results": "JSON",
}
base_url = "https://nvd.nist.gov/extensions/nudp/services/json/nvd/cve/search/results"
categories = ['it']
paging = True
results_per_page = 10
def request(query, params):
start_index = (params["pageno"] - 1) * results_per_page
query_params = {
"resultType": "records",
"keyword": query,
"rowCount": results_per_page,
"offset": start_index,
}
params["url"] = f"{base_url}?{urlencode(query_params)}"
params['headers']['Referer'] = "https://nvd.nist.gov/vuln/search"
return params
def response(resp) -> EngineResults:
results = EngineResults()
search_res = resp.json()
for item in search_res['response'][0]['grid']['vulnerabilities']:
cve_id = item["cve"]["id"]
description = item["cve"]["descriptions"][0]["value"]
date = datetime.fromisoformat(item["cve"]["published"])
# Extract severity (Low, Medium, High, or Critical) and CVSS score, if available
info = item["cve"].get("metrics", {}).get("cvssMetricV31", [{}])[0].get("cvssData", {})
severity = info.get("baseSeverity")
cvss_score = info.get("baseScore")
metadata = ""
if severity and cvss_score is not None:
metadata = f"Severity: {severity} | CVSS Score: {cvss_score}"
results.add(
results.types.MainResult(
url=f'https://nvd.nist.gov/vuln/detail/{cve_id}',
title=cve_id,
publishedDate=date,
metadata=metadata,
content=description,
)
)
return results