fix(vulnerabilities): recognize host in historical target descriptions

This commit is contained in:
Sycun 2026-11-13 14:51:04 +08:00
parent 72042749e3
commit 9a0ea174b1
3 changed files with 25 additions and 8 deletions

View File

@ -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 ""
}

View File

@ -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"},

View File

@ -39,7 +39,7 @@
}
})();
</script>
<link rel="stylesheet" href="/static/css/style.css?v=20261113-chat-scroll">
<link rel="stylesheet" href="/static/css/style.css?v=20261113-vulnerability-host-groups">
<link rel="stylesheet" href="/static/css/vulnerability-download.css?v=20261030-2">
<link rel="stylesheet" href="/static/css/tool-guard.css?v=20260907-7">
<link rel="stylesheet" href="/static/css/chat-plan-progress.css?v=20260813-4">
@ -7081,7 +7081,7 @@
<script src="/static/js/skills.js?v=20261103-personal-integration"></script>
<script src="/static/js/fact-graph.js"></script>
<script src="/static/js/projects.js?v=20260819-1-pagination-20261027"></script>
<script src="/static/js/vulnerability.js?v=20261112-related-facts-theme"></script>
<script src="/static/js/vulnerability.js?v=20261113-vulnerability-host-groups"></script>
<script src="/static/js/vulnerability-download.js?v=20261030-2"></script>
<script src="/static/js/webshell.js?v=20261011-token-usage-tool-title"></script>
<script src="/static/js/chat-files.js?v=20261103-personal-integration"></script>