strits2 csrf portect

http://web.securityinnovation.com/appsec-weekly/blog/bid/84318/Cross-Site-Request-Forgery-CSRF-Prevention-Using-Struts-2


Secure Development Tips

a blog with tips relating to secure application development, from Security Innovation's eknowledge database, TeamMentor

Current Articles | RSS Feed RSS Feed

Cross-Site Request Forgery (CSRF) Prevention Using Struts 2

  
Share  

Applies to

  • Java
  • Struts 2

Summary

Perform CSRF prevention using Struts 2 within an application.

Objectives

CSRF prevention is a key security control for an application that protects the application and its users from CSRF attacks. This article will describe how to use the built-in mechanisms provided by Struts 2 to perform CSRF prevention.

Code Example

There is a standard model for CSRF prevention using Struts 2 that involves 3 basic steps

1. Update your interceptor stack to include the tokenSessionInterceptor, either including or excluding all methods (all are included here).

<interceptor-stack name="myStack">
    <interceptor-ref name="defaultStack" />
    <interceptor-ref name="tokenSession">
 <param name="includeMethods">*</param>
    </interceptor-ref>
</interceptor-stack>

<default-interceptor-ref name="myStack" />

2. Update your action configuration to include or exclude any methods that need or do not need CSRF protection.

<action ...>
    ...
    <interceptor-ref name="tokenSession">
 <param name="excludeMethods">searchBooks,getBook</param>
    </interceptor-ref>
</action>

3. Use s:token in your JSP form that requests the action.

<s:form action="...">
    ...
    <s:token />
    ...
</s:form>

Using these 3 simple steps you can effectively have a session specific per user token used to validate that a request was submitted by a user intentionally.

Note: There have been effective attacks against various CSRF prevention techniques including this token-based approach when an application has XSS vulnerabilities. Removing XSS is therefore viewed as a prerequisite activity for a complete CSRF prevention mechanism.

In conclusion, CSRF prevention can function as a strong security control if used properly and applied thoroughly throughout the application. The Struts 2 framework provides a simple series of steps for accomplishing this task.

More Information

Comments

Currently, there are no comments. Be the first to post one!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值