为什么iFrame src发送文件时IE只检查X-Frame-Options Header?
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 header 设置为拒绝的文本文件:
<?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
旨在实现的目标,因为可以通过在新的 window.
中打开 link 轻松绕过这种限制。
因此 Chrome 和 Firefox 的行为是正确的。
(另见 https://crbug.com/331211 "The X-Frame-Options flags aren't intended to prevent downloading. They only prevent displaying the page as a subframe.")
调试一个奇怪的问题,我偶然发现了一个有趣的行为:
在网页上,我使用以下 JavaScript 代码触发文件下载:
var iframe = document.createElement("iframe");
iframe.src = 'download.php';
document.body.appendChild(iframe);
PHP 脚本 download.php 发送一个 X-Frame-Options header 设置为拒绝的文本文件:
<?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
旨在实现的目标,因为可以通过在新的 window.
因此 Chrome 和 Firefox 的行为是正确的。
(另见 https://crbug.com/331211 "The X-Frame-Options flags aren't intended to prevent downloading. They only prevent displaying the page as a subframe.")