Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix(security): treat a trailing DNS root label as the same host in the allowlist

Luigi Agostic9ddb2ae727d
diff --git a/internal/security/allowlist.go b/internal/security/allowlist.go
index 8a4fdff2..8b59d30a 100644
--- a/internal/security/allowlist.go
+++ b/internal/security/allowlist.go
@@ -54,7 +54,7 @@ func HostMatchesPatterns(host string, patterns []string) bool {
// It handles both fully-qualified URLs ("https://example.com:8080/path") and
// bare hostnames ("example.com" or "example.com/path").
func ExtractHost(rawURL string) string {
- parsed, err := url.Parse(rawURL)
+ parsed, err := url.Parse(strings.TrimSpace(rawURL))
if err != nil {
return ""
}
@@ -73,7 +73,14 @@ func ExtractHost(rawURL string) string {
}
}
- return strings.ToLower(strings.TrimSpace(host))
+ // The DNS root label is silent: "example.com." and "example.com" name the
+ // same host and the browser fetches both. Leaving it on made the two answers
+ // differ, and this primitive is read in both directions — a listed host that
+ // stops matching is a refusal on a target the operator allowed, and the
+ // response-forgery rule reads the same answer inverted, where a listed host
+ // that stops matching PERMITS forgery on exactly the sensitive origin the
+ // list marks. navguard's host extractor already trimmed it.
+ return strings.TrimSuffix(strings.ToLower(strings.TrimSpace(host)), ".")
}
// IsAllowedSpecialURL reports whether rawURL is a non-routable URL that bypasses
diff --git a/internal/security/allowlist_test.go b/internal/security/allowlist_test.go
index 85863a95..13d1d985 100644
--- a/internal/security/allowlist_test.go
+++ b/internal/security/allowlist_test.go
@@ -75,3 +75,40 @@ func TestExtractHost_NoHost(t *testing.T) {
t.Errorf("ExtractHost('about:blank') = %q, want ''", got)
}
}
+
+// A fully-qualified name carrying the silent DNS root label is the same host:
+// the browser resolves and fetches "example.com." exactly as "example.com".
+// The allowlist is read in both directions, so a host that stops matching is
+// wrong twice over — a refusal on a target the operator listed, and, where the
+// answer is read inverted (bridge response forgery is BLOCKED on listed hosts),
+// permission to forge responses on the sensitive origin the list marks.
+func TestHostAllowed_TrailingRootLabelIsTheSameHost(t *testing.T) {
+ cases := []struct {
+ name string
+ rawURL string
+ allowed []string
+ }{
+ {"exact", "https://example.com./path", []string{"example.com"}},
+ {"exact with port", "https://example.com.:8443/path", []string{"example.com"}},
+ {"wildcard subdomain", "https://api.example.com./v1", []string{"*.example.com"}},
+ {"bare hostname", "example.com./path", []string{"example.com"}},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ if !HostAllowed(tc.rawURL, tc.allowed) {
+ t.Errorf("HostAllowed(%q, %v) = false; the root label names the same host", tc.rawURL, tc.allowed)
+ }
+ })
+ }
+}
+
+// The trim must not reach past the root label into the name itself, and it must
+// not turn a non-match into a match.
+func TestHostAllowed_TrailingRootLabelDoesNotWidenTheList(t *testing.T) {
+ if HostAllowed("https://evil.com./path", []string{"example.com"}) {
+ t.Error("an unlisted host matched the allowlist")
+ }
+ if got := ExtractHost("https://example.com../path"); got != "example.com." {
+ t.Errorf("ExtractHost trimmed more than the single root label: %q", got)
+ }
+}