aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-04-25 07:55:12 +0200
committerGitHub <noreply@github.com>2022-04-25 13:55:12 +0800
commit2ec2baf24894727febb964039b69982e7ed3c633 (patch)
tree0b67292fb4b18e600001101a2175adccbfdeffbf /modules
parent5e4134b11790fb97bdc1f062fd19b8c49ebb8389 (diff)
downloadgitea-2ec2baf24894727febb964039b69982e7ed3c633.tar.gz
gitea-2ec2baf24894727febb964039b69982e7ed3c633.zip
use IsLoopback (#19477)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/validation/helpers.go24
1 files changed, 1 insertions, 23 deletions
diff --git a/modules/validation/helpers.go b/modules/validation/helpers.go
index 617ec3578c..484b12b2a2 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