同源策略是浏览器中最基本的隔离潜在恶意文件的安全策略,他限制了来自不一样源(origin)的文档或脚本之间的相互做用。html
在跨域之URL中介绍过一个URL的标准格式以下:跨域
协议类型://服务器地址(必要时需加上端口号)/路径/文件名浏览器
对比URL的标准格式,这里的同源就是指:安全
下面是维基百科上的例子。服务器
假如一个URL为http://www.example.com/dir/page.html,下表中列举的URL与该URL的关系(Success表示同源,Failure表示不一样源):dom
Compared URL | Outcome | Reason |
---|---|---|
http://www.example.com/dir/page2.html | Success | Same protocol, host and port |
http://www.example.com/dir2/other.html | Success | Same protocol, host and port |
http://username:password@www.example.com/dir2/other.html | Success | Same protocol, host and port |
http://www.example.com:81/dir/other.html | Failure | Same protocol and host but different port |
https://www.example.com/dir/other.html | Failure | Different protocol |
http://en.example.com/dir/other.html | Failure | Different host |
http://example.com/dir/other.html | Failure | Different host (exact match required) |
http://v2.www.example.com/dir/other.html | Failure | Different host (exact match required) |
http://www.example.com:80/dir/other.html | Depends | Port explicit. Depends on implementation in browser. |
在处理同源策略的问题上,IE存在两个主要的不一样之处。
ide
授信范围(Trust Zones):两个相互之间高度互信的域名,如公司域名(corporate domains),不遵照同源策略的限制。
端口:IE未将端口号加入到同源策略的组成部分之中,所以
http://company.com:81/index.html 和http://company.com/index.html 属于同源而且不受任何限制。同源策略是为了保证用户信息的安全而设置的,若是两个页面不一样源,他们在如下交互上受到限制(摘自浏览器同源政策及其规避方法):学习
有些时候为了实现某些需求,能够使用一些特殊手段突破同源策略的限制,在以后的学习中再总结。ui