summaryrefslogtreecommitdiffstats
path: root/model/utils.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-11-02 14:13:34 -0500
committerChristopher Speller <crspeller@gmail.com>2015-11-02 14:13:34 -0500
commit31eee1ef6ebb59a89885ef7e3ebd6801f9a396d4 (patch)
treec21e52d00aa42dbb8e7f0077f259014eeaa8cbaf /model/utils.go
parent17233b1dce530eef75e16944da7abdb060d2c27e (diff)
parent1f3423796eee06a126d3cab7c276e2d0f169b869 (diff)
downloadchat-31eee1ef6ebb59a89885ef7e3ebd6801f9a396d4.tar.gz
chat-31eee1ef6ebb59a89885ef7e3ebd6801f9a396d4.tar.bz2
chat-31eee1ef6ebb59a89885ef7e3ebd6801f9a396d4.zip
Merge pull request #1268 from mattermost/plt-514
PLT-514 Validate callback urls on the server and add help text to outgoing webhooks
Diffstat (limited to 'model/utils.go')
-rw-r--r--model/utils.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/model/utils.go b/model/utils.go
index bb0669df7..681ade870 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -11,6 +11,7 @@ import (
"fmt"
"io"
"net/mail"
+ "net/url"
"regexp"
"strings"
"time"
@@ -301,3 +302,15 @@ var UrlRegex = regexp.MustCompile(`^((?:[a-z]+:\/\/)?(?:(?:[a-z0-9\-]+\.)+(?:[a-
var PartialUrlRegex = regexp.MustCompile(`/([A-Za-z0-9]{26})/([A-Za-z0-9]{26})/((?:[A-Za-z0-9]{26})?.+(?:\.[A-Za-z0-9]{3,})?)`)
var SplitRunes = map[rune]bool{',': true, ' ': true, '.': true, '!': true, '?': true, ':': true, ';': true, '\n': true, '<': true, '>': true, '(': true, ')': true, '{': true, '}': true, '[': true, ']': true, '+': true, '/': true, '\\': true}
+
+func IsValidHttpUrl(rawUrl string) bool {
+ if strings.Index(rawUrl, "http://") != 0 && strings.Index(rawUrl, "https://") != 0 {
+ return false
+ }
+
+ if _, err := url.ParseRequestURI(rawUrl); err != nil {
+ return false
+ }
+
+ return true
+}