fix(security): support IPv6 in SSRF validation via whitelist mechanism
- Keep strict mode blocking all direct IPs (IPv4 and IPv6 uniformly) - Unify all SSRF call sites to use ValidateURLForSSRF (whitelist-aware) - Add Teredo (2001:0000::/32) and 6to4 (2002::/16) tunnel detection - Make redirect handler and DNS pinning respect SSRF_WHITELIST - Unexport isSSRFSafeURL to prevent future callers bypassing whitelist - Add scheme validation for whitelisted redirect targets - Document IPv6 whitelist syntax in .env.example - Add comprehensive IPv6 test coverage
This commit is contained in:
@@ -667,9 +667,9 @@ func (r *ImageResolver) ResolveRemoteImages(
|
||||
continue
|
||||
}
|
||||
|
||||
// --- SSRF check ---
|
||||
if safe, reason := secutils.IsSSRFSafeURL(imgURL); !safe {
|
||||
log.Printf("WARN: remote image blocked by SSRF check (%s): %s", reason, imgURL)
|
||||
// --- SSRF check (centralised entry-point with whitelist support) ---
|
||||
if err := secutils.ValidateURLForSSRF(imgURL); err != nil {
|
||||
log.Printf("WARN: remote image blocked by SSRF check (%v): %s", err, imgURL)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -345,8 +345,8 @@ func (c *MinerUCloudReader) extractDoneResult(_ context.Context, item *extractRe
|
||||
var imgRefPattern = regexp.MustCompile(`!\[[^\]]*\]\(([^)]+)\)`)
|
||||
|
||||
func downloadAndExtractZip(zipURL string) (string, []types.ImageRef, error) {
|
||||
if safe, reason := utils.IsSSRFSafeURL(zipURL); !safe {
|
||||
return "", nil, fmt.Errorf("zip URL blocked by SSRF check: %s", reason)
|
||||
if err := utils.ValidateURLForSSRF(zipURL); err != nil {
|
||||
return "", nil, fmt.Errorf("zip URL blocked by SSRF check: %v", err)
|
||||
}
|
||||
client := utils.NewSSRFSafeHTTPClient(utils.SSRFSafeHTTPClientConfig{Timeout: 120 * time.Second, MaxRedirects: 5})
|
||||
resp, err := client.Get(zipURL)
|
||||
|
||||
Reference in New Issue
Block a user