fix: the crawler and the Chrome guard keep to the site's port

Fetcher.Allowed and Key, the rendered comparison and the Chrome request
guard accept an address only on the site's effective port (explicit,
else 443 for https and 80 for http), so page code cannot make headless
Chrome reach other services on the site host's address and a link to
another port is not reported as a page of the site.
This commit is contained in:
Jakub Zych
2026-11-04 22:56:02 +01:00
parent cfeb3dff12
commit 3fdb44bce2
9 changed files with 138 additions and 48 deletions

View File

@@ -103,7 +103,7 @@ func NewRenderer(ctx context.Context, cfg *compass.Config, site *url.URL, truste
if err != nil {
return nil, err
}
r, err := newChromeRenderer(path, hosts, trusted, ua)
r, err := newChromeRenderer(path, hosts, effectivePort(site), trusted, ua)
if err != nil {
return nil, err
}
@@ -161,9 +161,11 @@ func resolverRules(hosts map[string][]netip.Addr) string {
}
// allowRequest reports whether the headless browser may load rawURL: https
// (http only in trusted mode) to one of hosts, or a data: or blob: URL.
// Every other request, third-party scripts included, is failed.
func allowRequest(rawURL string, hosts []string, trusted bool) bool {
// (http only in trusted mode) to one of hosts on the site's effective port
// (port; the request's explicit port, else 443 for https and 80 for http),
// or a data: or blob: URL. Every other request, third-party scripts and
// other services on the site host's address included, is failed.
func allowRequest(rawURL string, hosts []string, port string, trusted bool) bool {
u, err := url.Parse(rawURL)
if err != nil {
return false
@@ -179,7 +181,7 @@ func allowRequest(rawURL string, hosts []string, trusted bool) bool {
default:
return false
}
if u.User != nil {
if u.User != nil || effectivePort(u) != port {
return false
}
host := strings.ToLower(u.Hostname())