我试图通过使用struts令牌拦截器保护我的Web应用程序免受CSRF攻击.
我现在面临的问题是我们的JSP页面对服务器进行了多次调用(当JSP被转换为JS时,一个struts令牌被添加到JS.But,在这个JS中有多个Ajax请求.我希望我自己清楚.),因为令牌拦截器只对服务器的第一次请求得到验证.其他请求将失效,因为struts令牌在每次验证后都会重置.
有没有办法阻止Struts每次验证时重置令牌?是否有任何其他解决方案来处理struts拦截器.
我也在看tomcatcsrfprotection模块,我想我最终也会遇到同样的问题.
managepage.jsp:
<s:token />
<script type="text/javascript">
var strutsToken = "<s:property value="#session['struts.tokens.token']" />";
var requestParams = {mainAction: 'loadGroups','struts.token.name': 'token' , token:strutsToken};
Ext.Ajax.request({
url: 'manageUserAccount.action',
params: Ext.urlEncode(requestParams),
disableCaching: true,
success: this.actionCallback
});
//loading widgets
var requestParams = {mainAction: 'loadusers','struts.token.name': 'token' , token:strutsToken};
Ext.Ajax.request({
url: 'manageUserAccount.action',
params: Ext.urlEncode(requestParams),
disableCaching: true,
success: this.actionCallback
});
</script>
Run Code Online (Sandbox Code Playgroud)
Struts.xml:
<action name="manageUserAccountEdit" class="ManageUserAccountEditAction">
<interceptor-ref name="csrf-protection" />
<result name="success">/pages/manageUserAccount.jsp</result>
</action>
Run Code Online (Sandbox Code Playgroud)
我刚刚添加了最少的代码,以便更容易理解它.
如何在JS中清空一个字符串,保持相同的对象引用?
var str= "hello";
str=""; // this will clear the string but will create a new reference
Run Code Online (Sandbox Code Playgroud)