Read a blocked_networks entry in the IPv4-mapped form as its IPv4 range (closes #301)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The fetcher matches an IPv4-mapped address (::ffff:a.b.c.d) as the IPv4 address it holds, so a blocked_networks entry written in that form was accepted and matched nothing. Such an entry is now kept as the IPv4 range it covers: ::ffff:10.0.0.0/104 becomes 10.0.0.0/8, and ::ffff:0:0/96 becomes 0.0.0.0/0. One shorter than /96 covers more than IPv4 addresses and aborts startup naming the setting. README.md says both. trusted_proxies shares the list parser, has the same fault and is unchanged here (issue 303). Model: opus-5-5
This commit was merged in pull request #302.
This commit is contained in:
@@ -91,6 +91,7 @@ var (
|
||||
errNotABoolean = errors.New("not a boolean")
|
||||
errNotAStringList = errors.New("not a list of strings")
|
||||
errNotAValidCIDR = errors.New("not a valid CIDR network")
|
||||
errMappedTooShort = errors.New("in the IPv4-mapped form but shorter than /96")
|
||||
errNotAMetricsMap = errors.New("not a map of metrics settings")
|
||||
errEmptyListEntry = errors.New("list contains an empty entry")
|
||||
errEmptyEntry = errors.New("contains an empty entry")
|
||||
@@ -271,7 +272,7 @@ func newFromSmartConfig(sc *smartconfig.Config) (*Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blockedNetworks, err := parseCIDRList(sc, keyBlockedNetworks)
|
||||
blockedNetworks, err := parseBlockedNetworks(sc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1278,6 +1279,39 @@ func parseCIDRList(sc *smartconfig.Config, key string) ([]netip.Prefix, error) {
|
||||
return prefixes, nil
|
||||
}
|
||||
|
||||
// parseBlockedNetworks parses blocked_networks with parseCIDRList, and keeps
|
||||
// an entry written in the IPv4-mapped form (::ffff:a.b.c.d) as the IPv4
|
||||
// range it covers: ::ffff:10.0.0.0/104 is kept as 10.0.0.0/8. The fetcher
|
||||
// matches an IPv4-mapped address as the IPv4 address it holds, so the entry
|
||||
// as written would match nothing. Such an entry shorter than /96 covers more
|
||||
// than the IPv4 addresses and aborts startup.
|
||||
func parseBlockedNetworks(sc *smartconfig.Config) ([]netip.Prefix, error) {
|
||||
prefixes, err := parseCIDRList(sc, keyBlockedNetworks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// An IPv4-mapped address is the 96 bits of ::ffff:0:0/96 followed by
|
||||
// the 32 bits of the IPv4 address it holds.
|
||||
const mappedPrefixBits = 96
|
||||
|
||||
for i, prefix := range prefixes {
|
||||
if !prefix.Addr().Is4In6() {
|
||||
continue
|
||||
}
|
||||
|
||||
if prefix.Bits() < mappedPrefixBits {
|
||||
return nil, fmt.Errorf("%s: value %q is %w",
|
||||
settingName(keyBlockedNetworks), prefix, errMappedTooShort)
|
||||
}
|
||||
|
||||
prefixes[i] = netip.PrefixFrom(prefix.Addr().Unmap(),
|
||||
prefix.Bits()-mappedPrefixBits)
|
||||
}
|
||||
|
||||
return prefixes, nil
|
||||
}
|
||||
|
||||
// parseHostList parses the value of the named config key into host patterns,
|
||||
// or returns nil if the key is omitted. It accepts a YAML list of strings or a
|
||||
// comma-separated string. An explicitly null value, a wrong type, an empty
|
||||
|
||||
Reference in New Issue
Block a user