浏览器同源策略
1. 同源策略:是一个重要的安全策略,它用于限制一个资源如何能与另一个资源进行交互。它能帮助阻隔恶意攻击,减少可能被攻击的媒介。
如果两个 URL 的协议、域名以及端口号均相等,那么称这两个 URL 为同源的.
2. 举例说明同源 URL:下表给出了与 URL http://store.company.com/dir/page.html 的源进行对比的示例【转载自MDN------https://developer.mozilla.org/zh-CN/docs/Web/Security/Same-origin_policy】
| URL | 结果 | 原因 |
|---|---|---|
http://store.company.com/dir2/other.html |
同源 | 只有路径不同 |
http://store.company.com/dir/inner/another.html |
同源 | 只有路径不同 |
https://store.company.com/secure.html |
失败 | 协议不同 |
http://store.company.com:81/dir/etc.html |
失败 | 端口不同 ( http:// 默认端口是80) |
http://news.company.com/dir/other.html |
失败 | 主机不同 |

浙公网安备 33010602011771号