A FastAPI-based backend service for tracking and identifying vulnerabilities in Python project dependencies using the OSV.dev API.
- 🔍 Vulnerability Scanning: Automatically scans Python dependencies for known vulnerabilities
- 📦 Project Management: Create and manage multiple Python projects
- 🔄 Caching: Intelligent caching system to optimize API response times
- 📊 Dependency Tracking: Track dependencies across multiple projects
- 🚨 Real-time Updates: Refresh vulnerability data on demand
- 🛡️ Security Focus: Leverages OSV.dev's comprehensive vulnerability database
- FastAPI
- Python 3.10+
- HTTPX (for async requests to OSV)
- Pytest (for unit tests)
- Clone the repository:
git clone https://github.com/Sepidband/vulnerability-tracker.git
cd vulnerability-tracker- Install dependencies:
python -m venv msvenv
source msvenv/bin/activate
pip install -r requirements.txt- Run the application:
uvicorn main:app --reloadThe API will be available at http://localhost:8000
Once running, visit:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
POST /projects- Create a new projectGET /projects- List all projectsGET /projects/{id}- Get project detailsGET /projects/{id}/dependencies- Get project dependenciesPOST /projects/{id}/refresh- Refresh vulnerability data
GET /dependencies- List all dependenciesGET /dependencies/{name}/{version}- Get dependency details
GET /health- Health checkGET /cache/stats- Cache statisticsPOST /cache/clear- Clear cache
curl -X POST "http://localhost:8000/projects" \
-H "Content-Type: application/json" \
-d '{
"name": "My Python Project",
"description": "A sample project for testing",
"requirements_txt": "fastapi==0.104.1\nuvicorn==0.24.0\npydantic==2.5.0"
}'curl "http://localhost:8000/projects/{project_id}"curl -X POST "http://localhost:8000/projects/{project_id}/refresh"main.py: FastAPI application and route definitionsmodels.py: Pydantic models for data structuresschemas.py: Request/response schemasservices.py: Business logic and external API integrationcache.py: Caching layer for performance optimization
- 24-hour TTL for vulnerability data
- Automatic cache invalidation on refresh
- Thread-safe cache operations
- Parallel vulnerability checks using asyncio
- Semaphore-based rate limiting for external API calls
- Optimized performance for multiple dependencies
- Comprehensive exception handling
- Graceful degradation on API failures
- Detailed error responses
Run the test suite:
pytest tests/ -v- Unit tests for all core components
- Integration tests for API endpoints
- Mock testing for external dependencies
- Error handling scenarios
- Caching: Reduces redundant API calls to OSV.dev
- Async Operations: Non-blocking I/O for better concurrency
- Batch Processing: Efficient handling of multiple dependencies
- Rate Limiting: Prevents API overload
CACHE_TTL_HOURS: Cache time-to-live (default: 24)MAX_CONCURRENT_REQUESTS: Maximum concurrent OSV API requests (default: 5)
The application can be extended with:
- Database persistence (replace in-memory storage)
- Authentication and authorization
- Webhook notifications
- Custom vulnerability sources
- Advanced reporting features
- All vulnerability data is sourced from OSV.dev
- No persistent storage of sensitive information
- Input validation on all endpoints
- Rate limiting to prevent abuse
vulnerability-tracker/
├── main.py # FastAPI application
├── models.py # Data models
├── schemas.py # API schemas
├── services.py # Business logic
├── cache.py # Caching layer
├── requirements.txt # Dependencies
├── tests/
│ └── test_api.py # Test suite
│ └── __init__.py # init
└── README.md # This file
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Use clear, descriptive commit messages:
feat: add new endpoint for bulk vulnerability refreshfix: handle edge case in requirements.txt parsingdocs: update API documentationtest: add integration tests for dependency tracking
- Initial release with core functionality
- Project and dependency management
- OSV.dev integration
- Caching system
- Comprehensive test suite