我在一个页面上放置了一个指向另一个域的域iframe。一切正常。然后我通过POST方法发送到iframe表单,当它来回复时,Internet Explorer生成一个错误
Internet Explorer has modified this page to help prevent cross-site scripting
当我通过GET发送表单时,一切正常。
为什么会出现这个问题?我该怎么修理它?如果我无法访问承载iframe的页面,我可以修复它吗?
当请求中的某些内容也在响应中时,通常会发生这种情况。例如:
http://example.com/somepage?name=%3Cscript%3Ealert(%22lol%20hax%22%2Bdocument.cookie)%3B%3C%2Fscript%3E
所以这个问题完全取决于什么你是张贴到iframe。一般来说,您应该避免使用跨域iframe。
我知道这是个老问题,但是Niet在这个问题上是对的。解决方案是为该特定页面启用CORS。详细说明:http://www.html5rocks.com/en/tutorials/cors/
对于PHP,我使用的解决方案是:$http_protocolPos = stripos($_SERVER['SERVER_PROTOCOL'], '/');
$http_protocol = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, $http_protocolPos)).'://';
$http_serverName = $_SERVER['SERVER_NAME'];
$httpFull = $http_protocol . $http_serverName;
if ($httpFull == "{$http_protocol}www.example1.com" || $httpFull == "{$http_protocol}www.example2.com" ||
$httpFull == "{$http_protocol}localhost" )
{
header("Access-Control-Allow-Origin: $httpFull");
}
根据微软的文档,这也可以工作:
头(X-XSS-Protection: 0);
但我只是猜测。