在发送每封电子邮件之前过滤用户输入
我正在用 PHP 创建一个简单的反馈表单:用户只需输入一些关于我的网站的评论/建议等,然后单击“发送反馈”。然后他输入的文本将作为电子邮件正文直接发送给我(即我自己设置收件人地址,用户的输入仅在邮件正文中使用)。
现在我不确定,如果我只是简单地获取未经过滤的文本并将其插入电子邮件正文中,可能会发生什么样的攻击。
我目前正在使用 Joomla 平台(即我正在使用 Joomla 的 JMail
功能),但我认为问题更普遍:有很多关于 SQL 注入和跨站点脚本的信息(这是等效的攻击向量),但我没有找到太多关于电子邮件的信息。
请注意,在我的例子中,文本仅每封电子邮件发送,因此我不关心 SQL 注入或跨站点脚本(电子邮件以纯文本形式发送)。那么我应该应用什么样的过滤呢?
谢谢 马丁
I'm creating a simple feedback form in PHP: The user can just enter some comments/suggestions etc. about my site and click "Send feedback". Then the text he entered is send as the body of an email directly to me (i.e. I set the recipient address by myself, user's input is only used within the body of th mail).
Now I'm not sure, what sort of attacks would be possible if I simply take the unfiltered text and insert it into the email body.
I'm currently working with the Joomla platform (i.e. I'm using Joomla's JMail
functionality), but I think the question is more general: There's a lot of information about SQL injection and Cross-Site-Scripting (which are equivalent attack vectors), but I didn't find much about emails.
Note that in my case, the text is only sent per email, so I do not care about SQL-Injection or Cross-Site-Scripting (the email is sent as plain text). So what kind of filtering should I apply?
Thanks
Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您只需要评论和建议,因此您可以简单地删除除字母、数字和“.”、“,”之外的任何字符。即使它删除了其他字符,对您来说也没关系,您会知道它们的含义。 “=”是最大的敌人。但我描述的这套装置应该可以保证你的安全。
Since you are expecting only comments and suggestions, you can simply remove any characters other thant alphabets, numbers, and ".", ",". Even if it removes other characters it wouldn't matter to you, you would get to know what they mean. The "=" is the biggest enemy. But the set I described should keep you safe.
最重要的是垃圾邮件防护。
如果您以 HTML 格式发送电子邮件,则应过滤标签(strip_tags 或 htmlspecialchars)或验证用户的 HTML (HTMLPurifier http://htmlpurifier.org/< /a>)
限制消息的长度也很有用。
Most important will be SPAM protection.
If you send email in HTML you should filter tags (strip_tags or htmlspecialchars) or validate user's HTML (HTMLPurifier http://htmlpurifier.org/)
Limiting the length of the message also can be useful.