refactor(publicnet): one public-address dial guard for webhooks, attachments and web fetch (#1795)
deploy / gate (push) Failing after 8m13s
deploy / archied-image (push) Skipped
deploy / agent-image (push) Skipped
deploy / dist-zip (push) Skipped

This commit is contained in:
sam committed 2026-11-08 15:52:39 +11:00
1 parent 8f37cc79cd
commit b548cabcbf
5 files changed
+45 -55

No files matched your search

+6 -21
View File
@@ -14,6 +14,8 @@ import (
"time"
"golang.org/x/net/html"
"github.com/samcharles93/archie-core/internal/infrastructure/publicnet"
)
const (
@@ -38,9 +40,9 @@ type Config struct {
// MaxBytes bounds how much of a response body is read.
MaxBytes int64
// AllowPrivateNetworks permits loopback, private, link-local and
// carrier-grade-NAT addresses. Off by default: leaving it off is what
// keeps the daemon's own control surfaces out of reach.
// AllowPrivateNetworks permits addresses off the public internet. Off by
// default: leaving it off is what keeps the daemon's own control surfaces
// out of reach.
AllowPrivateNetworks bool
}
@@ -245,24 +247,7 @@ func (c *Client) addressAllowed(ip net.IP) bool {
if c.cfg.AllowPrivateNetworks {
return true
}
switch {
case ip.IsLoopback(), ip.IsPrivate(), ip.IsUnspecified(),
ip.IsLinkLocalUnicast(), ip.IsLinkLocalMulticast(),
ip.IsInterfaceLocalMulticast(), ip.IsMulticast():
return false
case isCarrierGradeNAT(ip):
return false
default:
return true
}
}
// isCarrierGradeNAT reports whether ip is in 100.64.0.0/10, which net.IP has
// no predicate for and which routes to infrastructure rather than the public
// internet.
func isCarrierGradeNAT(ip net.IP) bool {
v4 := ip.To4()
return v4 != nil && v4[0] == 100 && v4[1] >= 64 && v4[1] <= 127
return publicnet.Public(ip)
}
// blockedElements hold text that is markup machinery rather than content.