![](/img/trans.png)
[英]Apache X-Frame-Options conflict for IE and Chrome (only either one worked!)
[英]Why does only IE check the X-Frame-Options Header when iFrame src sends a file?
調試一個奇怪的問題后,我偶然發現了一個有趣的行為:
在網頁上,我使用以下JavaScript代碼觸發文件下載:
var iframe = document.createElement("iframe");
iframe.src = 'download.php';
document.body.appendChild(iframe);
PHP腳本download.php發送一個X-Frame-Options標頭設置為DENY的文本文件:
<?php
header('X-Frame-Options: DENY');
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="text.txt"');
?>
Text
Chrome和Firefox允許下載文件,IE 11顯示一個iframe,並顯示一條消息,指出內容無法嵌入。
正確的行為是什么? 對我來說,IE所做的事情更有意義。
X-Frame-Options
可以防止點擊劫持。 阻止文件下載不是X-Frame-Options
想要實現的目標,因為可以通過在新窗口中打開鏈接來輕松繞過這種限制。
因此,Chrome和Firefox的行為是正確的。
(另請參見https://crbug.com/331211 “ X-Frame-Options標志並非旨在阻止下載。它們僅阻止將頁面顯示為子幀。”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.