消毒?当它既不输出为 HTML 也不进入 SQL 查询时

发布于 2024-12-22 11:32:34 字数 696 浏览 1 评论 0原文

查看一些网站后(例如 https://www.owasp.org/index.php/Main_Page< /a>) 我发现没有明确提及以下过程会给我带来哪些危险;

用户回答多项选择题。发送带有“答案”作为隐藏字段的表单。

.php 页面获取它(验证它少于 100 个字符),然后从数据库中获取正确答案。它比较两者(使用 == 比较运算符)。

然后发送

 echo "Wrong! The correct answer is ".$correctAnswer; //a hack presumably will always be wrong!!!

基本上,让用户输入(最多 100 个字符)陷入

$playersAnswer = $_POST['checkAnswer'];

and

 if ($correctAnswer == $playersAnswer){ ....etc

可能会造成什么损害。对我来说,优点是我不必担心用户答案中的任何字母/符号/字符被删除或转换。因此我可以毫无畏惧地使用带有完整标点符号的问题、外语问题甚至有关 javascript 的问题!

After looking through some sites (eg https://www.owasp.org/index.php/Main_Page) I found no EXPLICIT mention of what hazards the following process would open me up to;

A user answers a multiple choice question. Sending a form with the "answer" as a hidden field.

The .php page takes it (validates it to have less than 100 characters), then takes the Correct Answer from the database. It compares the two (using == comparison operator).

then sends

 echo "Wrong! The correct answer is ".$correctAnswer; //a hack presumably will always be wrong!!!

Basically, what damage could there possibly be with letting userinput (up to 100 characters) get stuck into

$playersAnswer = $_POST['checkAnswer'];

and

 if ($correctAnswer == $playersAnswer){ ....etc

The advantage for me is that I need not worry about any letters/symbols/characters in the user's answer being stripped or converted. Therefore I can use questions with full punctuation, foreign languages and even questions about javascript wwithout fear!

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

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

发布评论

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

评论(1

少女净妖师 2024-12-29 11:32:34

如果您所做的只是在比较中使用 POST 变量:

$correctAnswer == $playersAnswer

则没有危险。

危险从您使用变量的地方开始 - 在 HTML 输出中、在数据库查询中、在 exec()eval() 命令中。 ....

If all you do is use the POST variable in a comparison:

$correctAnswer == $playersAnswer

there is no danger to this.

The danger begins where you use the variable - in HTML output, in a database query, in an exec() or eval() command.....

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