防止从$ _GET方法显示HTML

发布于 2025-01-20 08:48:03 字数 844 浏览 3 评论 0原文

我目前正在开发用户管理系统。 我在其他网站中有注册和登录页面,它们都使用 $_GET 函数。经过一番尝试后,我注意到,当您确切知道自己在做什么时,可以从 GET 参数打印 HTML 代码。可能有一种方法可以通过在 img 标签中使用 onerror 来利用这个问题,例如
如何防止这种情况发生?

网址:users.php?s=login&mail=">%20
它显示的内容: 输入图片此处描述我的代码:

print ' <form action="' .$url. '" method="post">
                <input type="hidden" name="a" value="login"/>
    
                <b><label for="mail">E-Mail:</label></b>
                <input type="email" id="mail" name="mail" maxlength="50" value="' .$mail. '" required><br><br>

如何防止这种情况发生?

I'm currently working on a user management system.
I have the register and sign-in page among other sites, that all use the $_GET function. After experimenting around a bit I noticed that you can print HTML code from the GET parameters when you exactly know what you are doing. There is probably a way to exploit this by using the onerror in an img tag e.g.

How can I prevent this from happening?

The URL: users.php?s=login&mail=">%20<img%20src=%27../images/notification_bell.png%27%20width=%2725px%27>

What it displays:
enter image description here
And my code:

print ' <form action="' .$url. '" method="post">
                <input type="hidden" name="a" value="login"/>
    
                <b><label for="mail">E-Mail:</label></b>
                <input type="email" id="mail" name="mail" maxlength="50" value="' .$mail. '" required><br><br>

How can I prevent this from happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住你手 2025-01-27 08:48:03

使用HTMLSpecialChars将用户定义的字符转换为Web-Safe代码。 https://www.php.net/htmlspecialchars

也许您也可以使用fill_var /代码>验证电子邮件,如果它无效,请删除它。 https://www.php.net/filter_var

use htmlspecialchars to convert user-defined characters into web-safe code. https://www.php.net/htmlspecialchars

also, maybe you could use filter_var to validate the email and simply unset it if it's invalid. https://www.php.net/filter_var

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文