mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-29 03:38:52 +03:00
Add Federation specific URL validation
This commit is contained in:
parent
41da150fb3
commit
584af0486d
1 changed files with 27 additions and 0 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
@ -116,6 +117,32 @@ func IsValidExternalTrackerURLFormat(uri string) bool {
|
||||||
return true
|
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 (
|
var (
|
||||||
validUsernamePatternWithDots = regexp.MustCompile(`^[\da-zA-Z][-.\w]*$`)
|
validUsernamePatternWithDots = regexp.MustCompile(`^[\da-zA-Z][-.\w]*$`)
|
||||||
validUsernamePatternWithoutDots = regexp.MustCompile(`^[\da-zA-Z][-\w]*$`)
|
validUsernamePatternWithoutDots = regexp.MustCompile(`^[\da-zA-Z][-\w]*$`)
|
||||||
|
|
Loading…
Reference in a new issue