summaryrefslogtreecommitdiffstats
path: root/utils/api.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2018-02-12 12:02:54 -0600
committerGitHub <noreply@github.com>2018-02-12 12:02:54 -0600
commit1ae680aefae2deb1e9d07d7c2a1c863ec807a79f (patch)
treea99a74d6b858d73624c06f85e393acbe97c90586 /utils/api.go
parent9707ac3aaf2cb4352c573aadf54b8535e237dd9e (diff)
parent07fd7aeeb8eb2b198b01b713a4ab57f6352faef2 (diff)
downloadchat-1ae680aefae2deb1e9d07d7c2a1c863ec807a79f.tar.gz
chat-1ae680aefae2deb1e9d07d7c2a1c863ec807a79f.tar.bz2
chat-1ae680aefae2deb1e9d07d7c2a1c863ec807a79f.zip
Merge branch 'master' into release-4.7
Diffstat (limited to 'utils/api.go')
-rw-r--r--utils/api.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/utils/api.go b/utils/api.go
index 005c3284b..51524074d 100644
--- a/utils/api.go
+++ b/utils/api.go
@@ -4,6 +4,9 @@
package utils
import (
+ "crypto"
+ "crypto/rand"
+ "encoding/base64"
"fmt"
"html/template"
"net/http"
@@ -32,13 +35,25 @@ func OriginChecker(allowedOrigins string) func(*http.Request) bool {
}
}
-func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) {
- status := http.StatusTemporaryRedirect
- if err.StatusCode != http.StatusInternalServerError {
- status = err.StatusCode
+func RenderWebAppError(w http.ResponseWriter, r *http.Request, err *model.AppError, s crypto.Signer) {
+ RenderWebError(w, r, err.StatusCode, url.Values{
+ "message": []string{err.Message},
+ }, s)
+}
+
+func RenderWebError(w http.ResponseWriter, r *http.Request, status int, params url.Values, s crypto.Signer) {
+ queryString := params.Encode()
+
+ h := crypto.SHA256
+ sum := h.New()
+ sum.Write([]byte("/error?" + queryString))
+ signature, err := s.Sign(rand.Reader, sum.Sum(nil), h)
+ if err != nil {
+ http.Error(w, "", http.StatusInternalServerError)
+ return
}
+ destination := strings.TrimRight(GetSiteURL(), "/") + "/error?" + queryString + "&s=" + base64.URLEncoding.EncodeToString(signature)
- destination := strings.TrimRight(GetSiteURL(), "/") + "/error?message=" + url.QueryEscape(err.Message)
if status >= 300 && status < 400 {
http.Redirect(w, r, destination, status)
return