初探 Content-Security-Policy (CSP)

問題 原有 a.com/hello 當中嵌入 a.com/world iframe 本身沒問題,後來因為公司政策改變需要調整為 hello.a.com 與 world.a.com 而原有的 a.com/hello 以及 a.com/world 拜訪後會 redirect 到 hello.a.com 與 world.a.com 當中,而在這中間發現 iframe 失效並嘗試進行解決。 依照同源政策規則,調整為 hello.a.com 與 world.a.com 視為不同源,因此需要額外配置。 同源定義 所謂同源是指兩份網頁具備相同協定、埠號 (如果有指定) 以及主機位置,下表提供了一些例子展示那些來源和 http://store.company.com/dir/page.html 屬於同源: URL Outcome Reason 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://news.company.com/dir/other.html 不同源 ✅ 主機位置不同 ✅ MDN 說明 出錯點 Refused to display 'https://world.a.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'. 問題思路與解法 X-Frame-Options MDN 說明...

August 22, 2023 · Yish