为什么这个 XSS 不起作用?

Why doesn't this XSS work?

可能是一个简单的解决方案,但我不明白为什么我尝试通过索引页面上的 XSS 输入在欢迎页面上 运行 这个警报脚本不起作用。

我有一个简单的 index.htm 页面,其中包含一个表单:

<!DOCTYPE html>
<html>
<body>
    <form method="post" action="welcome.php">
        Name: <input type="text" name="name">
        <input type="submit">
    </form>
</body>
</html>

和 welcome.php 文件:

<!DOCTYPE html>
<html>
<body>

    <h3> Welcome <?php echo $_POST['name']; ?> </h3>

</body>
</html>

作为 index.php 页面的访问者,我试图在名称字段中输入:

这与 PHP 本身无关,因为大多数浏览器都有 XSS auditor 来保护用户免受已知的 XSS 攻击

运行 您的示例将导致:

The XSS Auditor refused to execute a script in 'http://localhost:9093/welcome.php' because its source code was found within the request. The auditor was enabled as the server did not send an 'X-XSS-Protection' header.

更多信息,您可以查看this question