-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement XSRFIgnoreMethods #207
Conversation
isn't this already exist with https://github.com/go-pkgz/auth/blob/master/auth.go#L106 https://github.com/go-pkgz/auth/blob/master/auth.go#L106 ? |
No, in this situation I still definitely want XSRF protections on POST, PUT, DELETE, etc. but specifically not for GET requests. The DisableXSRF option disables it for all methods. |
This PR would allow for ignoring just certain HTTP methods, by setting |
token/jwt.go
Outdated
JWTHeaderKey string | ||
XSRFCookieName string | ||
XSRFHeaderKey string | ||
XSRFIgnoreMethods string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to use a comma-separated string in this context and then apply strings.contains
on the string subsequently. It would be more organized to utilize a slice of methods in this scenario and perform an exact match on the request method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I originally did that but saw the the default values for the related options were constants and wanted to stick to that, which couldn't be done with a slice. I will switch it back to an array of strings.
Unless I missed something, this code does not expect a []string with all the ignored methods but rather a single string (see my comment in the review above). |
one more thing - this change should be also documented in readme. Maybe a section about "Options to ignore XSRF protections" or smth like what showing how to do it and providing a basic explanation why this may be needed |
Will do |
The requested changes have been made. Thanks for the feedback. |
Pull Request Test Coverage Report for Build 10101670690Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a minor thing with implicit types for Contains func
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx
@oalexander6 could you please copy the very same changes to v2 directory please? |
|
XSRFIgnoreMethods
Background
I discovered while using this library that the current XSRF protections do not allow for a GET request sent by the browser on protected routes, due to requiring the presence of the XSRF token in a header. This is a problem for applications that are not SPAs and send GET requests to the server to retrieve a new HTML page. In these situations, the common pattern is to skip XSRF checks on GET requests.
Solution
To resolve this, I implemented a configuration option called
XSRFIgnoreMethods
, allowing the user to specify a comma-separated list of HTTP methods for which XSRF checks should be skipped when extracting and validating the JWT. I am open to any feedback, modifications, or discussions about this.