A FastAPI-powered REST API for querying CVE (Common Vulnerabilities and Exposures) data from the National Vulnerability Database (NVD) with MongoDB storage. Designed for security researchers and developers to programmatically access vulnerability information.
- Automatic NVD Synchronization: Sync latest CVEs from NVD's REST API
- Advanced Querying: Search by CVE ID, publication year, score, and date ranges
- MongoDB Backend: Scalable NoSQL storage for vulnerability data
- RESTful Endpoints: Easy integration with security tools and workflows
- Pagination Support: Built-in MongoDB cursor handling for large datasets
- Date Filtering: Search by last N days or custom date ranges
- Python 3.8+
- FastAPI (Web Framework)
- MongoDB (Database)
- httpx (Async HTTP Client)
- Pymongo (MongoDB Driver)
- Python 3.8+
- MongoDB (running locally on port 27017)
git clone https://github.com/tharun-dv/NVD-API.git cve-api
cd cve-api
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtCreate .env file:
MONGODB_URL=mongodb://localhost:27017| Endpoint | Method | Description |
|---|---|---|
/sync |
GET | Sync latest CVEs from NVD |
/find |
GET | Get first 100 CVEs |
/cve/id/{id} |
GET | Get CVE by ID (path param) |
/cve/search/?id=CVE-... |
GET | Get CVE by ID (query param) |
/cve/year/{year} |
GET | Get CVEs by publication year |
/cve/year/?year1=YYYY&year2=YYYY |
GET | Get CVEs between years |
/score/{score} |
GET | Get CVEs by CVSS base score |
/cve/last/{N} |
GET | Get CVEs modified in last N days |
curl -X GET "http://localhost:8000/sync"{"message":"Synced 50 CVEs"}curl "http://localhost:8000/cve/id/CVE-2023-1234"{
"_id": "64f1a2b3...",
"cve": {
"id": "CVE-2023-1234",
"published": "2023-01-01T00:00Z",
"metrics": {
"cvssMetricV2": [
{
"cvssData": {
"baseScore": 7.5
}
}
]
}
}
}curl "http://localhost:8000/cve/last/7"- Rate Limiting: Default 5 requests/second (NVD public limit)
- Pagination: MongoDB's native cursor handling (modify queries as needed)
- Storage: All CVEs stored in
Exploits.CVEscollection - Indexing: Recommended to create indexes on:
db.CVEs.create_index("cve.id") db.CVEs.create_index("cve.published")
uvicorn main:app --reloaddocker build -t cve-api .
docker run -p 8000:8000 cve-apiMIT License
- Data Freshness: NVD updates occur every 2 hours - sync regularly
- Rate Limiting: Add API gateway for production deployments
- Authentication: Implement API key auth for sensitive deployments
- Data Validation: Validate all NVD responses before storage