[转]安全沙箱手记 (跨域加载操作必备良药)

在未经授权的情况下,Flash默认状态是不允许进行跨域通信的,这样就使得Flash的安全可靠性得到了提高

//++++++++++++++++++++++++++++ 没有指定元策略
警告: 域 xxx.xxx.xxx.xxx 没有指定元策略。将应用默认元策略 ‘master-only’。此配置已停用。请访问http://www.adobe.com/go/strict_policy_files_cn 以解决此问题。

A:策略文件有错误 CrossDomain.xml
<?xml version=”1.0″?>
<!DOCTYPE cross-domain-policy SYSTEM “http://www.adobe.com/xml/dtds/cross-domain-policy.dtd”>
<cross-domain-policy> <site-control permitted-cross-domain-policies=”all” />
<allow-access-from domain=”*” />
<allow-http-request-headers-from domain=”*” headers=”*”/>
</cross-domain-policy>
PS:加载方式 Security.loadPolicyFile(“http://myDomain/crossdomain.xml”);
策略文件放在被加载者服务器根目录(在提供数据的站点放入一个crossdomain.xml文件)
个人理解:所有网络上的资源除非是服务器限制,我们都可以加载,只是无法对其进行数据的操作,如果需要操作这些数据,就需要在服务器上放置策略文件。(eg:如果需要对图片进行像素级操作,那就在服务器上放策略文件)
再次PS:如果策略文件不在根目录,需要用 Security.loadPolicyFile(filepath); 方法加载安全策略文件

//++++++++++++++++++++++++++++ 对加载者进行权限操作 (applicationDomain)
SecurityError: Error #2119: 安全沙箱冲突:调用者http://cs4165.vkontakte.ru/[[IMPORT]]/xn.smoothfish.cn/fish_xn/main.swf?lang=ru&pid=0&apiID=1716287&mode=0&version=2027 不能访问 http://xn.smoothfish.cn/fish_xn/items.swf 拥有的 LoaderInfo.applicationDomain。
at flash.display:loaderInfo/get applicationDomain()
at cafe.util::CClass$/getClass()
at cafe.map::CLayerLoading/showCookResLoading()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at cafe.main::main/getResLoading()
at cafe.main::main/loadCompleteHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at cafe.load::CLoad/load()
at cafe.load::CLoad/loadStartHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at cafe.load::CLoad/loaderCompleteHandler3()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at cafe.load::CLoadAbstract/finish()
at cafe.load::CLoadConfig/loadConfigHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

在被加载者SWF内写入
Security.allowDomain(“*”);// 注意,”www.baidu.com” 和 “baidu.com”不是相同域,多个域 用逗号隔开
PS:security.allowDomain (“*”) 与跨域加载资源其实是两回事
有security.allowDomain (“*”)标注的Flash文件 只表示成功加载此的容器可以对它进行所有权限的操作

//++++++++++++++++++++++++++++
//为true的时候,先下载策略文件( 指定 Flash Player 在加载对象前是否应检查跨域策略文件是否存在)
var lcoader:LoaderContext = new LoaderContext(true);

//var loadercontexloaderContext = new LoaderContext(false, new ApplicationDomain(), SecurityDomain.currentDomain);
var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
context.securityDomain = SecurityDomain.currentDomain;
loader.load(url,context);

//++++++++++++++++++++++++++++
解决flash安全沙箱的几种方法总结
1。配置跨域文件来实现
System.security.allowDomain(“www.baidu.com”, “baidu.com”, “mp3.baidu.com”);
2。利用JS脚本绕过安全沙箱(有待验证)
<param name=”allowScriptAccess” value=”always” />
3。使用Asp.Net绕过As3的跨域安全沙箱完全的文件转发,以极低的效率来解决了问题,基本无实用价值
4。本地安全沙箱:在C:\windows\system32\Macromed\Flash\FlashPlayerTrust 下面,添加一个txt文件,例如songhuan .txt,然后在里面添加你的本机的目录,例如f:\crayon\或者c:\都可以。

转载于 蜡笔工作室 原文:http://flash.9ria.com/thread-51824-1-1.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值