summaryrefslogtreecommitdiffstats
path: root/modules/auth
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-04-19 06:02:20 +0300
committerBo-Yi Wu <appleboy.tw@gmail.com>2017-04-19 11:02:20 +0800
commitf42ec6120e8a2830407027020b65391ebf8e7f59 (patch)
treeaee67e8f44d105ef957b27fe3777e38aa034baa6 /modules/auth
parent941281ae12f0df84ffc73c279dc9e55f058e4703 (diff)
downloadgitea-f42ec6120e8a2830407027020b65391ebf8e7f59.tar.gz
gitea-f42ec6120e8a2830407027020b65391ebf8e7f59.zip
Better URL validation (#1507)
* Add correct git branch name validation * Change git refname validation error constant name * Implement URL validation based on GoLang url.Parse method * Backward compatibility with older Go compiler * Add git reference name validation unit tests * Remove unused variable in unit test * Implement URL validation based on GoLang url.Parse method * Backward compatibility with older Go compiler * Add url validation unit tests
Diffstat (limited to 'modules/auth')
-rw-r--r--modules/auth/admin.go2
-rw-r--r--modules/auth/auth.go3
-rw-r--r--modules/auth/org.go2
-rw-r--r--modules/auth/repo_form.go12
-rw-r--r--modules/auth/user_form.go2
5 files changed, 12 insertions, 9 deletions
diff --git a/modules/auth/admin.go b/modules/auth/admin.go
index 68bc4f3941..0bb7d355c4 100644
--- a/modules/auth/admin.go
+++ b/modules/auth/admin.go
@@ -32,7 +32,7 @@ type AdminEditUserForm struct {
FullName string `binding:"MaxSize(100)"`
Email string `binding:"Required;Email;MaxSize(254)"`
Password string `binding:"MaxSize(255)"`
- Website string `binding:"Url;MaxSize(255)"`
+ Website string `binding:"ValidUrl;MaxSize(255)"`
Location string `binding:"MaxSize(50)"`
MaxRepoCreation int
Active bool
diff --git a/modules/auth/auth.go b/modules/auth/auth.go
index 33ba777966..89b3e38509 100644
--- a/modules/auth/auth.go
+++ b/modules/auth/auth.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/validation"
)
// IsAPIPath if URL is an api path
@@ -253,6 +254,8 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_error")
case binding.ERR_ALPHA_DASH_DOT:
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error")
+ case validation.ErrGitRefName:
+ data["ErrorMsg"] = trName + l.Tr("form.git_ref_name_error")
case binding.ERR_SIZE:
data["ErrorMsg"] = trName + l.Tr("form.size_error", GetSize(field))
case binding.ERR_MIN_SIZE:
diff --git a/modules/auth/org.go b/modules/auth/org.go
index 8ad2ca6c6a..b9b3f981e1 100644
--- a/modules/auth/org.go
+++ b/modules/auth/org.go
@@ -31,7 +31,7 @@ type UpdateOrgSettingForm struct {
Name string `binding:"Required;AlphaDashDot;MaxSize(35)" locale:"org.org_name_holder"`
FullName string `binding:"MaxSize(100)"`
Description string `binding:"MaxSize(255)"`
- Website string `binding:"Url;MaxSize(255)"`
+ Website string `binding:"ValidUrl;MaxSize(255)"`
Location string `binding:"MaxSize(50)"`
MaxRepoCreation int
}
diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go
index dd3fbff7bf..c56e76c871 100644
--- a/modules/auth/repo_form.go
+++ b/modules/auth/repo_form.go
@@ -87,7 +87,7 @@ func (f MigrateRepoForm) ParseRemoteAddr(user *models.User) (string, error) {
type RepoSettingForm struct {
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
Description string `binding:"MaxSize(255)"`
- Website string `binding:"Url;MaxSize(255)"`
+ Website string `binding:"ValidUrl;MaxSize(255)"`
Interval string
MirrorAddress string
Private bool
@@ -143,7 +143,7 @@ func (f WebhookForm) ChooseEvents() bool {
// NewWebhookForm form for creating web hook
type NewWebhookForm struct {
- PayloadURL string `binding:"Required;Url"`
+ PayloadURL string `binding:"Required;ValidUrl"`
ContentType int `binding:"Required"`
Secret string
WebhookForm
@@ -156,7 +156,7 @@ func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) bin
// NewSlackHookForm form for creating slack hook
type NewSlackHookForm struct {
- PayloadURL string `binding:"Required;Url"`
+ PayloadURL string `binding:"Required;ValidUrl"`
Channel string `binding:"Required"`
Username string
IconURL string
@@ -323,7 +323,7 @@ type EditRepoFileForm struct {
CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
+ NewBranchName string `binding:"GitRefName;MaxSize(100)"`
LastCommit string
}
@@ -356,7 +356,7 @@ type UploadRepoFileForm struct {
CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
+ NewBranchName string `binding:"GitRefName;MaxSize(100)"`
Files []string
}
@@ -387,7 +387,7 @@ type DeleteRepoFileForm struct {
CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
+ NewBranchName string `binding:"GitRefName;MaxSize(100)"`
}
// Validate validates the fields
diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go
index bac9622fcc..2f767d4c8c 100644
--- a/modules/auth/user_form.go
+++ b/modules/auth/user_form.go
@@ -103,7 +103,7 @@ type UpdateProfileForm struct {
FullName string `binding:"MaxSize(100)"`
Email string `binding:"Required;Email;MaxSize(254)"`
KeepEmailPrivate bool
- Website string `binding:"Url;MaxSize(255)"`
+ Website string `binding:"ValidUrl;MaxSize(255)"`
Location string `binding:"MaxSize(50)"`
}