【问题标题】:Same Origin Policy and external scripts同源策略和外部脚本
【发布时间】:2011-08-08 02:52:39
【问题描述】:

我的任务是集成来自 AdBrite 的广告代码。

这是给我的 sn-p,经过清理以删除我们的标识符:

<script type="text/javascript">
var AdBrite_Title_Color = '3D81EE';
var AdBrite_Text_Color = '000000';
var AdBrite_Background_Color = 'FFFFFF';
var AdBrite_Border_Color = 'CCCCCC';
var AdBrite_URL_Color = '008000';
try{var AdBrite_Iframe=window.top!=window.self?2:1;var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);}catch(e){var AdBrite_Iframe='';var AdBrite_Referrer='';}
</script>
<script type="text/javascript">document.write(String.fromCharCode(60,83,67,82,73,80,84));document.write(' src="http://ads.adbrite.com/mb/text_group.php?sid=sanitized&zs=sanitized&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));</script>
<div><a target="_top" href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=sanitized&afsid=1" style="font-weight:bold;font-family:Arial;font-size:13px;">Your Ad Here</a></div>

它通过写入 DOM 从 Adbrite 服务器加载远程脚本。 String.fromCharCode 巧妙地为 &lt;script&gt; 写出 ASCII 字符,以便引用远程 Javascript 文件。

我的问题是:为什么会这样?浏览器不认为这违反了同源政策吗?

顺便说一句,促使我对此进行调查的原因是我让trouble 让 URL 参数正确转义,然后在 GWT 的 UIBinder 中取消转义。

谢谢

【问题讨论】:

    标签: javascript xss same-origin-policy


    【解决方案1】:

    同源策略适用于 AJAX 请求。加载远程脚本不受此规则的约束,因此可能存在 JSONP 之类的解决方案。

    【讨论】:

    • 好的,但是为什么 AdBrite 用 String.fromCharCode 混淆它?
    • 我相信这可能是一些旧浏览器误解引号内的&lt;script&gt; 标签的解决方法。不过不确定。
    • 嗯,我认为 String.fromCharCode() 的原因是他们正在使用它来动态设置 url 参数,并且他们正在转义
    猜你喜欢
    • 2012-09-25
    • 2011-10-24
    • 2011-04-08
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 2010-09-25
    • 2014-06-05
    相关资源
    最近更新 更多