简体   繁体   English

X-XSS-Protection假阳性?

[英]X-XSS-Protection false positive?

I encounter a strange behavior with my webapp into safari (no problem at all with FF). 我的webapp遇到了一个奇怪的行为进入safari(FF完全没问题)。

The code is pretty simple : 代码非常简单:

  • I have a form which contains some checkboxes. 我有一个包含一些复选框的表单。
  • I click on the submit button, which send the data via POST to the same page, in which a PHP script writes a cookie 我点击提交按钮,它通过POST将数据发送到同一页面,其中PHP脚本写入cookie
  • then, PHP reloads the same page with header("Location:index.php"); 然后,PHP重新加载带有标题的相同页面(“Location:index.php”);

Unfortunately, I get the following error with Safari : 不幸的是,我在Safari中遇到以下错误:

"Refused to execute a JavaScript script. Source code of script found within request." “拒绝执行JavaScript脚本。在请求中找到脚本的源代码。”

The page does NOT send javascript or URL or other malicious code. 该页面不发送javascript或URL或其他恶意代码。 It just POST datas from a form. 它只是从表单POST数据。 So, how could I avoid this ? 那么,我怎么能避免这种情况呢? Could anyone explain why safari tells me I want to execute javascript code ? 谁能解释为什么safari告诉我我想执行javascript代码? (Of course, adding "header("X-XSS-Protection: 0");" in top of the page fixes the problem. But I'm not very happy with this kind of countermeasure...) (当然,添加“标题(”X-XSS-Protection:0“);”在页面顶部修复了问题。但我对这种对策不满意......)

This is some relevant parts of the code (simplified): 这是代码的一些相关部分(简化):

<?php
if(@$_POST["foo"] == "yes"){
    $choice = join("-", $_POST["choice"]);
    setcookie("bar",$choice, time()+900000);
    header("Location:index.php");
    }
?>


<form method="post" action="index.php">
<input type="hidden" name="foo" value="yes">
<p><input type='checkbox' name='choice[]' value='foo'> foo</p>
<p><input type='checkbox' name='choice[]' value='bar'> bar</p>
<p><input type='checkbox' name='choice[]' value='baz'> baz</p>
<input type="submit">
</form>

Thanks in advance for your responses ! 在此先感谢您的回复!

EDIT : 编辑:

  • I strongly suspect a bug in my favourite version of Safari (5) since the code is working perfectly in safari 6 (ML), firefox and chrome. 我强烈怀疑我最喜欢的Safari(5)版本中有一个错误,因为代码在safari 6(ML),firefox和chrome中完美运行。
  • Putting the setcookie section on the top of the page and call "exit" right after header("location:") doesn't fix the problem. 将setcookie部分放在页面顶部并在标题(“location:”)之后调用“exit”不能解决问题。
  • Even if I put the setcookie in a separate PHP script and reload the page from within this new page, I got the same error in safari 5. 即使我将setcookie放在一个单独的PHP脚本中并从这个新页面重新加载页面,我在safari 5中也遇到了同样的错误。

As requested by silverlightfox, here are some screenshots of the http response headers of the 2 pages : 根据silverlightfox的要求,以下是2页的http响应标题的一些屏幕截图:

设置cookie的页面标题

重新加载页面的标题

After setting the Location header, you should make a call to exit . 设置Location标头后,您应该拨打电话exit

This will prevent any more processing of your page, and the rest of the response will not be sent to the browser (the HTML content will still be sent, even though you are redirecting if you do not call exit ). 这将阻止对页面的任何进一步处理,并且其余的响应将不会发送到浏览器(即使您没有调用exit ,即使您正在重定向,HTML内容仍将被发送)。

My guess is that there is output of an unencoded parameter somewhere in your page (not present in your code snippet in your question). 我的猜测是在页面的某处输出了未编码的参数(在你的问题的代码片段中没有)。 View the page output to see if your HTML content is inadvertently generating any JavaScript code in the HTTP response body after the redirect header is sent. 在发送重定向标头后,查看页面输出以查看HTML内容是否无意中在HTTP响应正文中生成任何JavaScript代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM