Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSRF Token coming empty in login form using Spring MVC and Spring Security

${_csrf.parameterName} and ${_csrf.token} coming empty in login form. I am using Spring 4.1.3 and Spring Security 3.2.5
All the configurations are made correctly but still i am getting

<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>

as

<input type="hidden" name="" value=""/>
like image 934
Giridhar Avatar asked Dec 30 '14 17:12

Giridhar


People also ask

How is CSRF token generated in Spring?

To protect MVC applications, Spring adds a CSRF token to each generated view. This token must be submitted to the server on every HTTP request that modifies state (PATCH, POST, PUT and DELETE — not GET). This protects our application against CSRF attacks since an attacker can't get this token from their own page.

Is CSRF enabled by default in Spring Security?

As of Spring Security 4.0, CSRF protection is enabled by default with XML configuration.

How do I know if my CSRF token is working?

A couple of ways you can test it: Open the developer tools in your browser find the input element for the CSRF token and edit the token value. Trigger a POST submission. This should cause an error, HTTP status 403 typically.


1 Answers

I found the answer, i placed the security filter tags in web.xml at top of any other filters and it worked.

like image 65
Giridhar Avatar answered Sep 18 '22 13:09

Giridhar