From 11c769b3c783b6365a7fc0d79c61b0c2d01aa9e1 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 24 Apr 2022 21:43:23 +0200 Subject: [PATCH] use IsLoopback --- modules/validation/helpers.go | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/modules/validation/helpers.go b/modules/validation/helpers.go index 617ec3578c8f9..484b12b2a23c4 100644 --- a/modules/validation/helpers.go +++ b/modules/validation/helpers.go @@ -13,32 +13,10 @@ import ( "code.gitea.io/gitea/modules/setting" ) -var loopbackIPBlocks []*net.IPNet - var externalTrackerRegex = regexp.MustCompile(`({?)(?:user|repo|index)+?(}?)`) -func init() { - for _, cidr := range []string{ - "127.0.0.0/8", // IPv4 loopback - "::1/128", // IPv6 loopback - } { - if _, block, err := net.ParseCIDR(cidr); err == nil { - loopbackIPBlocks = append(loopbackIPBlocks, block) - } - } -} - func isLoopbackIP(ip string) bool { - pip := net.ParseIP(ip) - if pip == nil { - return false - } - for _, block := range loopbackIPBlocks { - if block.Contains(pip) { - return true - } - } - return false + return net.ParseIP(ip).IsLoopback() } // IsValidURL checks if URL is valid