feat(dingtalk): enable secure multimodal image QA

This commit is contained in:
姚章浩
2026-07-16 00:17:16 +08:00
parent 4022040e98
commit c9c4f0aaa5
59 changed files with 3279 additions and 429 deletions
+37 -13
View File
@@ -226,6 +226,14 @@ var restrictedHostSuffixes = []string{
var restrictedIPv4Ranges = []*net.IPNet{
// 100.64.0.0/10 - Carrier-grade NAT (RFC 6598)
mustParseCIDR("100.64.0.0/10"),
// 192.31.196.0/24 - AS112-v4 special-purpose service
mustParseCIDR("192.31.196.0/24"),
// 192.52.193.0/24 - AMT special-purpose service
mustParseCIDR("192.52.193.0/24"),
// 192.88.99.0/24 - Deprecated 6to4 relay anycast
mustParseCIDR("192.88.99.0/24"),
// 192.175.48.0/24 - Direct Delegation AS112 service
mustParseCIDR("192.175.48.0/24"),
// 198.18.0.0/15 - Network device benchmark testing (RFC 2544)
mustParseCIDR("198.18.0.0/15"),
// 198.51.100.0/24 - TEST-NET-2 for documentation (RFC 5737)
@@ -250,6 +258,22 @@ var restrictedIPv4Ranges = []*net.IPNet{
mustParseCIDR("172.20.0.0/16"),
}
// restrictedIPv6Ranges contains special-purpose address space that must not be
// used as an outbound media-fetch destination. These ranges are not ordinary
// public unicast destinations and some can translate or encapsulate IPv4.
var restrictedIPv6Ranges = []*net.IPNet{
mustParseCIDR("64:ff9b::/96"),
mustParseCIDR("64:ff9b:1::/48"),
mustParseCIDR("100::/64"),
mustParseCIDR("100:0:0:1::/64"),
mustParseCIDR("2001::/23"),
mustParseCIDR("2001:db8::/32"),
mustParseCIDR("2002::/16"),
mustParseCIDR("2620:4f:8000::/48"),
mustParseCIDR("3fff::/20"),
mustParseCIDR("5f00::/16"),
}
// mustParseCIDR parses a CIDR string and panics on error
func mustParseCIDR(s string) *net.IPNet {
_, ipNet, err := net.ParseCIDR(s)
@@ -289,6 +313,19 @@ func isRestrictedIP(ip net.IP) (bool, string) {
// Check IPv6-specific restrictions
if ip.To4() == nil && len(ip) == 16 {
// Preserve explicit diagnostics for tunneling prefixes before the broader
// IANA special-purpose range table.
if ip[0] == 0x20 && ip[1] == 0x01 && ip[2] == 0x00 && ip[3] == 0x00 {
return true, "Teredo tunneling address"
}
if ip[0] == 0x20 && ip[1] == 0x02 {
return true, "6to4 special-purpose address"
}
for _, cidr := range restrictedIPv6Ranges {
if cidr.Contains(ip) {
return true, fmt.Sprintf("restricted range %s", cidr.String())
}
}
// Site-local (deprecated but still blocked): fec0::/10
if ip[0] == 0xfe && (ip[1]&0xc0) == 0xc0 {
return true, "site-local IPv6 address"
@@ -304,19 +341,6 @@ func isRestrictedIP(ip net.IP) (bool, string) {
return true, fmt.Sprintf("IPv4-mapped %s", reason)
}
}
// Teredo tunneling addresses: 2001:0000::/32
// Embed arbitrary IPv4 in the payload; can reach internal hosts via relay.
if ip[0] == 0x20 && ip[1] == 0x01 && ip[2] == 0x00 && ip[3] == 0x00 {
return true, "Teredo tunneling address"
}
// 6to4 addresses: 2002::/16
// Bits 16-47 carry an IPv4 address; block when embedded IPv4 is restricted.
if ip[0] == 0x20 && ip[1] == 0x02 {
embeddedIP := net.IP(ip[2:6])
if restricted, reason := isRestrictedIP(embeddedIP); restricted {
return true, fmt.Sprintf("6to4 embedded %s", reason)
}
}
}
return false, ""