I am trying to implement CSRF in a Struts 6.2.0 project.
struts.xml
<package name="struts-security" abstract="true" extends="struts-default">
<interceptors>
<interceptor-stack name="defaultSecurityStack" />
<interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor" />
<interceptor name="tokenSessionStore" class= "org.apache.struts2.interceptor.TokenSessionStoreInterceptor" />
</interceptors>
<default-interceptor-ref name = "defaultSecurityStack" />
<global-results>
<result name="error">/error401.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception" />
</global-exception-mappings>
LoginAction.java
@Namespace("/common")
@Action("Login")
@InterceptorRefs({
@InterceptorRef("token"),
@InterceptorRef("tokenSessionStore")
})
@Results({
@Result(name = "input", location = "login.Login", type = "tiles"),
})
login.jsp
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:form method="post" validate="true" theme="simple" name="form" id="paraFrm" >
<s:token />
It is returning invalid.token
. Because I have added return page, it is redirecting to error page. Is there any requirement of additional code to implement token in action page or any other places.