Skip to content

Commit 2ec2baf

Browse files
6543lunny
andauthored
use IsLoopback (#19477)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 5e4134b commit 2ec2baf

File tree

1 file changed

+1
-23
lines changed

1 file changed

+1
-23
lines changed

modules/validation/helpers.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,10 @@ import (
1313
"code.gitea.io/gitea/modules/setting"
1414
)
1515

16-
var loopbackIPBlocks []*net.IPNet
17-
1816
var externalTrackerRegex = regexp.MustCompile(`({?)(?:user|repo|index)+?(}?)`)
1917

20-
func init() {
21-
for _, cidr := range []string{
22-
"127.0.0.0/8", // IPv4 loopback
23-
"::1/128", // IPv6 loopback
24-
} {
25-
if _, block, err := net.ParseCIDR(cidr); err == nil {
26-
loopbackIPBlocks = append(loopbackIPBlocks, block)
27-
}
28-
}
29-
}
30-
3118
func isLoopbackIP(ip string) bool {
32-
pip := net.ParseIP(ip)
33-
if pip == nil {
34-
return false
35-
}
36-
for _, block := range loopbackIPBlocks {
37-
if block.Contains(pip) {
38-
return true
39-
}
40-
}
41-
return false
19+
return net.ParseIP(ip).IsLoopback()
4220
}
4321

4422
// IsValidURL checks if URL is valid

0 commit comments

Comments
 (0)