mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 16:47:30 +00:00
Add Federation specific URL validation
This commit is contained in:
parent
41da150fb3
commit
584af0486d
|
@ -7,6 +7,7 @@ import (
|
|||
"net"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -116,6 +117,32 @@ func IsValidExternalTrackerURLFormat(uri string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func IsValidForgejoActivityPubURL(url string) bool {
|
||||
if !IsValidURL(url) {
|
||||
return false
|
||||
}
|
||||
if !strings.Contains(url, "api/v1/activitypub") {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValidFederatedRepoURL(url string) bool {
|
||||
if !IsValidForgejoActivityPubURL(url) {
|
||||
return false
|
||||
}
|
||||
if !strings.Contains(url, "repository-id") {
|
||||
return false
|
||||
}
|
||||
splitURL := strings.Split(url, "/")
|
||||
repoIDIndex := len(splitURL) - 1
|
||||
// Is there a valid integer denoting a repo id?
|
||||
if _, err := strconv.Atoi(splitURL[repoIDIndex]); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var (
|
||||
validUsernamePatternWithDots = regexp.MustCompile(`^[\da-zA-Z][-.\w]*$`)
|
||||
validUsernamePatternWithoutDots = regexp.MustCompile(`^[\da-zA-Z][-\w]*$`)
|
||||
|
|
Loading…
Reference in a new issue