Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions middleware/csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package middleware

import (
"crypto/subtle"
"errors"
"net/http"
"slices"
"strings"
Expand Down Expand Up @@ -160,6 +161,9 @@ func (config CSRFConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
if cErr != nil {
return nil, cErr
}
if len(extractors) == 0 {
return nil, errors.New("echo csrf middleware could not create extractors from TokenLookup string")
}

return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c *echo.Context) error {
Expand Down
8 changes: 8 additions & 0 deletions middleware/csrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ func TestCSRF_tokenExtractors(t *testing.T) {
givenQueryTokens: map[string][]string{},
expectToMiddlewareError: "extractor source for lookup could not be split into needed parts: q",
},
{
name: "nok, TokenLookup with only unknown source yields no extractors",
whenTokenLookup: "nope:nope",
givenCSRFCookie: "token",
givenMethod: http.MethodPut,
givenQueryTokens: map[string][]string{},
expectToMiddlewareError: "echo csrf middleware could not create extractors from TokenLookup string",
},
}

for _, tc := range testCases {
Expand Down
Loading