Skip to content

Commit 9fe724d

Browse files
committed
Fixed #802, closes #773
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 4cbef06 commit 9fe724d

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

middleware/csrf.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ func CSRFWithConfig(config CSRFConfig) echo.MiddlewareFunc {
140140
// Validate token only for requests which are not defined as 'safe' by RFC7231
141141
clientToken, err := extractor(c)
142142
if err != nil {
143-
return err
143+
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
144144
}
145145
if !validateCSRFToken(token, clientToken) {
146-
return echo.NewHTTPError(http.StatusForbidden, "CSRF token is invalid")
146+
return echo.NewHTTPError(http.StatusForbidden, "Invalid csrf token")
147147
}
148148
}
149149

@@ -187,7 +187,7 @@ func csrfTokenFromForm(param string) csrfTokenExtractor {
187187
return func(c echo.Context) (string, error) {
188188
token := c.FormValue(param)
189189
if token == "" {
190-
return "", errors.New("Missing csrf token in form param")
190+
return "", errors.New("Missing csrf token in the form parameter")
191191
}
192192
return token, nil
193193
}
@@ -199,7 +199,7 @@ func csrfTokenFromQuery(param string) csrfTokenExtractor {
199199
return func(c echo.Context) (string, error) {
200200
token := c.QueryParam(param)
201201
if token == "" {
202-
return "", errors.New("Missing csrf token in query param")
202+
return "", errors.New("Missing csrf token in the query string")
203203
}
204204
return token, nil
205205
}

middleware/jwt.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc {
111111
config.keyFunc = func(t *jwt.Token) (interface{}, error) {
112112
// Check the signing method
113113
if t.Method.Alg() != config.SigningMethod {
114-
return nil, fmt.Errorf("unexpected jwt signing method=%v", t.Header["alg"])
114+
return nil, fmt.Errorf("Unexpected jwt signing method=%v", t.Header["alg"])
115115
}
116116
return config.SigningKey, nil
117117
}
@@ -162,7 +162,7 @@ func jwtFromHeader(header string, authScheme string) jwtExtractor {
162162
if len(auth) > l+1 && auth[:l] == authScheme {
163163
return auth[l+1:], nil
164164
}
165-
return "", errors.New("Missing or invalid jwt in request header")
165+
return "", errors.New("Missing or invalid jwt in the request header")
166166
}
167167
}
168168

@@ -171,7 +171,7 @@ func jwtFromQuery(param string) jwtExtractor {
171171
return func(c echo.Context) (string, error) {
172172
token := c.QueryParam(param)
173173
if token == "" {
174-
return "", errors.New("Missing jwt in query string")
174+
return "", errors.New("Missing jwt in the query string")
175175
}
176176
return token, nil
177177
}
@@ -182,7 +182,7 @@ func jwtFromCookie(name string) jwtExtractor {
182182
return func(c echo.Context) (string, error) {
183183
cookie, err := c.Cookie(name)
184184
if err != nil {
185-
return "", errors.New("Missing jwt in cookie")
185+
return "", errors.New("Missing jwt in the cookie")
186186
}
187187
return cookie.Value, nil
188188
}

middleware/key_auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func keyFromHeader(header string, authScheme string) keyExtractor {
115115
if len(auth) > l+1 && auth[:l] == authScheme {
116116
return auth[l+1:], nil
117117
}
118-
return "", errors.New("Invalid key in request header")
118+
return "", errors.New("Invalid key in the request header")
119119
}
120120
return auth, nil
121121
}
@@ -126,7 +126,7 @@ func keyFromQuery(param string) keyExtractor {
126126
return func(c echo.Context) (string, error) {
127127
key := c.QueryParam(param)
128128
if key == "" {
129-
return "", errors.New("Missing key in query string")
129+
return "", errors.New("Missing key in the query string")
130130
}
131131
return key, nil
132132
}

0 commit comments

Comments
 (0)