Skip to content
Closed
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
2 changes: 1 addition & 1 deletion csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (cs *csrf) ServeHTTP(w http.ResponseWriter, r *http.Request) {

// HTTP methods not defined as idempotent ("safe") under RFC7231 require
// inspection.
if !contains(safeMethods, r.Method) {
if !slices.Contains(safeMethods, r.Method) {
var isPlaintext bool
val := r.Context().Value(PlaintextHTTPContextKey)
if val != nil {
Expand Down
2 changes: 1 addition & 1 deletion csrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestBadCookie(t *testing.T) {
r = createRequest("POST", "/", false)

// Replace the cookie prefix
badHeader := strings.Replace(cookieName+"=", rr.Header().Get("Set-Cookie"), "_badCookie", -1)
badHeader := strings.ReplaceAll(cookieName+"=", rr.Header().Get("Set-Cookie"), "_badCookie")
r.Header.Set("Cookie", badHeader)
r.Header.Set("X-CSRF-Token", token)
r.Header.Set("Referer", "http://www.gorillatoolkit.org/")
Expand Down
12 changes: 0 additions & 12 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,6 @@ func xorToken(a, b []byte) []byte {
return res
}

// contains is a helper function to check if a string exists in a slice - e.g.
// whether a HTTP method exists in a list of safe methods.
func contains(vals []string, s string) bool {
for _, v := range vals {
if v == s {
return true
}
}

return false
}

// envError stores a CSRF error in the request context.
func envError(r *http.Request, err error) *http.Request {
return contextSave(r, errorKey, err)
Expand Down
5 changes: 4 additions & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ func TestMultipartFormToken(t *testing.T) {
t.Fatal(err)
}

mp.Close()
err = mp.Close()
if err != nil {
t.Fatal(err)
}

r = httptest.NewRequest("POST", "/", &b)
r.Host = "www.gorillatoolkit.org"
Expand Down
Loading