安全策略手记 (安全沙箱全攻略)



转载请注明出处:
http://hi.baidu.com/蜡笔工作室/blog/item/ba395a52dbc2fa020df3e3d8.html

昨天在做项目的时候遇到可恨的安全沙箱问题,折磨了好久,感觉对安全沙箱终于登堂入室了,呵呵。。感谢咸鱼、树人、小火柴的帮助,HOHO,再次感谢下
下面是我总结的一些常见的安全沙箱出现的错误和解决方法已经个人对安全沙箱的认识总结。能力有限,有什么认识错误的地方欢迎大家指正拍砖

在未经授权的情况下,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 lc:LoaderContext = new LoaderContext(true);

//var loadercontex:LoaderContext = 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:\都可以。

posted @ 2010-04-30 10:43  Akweb  阅读(172)  评论(0编辑  收藏  举报