Overview
The NVD Search module provides functions to search the National Vulnerability Database (NVD) for CVEs related to specific technologies and versions. It implements NIST SP 800-53 Rev. 5 controls for vulnerability scanning and assessment.NIST SP 800-53 Rev. 5 Controls Implemented
- SI-7 (Software, Firmware, and Information Integrity): Vulnerability assessment and monitoring
- RA-5 (Vulnerability Scanning): Automated vulnerability identification via NVD
- SC-7 (Boundary Protection): External API communication security
- AU-3 (Content of Audit Records): API interaction logging
- SI-4 (Information System Monitoring): Continuous vulnerability monitoring
Classes
NVDConfig
Maximum number of retry attempts for API calls
Initial delay in seconds between retry attempts
Default number of top CVEs to return
NVDAPIError
Functions
search_nvd()
The API key for accessing the NVD API
The CPE (Common Platform Enumeration) name for the technology
The version of the technology to search for
The technology name for display purposes
The category of the technology for display purposes
The number of top CVEs to return, sorted by CVSS score and published date
Optional configuration settings for retry behavior
A formatted string containing CVE information including:
- CVE ID
- Technology name and category
- Version
- CVSS score
- Published date
- Description
- Total vulnerabilities found
Error Handling
Raises:NVDAPIError: If there’s an error accessing the NVD API or processing the results- Handles timeout, HTTP errors (including rate limiting), and unexpected errors
- Returns error messages as formatted strings rather than raising exceptions
Example Usage
fetch_cpe_name()
The API key for accessing the NVD API
The CPE prefix for the technology (e.g., “cpe:2.3:a:apache:tomcat:”)
The version of the technology (defaults to wildcard)
The CPE name string. If the CPE is deprecated, returns the replacement CPE name.
Error Handling
Raises:NVDAPIError: If no CPE is found, API timeout occurs, rate limit is exceeded, or other HTTP/unexpected errors
Example Usage
retry_with_backoff()
The function to retry (should be a callable with no arguments)
Optional configuration settings. If None, uses default NVDConfig values.
The result of the function call if successful
Error Handling
Raises:NVDAPIError: If all retry attempts fail- Logs warnings for each retry attempt
- Implements exponential backoff (delay doubles after each attempt)
Example Usage
Implementation Notes
Logging
All functions implement comprehensive logging:- API key masking for security (only first 8 characters shown)
- Debug logs for CPE match strings and found CPE names
- Info logs for search queries and result counts
- Warning logs for processing errors
- Error logs for API failures
Security
- API keys are masked in all log output
- Never logs sensitive credentials
- Implements rate limit handling
- Uses secure retry logic with exponential backoff
Result Sorting
CVE results are sorted by:- CVSS score (descending)
- Published date (descending)