fix: thread-safe signature loading, clear missing-file error, restrict CORS methods
This commit is contained in:
+2
-2
@@ -30,8 +30,8 @@ app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.cors_origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
allow_methods=["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||
allow_headers=["Authorization", "Content-Type"],
|
||||
)
|
||||
|
||||
app.include_router(auth.router, prefix="/api/v1/auth", tags=["auth"])
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
"""Match nmap scan results against service_signatures.json."""
|
||||
import json
|
||||
import re
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
_SIGNATURES: list[dict[str, Any]] | None = None
|
||||
_LOCK = threading.Lock()
|
||||
|
||||
|
||||
def _load() -> list[dict[str, Any]]:
|
||||
global _SIGNATURES
|
||||
if _SIGNATURES is None:
|
||||
path = Path(__file__).parent.parent / "data" / "service_signatures.json"
|
||||
with open(path) as f:
|
||||
_SIGNATURES = json.load(f)
|
||||
with _LOCK:
|
||||
if _SIGNATURES is None:
|
||||
path = Path(__file__).parent.parent / "data" / "service_signatures.json"
|
||||
try:
|
||||
with open(path) as f:
|
||||
_SIGNATURES = json.load(f)
|
||||
except FileNotFoundError as err:
|
||||
raise FileNotFoundError(
|
||||
f"service_signatures.json not found at {path}. "
|
||||
"This file should be bundled with the application."
|
||||
) from err
|
||||
return _SIGNATURES
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user