Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,21 +564,6 @@ Below are the primary routes used by the app, with descriptions and basic usage.
- Request body: `{ "cve_id": string, "description": string, "severity": string }`
- Success response: 200 with `{ success: true, python_code }`

- **GET `/api/cves/aggregated/`**: Fetch aggregated CVEs from all sources with optional save
- Auth: Not required
- Query params: `limit?=number` (default 500), `api_key?=string`, `save?=true|false`
- Success response: 200 with `{ success: true, total_cves, statistics, cves }`

- **GET `/api/cves/statistics/`**: Fetch only statistics for aggregated CVEs
- Auth: Not required
- Query params: `limit?=number` (default 500), `api_key?=string`
- Success response: 200 with `{ success: true, total_cves, statistics }`

- **GET `/api/cves/threat-feed/`**: Fetch CVEs filtered by a specific threat feed
- Auth: Not required
- Query params: `threat_feed=string` (required), `limit?=number` (default 500), `api_key?=string`
- Success response: 200 with `{ success: true, threat_feed, total_cves, statistics, cves }`
- Errors: 400 if `threat_feed` is missing

- **POST `/api/cve-explanation/`**: Generate a CVE explanation and Mermaid diagram via AI
- Auth: Bearer token required (JWT)
Expand Down
Binary file modified backend/api/__pycache__/functions.cpython-313.pyc
Binary file not shown.
Binary file modified backend/api/__pycache__/views.cpython-313.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions backend/api/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def generate_waf_rule(cve_id: str, description: str, severity: str, mode: str, w

Return ONLY a JSON object with key:
- waf_rule

IMPORTANT:
- Make sure the WAF rule is valid for the chosen WAF.
- Make sure the WAF rule is valid for the chosen mode ( JSON or cURL).
"""

response = client.chat.completions.parse(
Expand Down
125 changes: 1 addition & 124 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Add the current directory to Python path to import our modules
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from .aggregate import fetch_all_cves, get_cve_statistics, save_aggregated_cves
from .aggregate import fetch_all_cves
from .functions import generate_cve_description_and_mermaid, generate_waf_rule, generate_testing_code

# Authentication Views
Expand Down Expand Up @@ -348,129 +348,6 @@ def update_cve_status(request):
"error": str(e)
}, status=500)

@api_view(['GET'])
@permission_classes([AllowAny])
def get_aggregated_cves(request):
"""
API endpoint to fetch aggregated CVEs from all sources.

Query parameters:
- limit: Number of CVEs per category (default: 50)
- api_key: Optional NVD API key for higher rate limits
- save: Whether to save to file (default: false)
"""
try:
# Get query parameters
limit = int(request.GET.get('limit', 500))
api_key = request.GET.get('api_key', None)
save_to_file = request.GET.get('save', 'false').lower() == 'true'

# Fetch CVEs
cves = fetch_all_cves(limit_per_category=limit, api_key=api_key)

# Get statistics
stats = get_cve_statistics(cves)

# Save to file if requested
if save_to_file:
save_aggregated_cves(cves, "aggregated_cves.json")

# Prepare response
response_data = {
"success": True,
"total_cves": len(cves),
"statistics": stats,
"cves": cves
}

print(cves[:10])

return Response(response_data)

except Exception as e:
return Response({
"success": False,
"error": str(e)
}, status=500)

@api_view(['GET'])
@permission_classes([AllowAny])
def get_cve_statistics_only(request):
"""
API endpoint to get only CVE statistics without the full CVE data.
"""
try:
# Get query parameters
limit = int(request.GET.get('limit', 500))
api_key = request.GET.get('api_key', None)

# Fetch CVEs
cves = fetch_all_cves(limit_per_category=limit, api_key=api_key)

# Get statistics
stats = get_cve_statistics(cves)

# Prepare response
response_data = {
"success": True,
"total_cves": len(cves),
"statistics": stats
}

return Response(response_data)

except Exception as e:
return Response({
"success": False,
"error": str(e)
}, status=500)

@api_view(['GET'])
@permission_classes([AllowAny])
def get_cves_by_threat_feed(request):
"""
API endpoint to get CVEs filtered by threat feed.

Query parameters:
- threat_feed: Specific threat feed to filter by
- limit: Number of CVEs per category (default: 50)
- api_key: Optional NVD API key
"""
try:
threat_feed = request.GET.get('threat_feed', None)
limit = int(request.GET.get('limit', 500))
api_key = request.GET.get('api_key', None)

if not threat_feed:
return Response({
"success": False,
"error": "threat_feed parameter is required"
}, status=400)

# Fetch all CVEs
cves = fetch_all_cves(limit_per_category=limit, api_key=api_key)

# Filter by threat feed
filtered_cves = [cve for cve in cves if cve.get('threat_feed') == threat_feed]

# Get statistics for filtered CVEs
stats = get_cve_statistics(filtered_cves)

response_data = {
"success": True,
"threat_feed": threat_feed,
"total_cves": len(filtered_cves),
"statistics": stats,
"cves": filtered_cves
}

return Response(response_data)

except Exception as e:
return Response({
"success": False,
"error": str(e)
}, status=500)

@api_view(['POST'])
@authentication_classes([JWTAuthentication])
Expand Down
Binary file modified backend/backend/__pycache__/urls.cpython-313.pyc
Binary file not shown.
6 changes: 1 addition & 5 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
)
from api.views import (
LoginView, RegisterView, get_user_cves, refresh_user_cves,
update_cve_status, get_aggregated_cves, get_cve_statistics_only,
get_cves_by_threat_feed, cve_explanation, waf_rule, get_user_profile,
update_cve_status, cve_explanation, waf_rule, get_user_profile,
generate_cve_testing_code
)

Expand All @@ -41,9 +40,6 @@
path('api/auth/register/', RegisterView.as_view(), name='register'),

# CVE endpoints
path('api/cves/aggregated/', get_aggregated_cves, name='get_aggregated_cves'),
path('api/cves/statistics/', get_cve_statistics_only, name='get_cve_statistics'),
path('api/cves/threat-feed/', get_cves_by_threat_feed, name='get_cves_by_threat_feed'),
path('api/cve-explanation/', cve_explanation, name='cve_explanation'),
path('api/waf-rule/', waf_rule, name='waf_rule'),
path('api/generate-testing-code/', generate_cve_testing_code, name='generate_cve_testing_code'),
Expand Down
Binary file modified backend/db.sqlite3
Binary file not shown.