new seed file

This commit is contained in:
Oliver Kieselbach
2026-04-07 09:47:59 +02:00
parent 91e3e5e597
commit 3a5bf83b7c
2 changed files with 53 additions and 2 deletions
+2 -2
View File
@@ -179,8 +179,8 @@
"displayNamePatterns": ["microsoft visual c++ 2015-2022", "microsoft visual c++ 2015-2019", "visual c++ redistributable", "microsoft visual c++"],
"publisherPatterns": ["microsoft", "microsoft corporation"],
"cpeVendor": "microsoft",
"cpeProduct": "visual_c%2b%2b",
"cpeUri": "cpe:2.3:a:microsoft:visual_c%2b%2b",
"cpeProduct": "visual_c\\+\\+",
"cpeUri": "cpe:2.3:a:microsoft:visual_c\\+\\+",
"category": "runtime"
},
{
@@ -0,0 +1,51 @@
using System.Text;
namespace AutopilotMonitor.Functions.Services.Vulnerability
{
/// <summary>
/// Normalizes CPE 2.3 formatted strings into their canonical NVD form.
///
/// Background: NVD's CPE Dictionary uses the CPE 2.3 "formatted string" form
/// (NIST IR 7695), which requires special characters like '+' to be quoted
/// with a backslash, e.g. "visual_c\+\+". The NVD website often displays the
/// URL-encoded form ("visual_c%2b%2b") in browser address bars, which leads
/// users to copy that into custom mappings — but the API expects the
/// backslash-quoted form. Storing the URL-encoded form causes
/// double-encoding when the value is later passed through
/// Uri.EscapeDataString and breaks both NVD lookups and cache key matching.
///
/// This helper rewrites URL-encoded '+' (%2B/%2b) and bare '+' into '\+',
/// while leaving already-quoted '\+' alone. Other CPE special characters
/// are intentionally not handled here — '+' is the only one observed in
/// practice — to avoid surprising rewrites of legitimate wildcard chars
/// (e.g. '*' which has semantic meaning as ANY in CPE 2.3).
/// </summary>
public static class CpeUriNormalizer
{
public static string Normalize(string? value)
{
if (string.IsNullOrEmpty(value)) return value ?? string.Empty;
// 1) URL-decode the only encoding we care about: %2B / %2b -> +
// (Done manually to avoid touching other %xx sequences that may
// legitimately appear inside a CPE token.)
var decoded = value!.Replace("%2B", "+").Replace("%2b", "+");
// 2) Backslash-quote every bare '+' (i.e. '+' not already preceded
// by a backslash). Walk char-by-char so we don't double-quote.
var sb = new StringBuilder(decoded.Length + 4);
for (int i = 0; i < decoded.Length; i++)
{
char c = decoded[i];
if (c == '+')
{
bool alreadyQuoted = i > 0 && decoded[i - 1] == '\\';
if (!alreadyQuoted) sb.Append('\\');
}
sb.Append(c);
}
return sb.ToString();
}
}
}