-
Notifications
You must be signed in to change notification settings - Fork 6k
CSRF Issue Latest spring Version:An expected CSRF token cannot be found #14151
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
Comments
Hi, @Debesh1234. CSRF support has gone through some changes between versions 5 and 6. The best place to start would be on the official documentation and maybe the migration docs. I assume that you have a JavaScript client based on your configuration, so you might be interested in #14149. I'll close this since it doesn't seem to be a bug, but, after you go through the documentation and apply the required changes, if the problem persists you can provide a minimal, reproducible sample and we can reopen this issue. |
@marcusdacoregio I have a spring gateway service, that is getting invoked from Angular application, So which way need to pass the token to get success, pls provide some path to correctly implement |
@Dbsahoo In the previous comment, I linked the documentation that guides you on how to provide such implementation. Please, read it thoroughly and reach out to us if the options there do not fit your use case. |
I am also facing an issue with CSRF token, Even I have disabled the csrf in security class. When I am calling API through postman and I'm getting the same error: An expected CSRF token cannot be found. Spring boot parent : 3.2.1 |
@sachinnirne Did you find the solution? |
@sachinnirne Did you find the solution? |
that worked for me |
CSRF Issue Latest spring Version:An expected CSRF token cannot be found
Summary
WIth Spring security version 5 with below configuration and Passing X-XSRF-TOKEN in POST request am able to get proceed .
@OverRide
protected void configure(HttpSecurity http) throws Exception {
http
.exceptionHandling(handling -> handling.authenticationEntryPoint(userAuthenticationEntryPoint))
.addFilterBefore(new UsernamePasswordAuthFilter(userAuthenticationProvider), BasicAuthenticationFilter.class)
.addFilterBefore(new JwtAuthFilter(userAuthenticationProvider), UsernamePasswordAuthFilter.class)
.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
.sessionManagement(management -> management.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeRequests(requests -> requests
.antMatchers(HttpMethod.GET, "/v1/csrf").permitAll()
.antMatchers(HttpMethod.POST, "/v1/test").permitAll()
.antMatchers(HttpMethod.POST, "/v1/signIn", "/v1/signUp", "/test").permitAll()
.anyRequest().authenticated());
}
Passing X-XSRF-TOKEN in POST request am able to get proceed whereas ,
With Webflux
@bean
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
Keep on getting "An expected CSRF token cannot be found"
Actual Behavior
Expected Behavior
Configuration
Version
Sample
The text was updated successfully, but these errors were encountered: