哪个XSS OWASP规则 [英] Which XSS OWASP Rule

查看:81
本文介绍了哪个XSS OWASP规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用OWASP核对表,这是正确的方法来保护这种情况吗?这是一个javascript字符串中的url,其中url参数需要具有xss保护。

Using the OWASP checklist, which is the correct way protect this situation? This is url inside of a javascript string where a url parameter needs to have xss protection.

问题:

<script>
    var u = 'xyz.html?x=<% url.baddata %>'  
    dosomeAjax(u);
</script>

可能的解决方案1:

var u = 'xyz.html?x=<% encodeForURL(url.baddata) %>'

可能的解决方案2:

var u = 'xyz.html?x=<% encodeForJavaScript(url.baddata) %>'  

可能的解决方案3:

var u = 'xyz.html?x=<% encodeForJavaScript(encodeForURL(url.baddata)) %>'  


推荐答案

应使用解决方案3:

//solution 3:
var u = 'xyz.html?x=<% encodeForJavaScript(encodeForURL(url.baddata)) %>';

如果我们将表达式重写为:

It is easier to see that this is correct if we rewrite the expression as:

var u = '<% encodeForJavaScript("xyz.html?x=" + encodeForURL(url.baddata)) %>';

首先,我们通过附加 baddata 到一个字符串常量,使用适当的转义函数。然后我们将这个安全的URL放在JavaScript字符串中,因此我们必须调用JavaScript转义函数。

First, we are creating a safe URL by appending baddata to a string constant, using the appropriate escape function. Then we are taking that safe URL and placing it in a JavaScript string, so we have to call the JavaScript escape function.

这篇关于哪个XSS OWASP规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆