fix: thread-safe signature loading, clear missing-file error, restrict CORS methods

This commit is contained in:
Pouzor
2026-03-27 18:01:43 +01:00
parent 0f643477f6
commit 09b5317a0c
2 changed files with 15 additions and 5 deletions
+2 -2
View File
@@ -30,8 +30,8 @@ app.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=settings.cors_origins, allow_origins=settings.cors_origins,
allow_credentials=True, allow_credentials=True,
allow_methods=["*"], allow_methods=["GET", "POST", "PUT", "PATCH", "DELETE"],
allow_headers=["*"], allow_headers=["Authorization", "Content-Type"],
) )
app.include_router(auth.router, prefix="/api/v1/auth", tags=["auth"]) app.include_router(auth.router, prefix="/api/v1/auth", tags=["auth"])
+10
View File
@@ -1,18 +1,28 @@
"""Match nmap scan results against service_signatures.json.""" """Match nmap scan results against service_signatures.json."""
import json import json
import re import re
import threading
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
_SIGNATURES: list[dict[str, Any]] | None = None _SIGNATURES: list[dict[str, Any]] | None = None
_LOCK = threading.Lock()
def _load() -> list[dict[str, Any]]: def _load() -> list[dict[str, Any]]:
global _SIGNATURES global _SIGNATURES
if _SIGNATURES is None:
with _LOCK:
if _SIGNATURES is None: if _SIGNATURES is None:
path = Path(__file__).parent.parent / "data" / "service_signatures.json" path = Path(__file__).parent.parent / "data" / "service_signatures.json"
try:
with open(path) as f: with open(path) as f:
_SIGNATURES = json.load(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 return _SIGNATURES