fix CVE data sync and signalr join

This commit is contained in:
Oliver Kieselbach
2026-03-27 20:48:35 +01:00
parent 8a1c8a553c
commit c4dabeeef4
5 changed files with 32 additions and 18 deletions
@@ -1 +1 @@
623
627
@@ -200,11 +200,14 @@ namespace AutopilotMonitor.Functions.Functions.Vulnerability
var cveDataJson = System.Text.Json.JsonSerializer.Serialize(cves);
// Guard 64KB limit
if (cveDataJson.Length > 60_000)
// Guard 64KB limit — iteratively halve until it fits
var cacheCves = cves;
while (cveDataJson.Length > 60_000 && cacheCves.Count > 10)
{
var reduced = cves.Take(cves.Count / 2).ToList();
cveDataJson = System.Text.Json.JsonSerializer.Serialize(reduced);
cacheCves = cacheCves.Take(cacheCves.Count / 2).ToList();
cveDataJson = System.Text.Json.JsonSerializer.Serialize(cacheCves);
_logger.LogInformation("[VulnSync] Reduced CVE cache for {CpeUri} to {Count} entries ({Bytes} chars)",
cpeUri, cacheCves.Count, cveDataJson.Length);
}
var data = new Dictionary<string, object>
@@ -92,8 +92,8 @@ public static class EndpointAccessPolicyCatalog
new("GET", "auth/me", EndpointPolicy.AuthenticatedUser),
new("GET", "auth/is-global-admin", EndpointPolicy.AuthenticatedUser),
new("POST", "realtime/negotiate", EndpointPolicy.AuthenticatedUser),
new("POST", "realtime/groups/join", EndpointPolicy.AuthenticatedUser),
new("POST", "realtime/groups/leave", EndpointPolicy.AuthenticatedUser),
new("POST", "realtime/groups/join", EndpointPolicy.MemberRead),
new("POST", "realtime/groups/leave", EndpointPolicy.MemberRead),
new("GET", "progress/sessions", EndpointPolicy.AuthenticatedUser),
new("GET", "progress/sessions/{sessionId}/events", EndpointPolicy.AuthenticatedUser),
new("PUT", "preview/notification-email", EndpointPolicy.AuthenticatedUser),
@@ -474,20 +474,31 @@ namespace AutopilotMonitor.Functions.Services.Vulnerability
// Persist to repository (best-effort, don't fail the request)
try
{
var cveDataJson = JsonSerializer.Serialize(cves, JsonOptions);
var cacheCves = cves
.OrderByDescending(c => c.CvssScore)
.ThenByDescending(c => c.PublishedDate)
.ToList();
var cveDataJson = JsonSerializer.Serialize(cacheCves, JsonOptions);
// Guard against exceeding Table Storage 64KB single-property limit
// Iteratively halve until it fits (floor: 10 CVEs)
while (cveDataJson.Length > 60_000 && cacheCves.Count > 10)
{
cacheCves = cacheCves.Take(cacheCves.Count / 2).ToList();
cveDataJson = JsonSerializer.Serialize(cacheCves, JsonOptions);
_logger.LogInformation("Reduced CVE cache for {CpeUri} to {Count} entries ({Bytes} chars) to fit 64KB limit",
cpeUri, cacheCves.Count, cveDataJson.Length);
}
// Last resort: strip Criteria strings (biggest space consumer) and retry
if (cveDataJson.Length > 60_000)
{
// Further reduce until it fits
var reduced = cves
.OrderByDescending(c => c.CvssScore)
.ThenByDescending(c => c.PublishedDate)
.Take(cves.Count / 2)
.ToList();
cveDataJson = JsonSerializer.Serialize(reduced, JsonOptions);
_logger.LogInformation("Further reduced CVE cache for {CpeUri} to {Count} entries to fit 64KB limit",
cpeUri, reduced.Count);
foreach (var c in cacheCves)
foreach (var v in c.AffectedVersions)
v.Criteria = null;
cveDataJson = JsonSerializer.Serialize(cacheCves, JsonOptions);
_logger.LogWarning("Stripped Criteria from CVE cache for {CpeUri} to fit 64KB limit ({Bytes} chars)",
cpeUri, cveDataJson.Length);
}
var data = new Dictionary<string, object>