diff --git a/internal/database/vulnerability.go b/internal/database/vulnerability.go index 52847a63..eae814e7 100644 --- a/internal/database/vulnerability.go +++ b/internal/database/vulnerability.go @@ -7,6 +7,7 @@ import ( "net/url" "strings" "time" + "unicode" "github.com/google/uuid" "go.uber.org/zap" @@ -247,15 +248,31 @@ func (db *DB) ListVulnerabilitiesByHostForAccess(limit, offset int, filter Vulne func vulnerabilityTargetHost(target string) string { target = strings.TrimSpace(target) + // Historical findings can append endpoint notes or secondary targets to + // the primary URL or host. Use the leading target for a single group. + if end := strings.IndexFunc(target, func(r rune) bool { + return unicode.IsSpace(r) || strings.ContainsRune("(),;、(,;", r) + }); end >= 0 { + target = target[:end] + } if ip, err := netip.ParseAddr(target); err == nil { return ip.String() } scheme, _, hasScheme := strings.Cut(target, "://") explicitURL := strings.HasPrefix(target, "//") || (hasScheme && !strings.ContainsAny(scheme, "/?#")) - if !explicitURL { - target = "//" + target + if explicitURL { + if strings.HasPrefix(target, "//") { + target = strings.TrimPrefix(target, "//") + } else { + target = target[len(scheme)+3:] + } } - parsed, err := url.Parse(target) + // Paths and queries can contain raw request fragments or malformed escape + // sequences. Host extraction only needs the authority. + if end := strings.IndexAny(target, "/?#"); end >= 0 { + target = target[:end] + } + parsed, err := url.Parse("//" + target) if err != nil || parsed.Host == "" { return "" } diff --git a/internal/handler/vulnerability_group_test.go b/internal/handler/vulnerability_group_test.go index b54fb9ae..6b64082e 100644 --- a/internal/handler/vulnerability_group_test.go +++ b/internal/handler/vulnerability_group_test.go @@ -23,9 +23,9 @@ func TestListVulnerabilitiesGroupedByHost(t *testing.T) { for i, item := range []struct { id, target, severity string }{ - {"domain-old", "HTTPS://Example.COM.:443/login", "high"}, - {"domain-new", "example.com:8443/api", "high"}, - {"subdomain", "https://sub.example.com/api", "high"}, + {"domain-old", "HTTPS://Example.COM.:443/login?keyword=%ZZ (旧接口);https://secondary.example.net/", "high"}, + {"domain-new", "example.com:8443(受影响的服务)", "high"}, + {"subdomain", "https://sub.example.com(旧记录)", "high"}, {"ipv6", "https://[2001:0DB8::1]:8080/", "high"}, {"unknown", "/api/login", "high"}, {"filtered", "https://other.example.com/", "low"}, diff --git a/web/templates/index.html b/web/templates/index.html index c2d01156..47298b9f 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -39,7 +39,7 @@ } })(); - + @@ -7081,7 +7081,7 @@ - +