【问题标题】:HTML form tag action attribute is blank but the submit button still work?HTML 表单标签操作属性为空但提交按钮仍然有效?
【发布时间】:2017-07-11 11:50:21
【问题描述】:

这是一个 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不会显示所有代码?

【问题讨论】:

  • 您的按钮工作因为它在form 内。顺便说一句,如果&lt;form action=""&gt; 为空,则表示数据将发送到当前文件。
  • 只需从提交切换到其他类型

标签: javascript html forms submit-button


【解决方案1】:

当表单的action属性为空时,点击提交按钮时表单会被提交到同一个页面。如果您不希望在单击提交按钮时提交您的表单..

只需用这个替换你的表单标签:

<form action="" onsubmit="return false" method="GET">

【讨论】:

    【解决方案2】:

    带有空白的动作属性将使用当前页面作为目标。尽管未定义 URL 以外的 HTML 4 specification saying 操作,但所有浏览器都以这种方式工作。

    对于 HTML5,规范中实际上也是这样写的。

    【讨论】:

      【解决方案3】:

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

      如果您不需要这种行为,我建议您在页面中使用&lt;input type="button" /&gt; 或简单的button 标签。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-08
        • 1970-01-01
        • 1970-01-01
        • 2016-07-10
        相关资源
        最近更新 更多