-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add csrf token support #2434
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
Add csrf token support #2434
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2434 +/- ##
=========================================
Coverage 95.41% 95.41%
Complexity 2956 2956
=========================================
Files 336 336
Lines 7856 7856
Branches 620 620
=========================================
Hits 7496 7496
Misses 227 227
Partials 133 133 |
Hi @dilipkrish , any suggestion? |
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.
Thank you for the PR! 👍 and 🤘 for the tests! I don't know enough about the javascript ecosystem, so I had one question about the babel configuration change. @kasecato do you have any feedback?
@@ -4,6 +4,7 @@ | |||
"targets": { | |||
"browsers": ["last 2 versions"] | |||
} | |||
}] | |||
}], | |||
"stage-3" |
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.
Why do we need this?
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.
@dilipkrish I think they wants to use object-rest-spread.
...request.headers,
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.
As @kasecato said.
I will push a new commit to refactor it. If you prefer this way, I will revert the commit.
@olOwOlo didnt mean for u to change it, was just asking if that has an impact on what browsers are supported. Thank you for doing that tho'. Also one last question. Does the swagger-ui.html need to change? Seems like it should have the meta tags as u suggested? <!-- The meta name must be _csrf and _csrf_header. / is the page used to query meta data. -->
<html>
<head>
<meta name="_csrf" content="${_csrf.token}"/>
<!-- default header name is X-CSRF-TOKEN -->
<meta name="_csrf_header" content="${_csrf.headerName}"/>
</head> |
@dilipkrish No, |
@olOwOlo thank you!! |
where is CsrfToken class ?? |
Hello guys, sorry but I have to ask :) Is there somewhere a "complete" example how to get rid of "404 for csrf" in spring boot 2.X? |
This is a terrible pr. |
If CSRF token in a cookie, how can swagger UI pick it up? The token is changing per ANY POST/PUT/DELETE/PATCH operation. So, is there any logic to pick up the value from the cookie? |
What's this PR do/fix?
Try to find csrf token and add it to the header of all requests by patching the
requestInterceptor
. The behavior is based on the configuration described in the spring security reference. The following order is the order of finding the csrf token.P.S. This implementation will always use the csrf token obtained the first time.
P.S. If necessary, Maybe someone in the future can add the ability to configure these behaviors, I don’t know how to add options. 😢
CSRF token within your meta tags [1]
The meta name must be
_csrf
and_csrf_header
./
is the page used to query meta data.Define an endpoint used to fetch csrf token [2]
The
@RequestMapping
value must be/csrf
.CSRF token within your cookie [3]
The default cookie name is
XSRF-TOKEN
, and the default header name isX-XSRF-TOKEN
.Are there unit tests? If not how should this be manually tested?
Any background context you want to provide?
requestInterceptor
Function=(a => a)
. MUST be a function. Function to intercept remote definition, Try-It-Out, and OAuth2 requests. Accepts one argument requestInterceptor(request) and must return the modified request, or a Promise that resolves to the modified request.What are the relevant issues?
#1450