mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-09-10 20:22:14 +02:00
use IsLoopback (#19477)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
5e4134b117
commit
2ec2baf248
1 changed files with 1 additions and 23 deletions
|
@ -13,32 +13,10 @@ import (
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
var loopbackIPBlocks []*net.IPNet
|
|
||||||
|
|
||||||
var externalTrackerRegex = regexp.MustCompile(`({?)(?:user|repo|index)+?(}?)`)
|
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 {
|
func isLoopbackIP(ip string) bool {
|
||||||
pip := net.ParseIP(ip)
|
return net.ParseIP(ip).IsLoopback()
|
||||||
if pip == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, block := range loopbackIPBlocks {
|
|
||||||
if block.Contains(pip) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValidURL checks if URL is valid
|
// IsValidURL checks if URL is valid
|
||||||
|
|
Loading…
Reference in a new issue