HTML表单标记操作属性为空,但提交按钮仍然有效?

时间:2017-07-11 11:50:21

标签: javascript html forms submit-button

这是一个XSS游戏网络来进行XSS攻击。关于第1级,我对表单的提交方式有疑问,操作是空白的,那么提交按钮的工作原理是什么? http://www.xssgame.com/f/m4KKGHi2rVUN/? 它的HTML代码是:

<!DOCTYPE html>
<html>
  <head>
    <style>
      body {
        background-color: #ffffff;
      }
    </style>
    <script src="/static/js/js_frame.js"></script>
  </head>
  <body>
    <center>
      <img src="/static/img/foogle.png">
      <br>
      <form action="" method="GET">
        <input id="demo2-query" name="query" value="Enter query here..."
          onfocus="this.value=''">
        <input id="demo2-button" type="submit" value="Search">
      </form>
    </center>
  </body>
</html>

和js_frame.js文件是:

top.postMessage({url:window.location.toString()},"*");var originalAlert=window.alert;
window.alert=function(b){function a(){document.getElementById("next_level")?originalAlert("Congratulations, you executed an alert:\n\n"+b+"\n\nYou can now advance to the next level."):originalAlert("You executed an alert, but the server side validation of your solution failed. It probably means that your solution requires user interaction, or is not generic enough to work for a different user. Please try to make it work without user interaction and generic enough so that it works for any user.")}console.log("solved");
top.postMessage("success","*");"onvalidationready"in window?window.onvalidationready=a:setTimeout(a,0)};

添加:我看到html代码不包含可以接收提交的代码,或者是因为chrome控制台的Sources不会显示所有代码?

3 个答案:

答案 0 :(得分:0)

具有空白的操作属性将使用当前页面作为目标。这种方式在所有浏览器中均有效,尽管未定义除URL以外的HTML 4 specification saying操作。

使用HTML5,它实际上也是在规范中以这种方式编写的。

答案 1 :(得分:0)

表单提交的默认行为是将内容发送到服务器上的操作url文件进行处理。如果未指定任何操作或操作保持为空,则浏览器假定当前文件(包含html表单)也是处理文件。因此,请求将当前页面Url作为操作。

如果您不需要此行为,建议您在页面中使用<input type="button" />或简单button标记。

答案 2 :(得分:0)

当表单的action属性留空时,单击提交按钮时表单将提交到同一页面。如果您不希望在单击提交按钮时提交表单,那么

只需用以下内容替换您的表单标记:

<form action="" onsubmit="return false" method="GET">
相关问题