fbpx
维基百科

同源策略

同源策略(英語:Same-origin policy)是指在Web浏览器中,允許某个网页腳本访问另一個网页的数据,但前提是這两个网页必須有相同的URI主机名端口号,一旦兩個網站滿足上述條件,這兩個網站就被認定為具有相同來源。此策略可防止某个网页上的恶意脚本通过该页面的文档对象模型访问另一网页上的敏感数据。

同源策略对Web应用程序具有特殊意义,因为Web应用程序广泛依赖于HTTP cookie[1]来維持用户会话,所以必须將不相关網站严格分隔,以防止丢失数据洩露。

值得注意的是同源策略仅适用于脚本,这意味着某網站可以通过相应的HTML标签[2]访问不同來源網站上的图像CSS动态加载脚本等资源。而跨站请求伪造就是利用同源策略不适用于HTML标签的缺陷。

相同來源網站舉例 编辑

下表列出哪些URLURL http://www.example.com/dir/page.html 屬於相同來源:

URL 結果 原因
http://www.example.com/dir/page2.html 只有路径不同
http://www.example.com/dir2/other.html 只有路径不同
http://username:password@www.example.com/dir2/other.html 只有路径不同
http://www.example.com:81/dir/other.html 不同端口(若未標明,http:// 默認端口號為80)
https://www.example.com/dir/other.html[失效連結] 不同协议httpshttp
http://en.example.com/dir/other.html 不同域名
http://example.com/dir/other.html 不同域名(需要完全匹配)
http://v2.www.example.com/dir/other.html 不同域名(需要完全匹配)

另見 编辑

参考文献 编辑

  1. ^ IETF [rfc:6265 HTTP State Management Mechanism, Apr, 2011]
  2. ^ Kemp, John. Security on the Web. 2011-02-04 [2018-07-24]. (原始内容于2020-09-23). The same-origin policy states that a document from one unique origin may only load resources from the origin from which the document was loaded. In particular this applies to XMLHttpRequest calls made from within a document. Images, CSS and dynamically-loaded scripts are not subject to same-origin policy. 

外部链接 编辑

同源策略, 此條目可参照英語維基百科相應條目来扩充, 若您熟悉来源语言和主题, 请协助参考外语维基百科扩充条目, 请勿直接提交机械翻译, 也不要翻译不可靠, 低品质内容, 依版权协议, 译文需在编辑摘要注明来源, 或于讨论页顶部标记, href, template, translated, page, html, title, template, translated, page, translated, page, 标签, 英語, same, origin, policy, 是指在web浏览器中, 允許某个网页腳. 此條目可参照英語維基百科相應條目来扩充 若您熟悉来源语言和主题 请协助参考外语维基百科扩充条目 请勿直接提交机械翻译 也不要翻译不可靠 低品质内容 依版权协议 译文需在编辑摘要注明来源 或于讨论页顶部标记 a href Template Translated page html title Template Translated page Translated page a 标签 同源策略 英語 Same origin policy 是指在Web浏览器中 允許某个网页腳本访问另一個网页的数据 但前提是這两个网页必須有相同的URI 主机名和端口号 一旦兩個網站滿足上述條件 這兩個網站就被認定為具有相同來源 此策略可防止某个网页上的恶意脚本通过该页面的文档对象模型访问另一网页上的敏感数据 同源策略对Web应用程序具有特殊意义 因为Web应用程序广泛依赖于HTTP cookie 1 来維持用户会话 所以必须將不相关網站严格分隔 以防止丢失数据洩露 值得注意的是同源策略仅适用于脚本 这意味着某網站可以通过相应的HTML标签 2 访问不同來源網站上的图像 CSS和动态加载脚本等资源 而跨站请求伪造就是利用同源策略不适用于HTML标签的缺陷 目录 1 相同來源網站舉例 2 另見 3 参考文献 4 外部链接相同來源網站舉例 编辑下表列出哪些URL與URL http www example com dir page html 屬於相同來源 URL 結果 原因http www example com dir page2 html 是 只有路径不同http www example com dir2 other html 是 只有路径不同http username password www example com dir2 other html 是 只有路径不同http www example com 81 dir other html 否 不同端口 若未標明 http 默認端口號為80 https www example com dir other html 失效連結 否 不同协议 https和http http en example com dir other html 否 不同域名http example com dir other html 否 不同域名 需要完全匹配 http v2 www example com dir other html 否 不同域名 需要完全匹配 另見 编辑跨來源資源共享 跨網站指令碼 跨站请求伪造 污点检验 内容安全策略参考文献 编辑 IETF rfc 6265 HTTP State Management Mechanism Apr 2011 Kemp John Security on the Web 2011 02 04 2018 07 24 原始内容存档于2020 09 23 The same origin policy states that a document from one unique origin may only load resources from the origin from which the document was loaded In particular this applies to XMLHttpRequest calls made from within a document Images CSS and dynamically loaded scripts are not subject to same origin policy 外部链接 编辑相同来源策略的几种风格的详细比较 页面存档备份 存于互联网档案馆 A review of deficiencies in same origin policies and their implication for web security 存档于互联网档案馆 存檔日期 February 11 2007 样本供应商提供的同源策略规范 页面存档备份 存于互联网档案馆 HTML5规范的来源定义 页面存档备份 存于互联网档案馆 W3C关于同一原产地政策的文章 页面存档备份 存于互联网档案馆 RFC 6454 on The Web Origin Concept 页面存档备份 存于互联网档案馆 博客文章 Cookie相同来源政策 页面存档备份 存于互联网档案馆 用于内容安全政策的wordpress org插件 页面存档备份 存于互联网档案馆 取自 https zh wikipedia org w index php title 同源策略 amp oldid 79229074, 维基百科,wiki,书籍,书籍,图书馆,

文章

,阅读,下载,免费,免费下载,mp3,视频,mp4,3gp, jpg,jpeg,gif,png,图片,音乐,歌曲,电影,书籍,游戏,游戏。