Is there an existing issue for this?
The issue
It seems like opt.TrustedOrigins is being required to set even though the request does come from the same origin
Current Behavior
The function sameOrigin is comparing a.Scheme == b.Scheme and a.Host == b.Host
|
func sameOrigin(a, b *url.URL) bool { |
|
return (a.Scheme == b.Scheme && a.Host == b.Host) |
The handler for the CSRF check is using this function to compare r.URL vs r.Header.Get("Origin") here
|
if !sameOrigin(&requestURL, parsedOrigin) && !slices.Contains(cs.opts.TrustedOrigins, parsedOrigin.Host) { |
|
r = envError(r, ErrBadOrigin) |
The issue is that requestURL.Schema is set to https even when request origin is http because isPlainText in local environment is false
|
requestURL.Scheme = "https" |
|
if isPlaintext { |
The current fix is to add localhost:8080 as opt.TrustedOrigins but in this case the origin is the same, it shouldn't be required.
Expected Behavior
Requests from the same origin (host + scheme) should not require manually adding entries to opt.TrustedOrigins.
Steps To Reproduce
No response
Anything else?
Solutions seems to be to update the logic to correctly detect plaintext (http) requests in local/dev environments or improve how isPlaintext is set/detected by default.