I added an interceptor to my struts.xml and to all of the forms to prevent Cross-site Request Forgery attacks. I am wondering if I should do anything else? Such as retrieving the token and matching with the one submitting along with forms, in case it won't be done automatically.
<interceptors>
<interceptor-stack name="defaultSecurityStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="tokenSession">
<param name="excludeMethods">*</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="defaultSecurityStack"/>
All forms has
<s:form ...>
<s:token/>
...
</s:form>
Firstly, I think you should put the token
interceptor as the first interceptor on your stack. That way, when the token does not match your code is not executed.
Secondly, <param name="excludeMethods">*</param>
means you are not using this interceptor ever.
Lastly, the token
interceptor automatically checks the token in the form parameters with the token in the session. If it does not match it returns a result invalid.token
by which you can alter the flow like follows
<result name="invalid.token" type="redirectAction">
<param name="actionName">wrongToken.jsp</param>
</result>
Following urls are interesting reading:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With