Is there an existing issue for this?
Current Behavior
When running in localhost, every csrf check returns "Invalid Origin" error. go-chi router is used.
router.Use(CsrfMiddleware(mustGetCsrfKey()))
func CsrfMiddleware(key []byte) func(http.Handler) http.Handler {
var opts []csrf.Option
env := os.Getenv("APP_ENV")
if env == "local" || env == "dev" {
opts = append(opts, csrf.Secure(false))
}
csrfFn := csrf.Protect(key, opts...)
return csrfFn
}
I made sure that the APP_ENV variable is correctly set and csrf.Protect is called with csrf.Secure(false) option.
After debugging I noticed the error happens do to the check if !sameOrigin(&requestURL, parsedOrigin) ... in gorilla/csrf/csrf.go. The request url gets rewritten in the same csrf.go file in this block:
requestURL := *r.URL // shallow clone
requestURL.Scheme = "https"
if isPlaintext {
requestURL.Scheme = "http"
}
if requestURL.Host == "" {
requestURL.Host = r.Host
}
Expected Behavior
csrf.Secure(false) option should prevent rewriting url scheme from "http" to "https"
Steps To Reproduce
No response
Anything else?
No response
Is there an existing issue for this?
Current Behavior
When running in localhost, every csrf check returns "Invalid Origin" error.
go-chirouter is used.I made sure that the APP_ENV variable is correctly set and
csrf.Protectis called withcsrf.Secure(false)option.After debugging I noticed the error happens do to the check
if !sameOrigin(&requestURL, parsedOrigin) ...ingorilla/csrf/csrf.go. The request url gets rewritten in the samecsrf.gofile in this block:Expected Behavior
csrf.Secure(false) option should prevent rewriting url scheme from "http" to "https"
Steps To Reproduce
No response
Anything else?
No response