清理稍后将通过电子邮件发送的用户输入 - 我应该担心什么?
我正在印度的一个非政府组织(Seva Mandir,http://sevamandir.org)实习,并试图修复他们的问题“订阅时事通讯”框已损坏。因为工作人员不是很熟练,而且我们的虚拟主机也不是很好,所以我决定通过 mail() 将相关数据发送给出版人员,而不是将其存储在 MySQL 数据库中。
我知道最好将用户输入视为恶意输入,并且我在 SO 论坛中搜索了与转义用户数据以在邮件中发送相关的帖子。我知道数据应该被转义;我应该担心什么?在通过电子邮件发送之前清理输入的最佳方法是什么?
另请注意,该组织的 Web 主机仍在使用 PHP 4,因此我不能仅对字符串使用 filter_var。我与他们一起解决问题,但现在我必须使用正则表达式或 strip_tags 或其他一些方法。
表单流程:
1. 用户在主页输入电子邮件并点击提交
2. 用户在第二页上输入姓名、地址和更多信息(我知道可用性不好,但我的老板要求我这样做),然后单击“提交”
3. 通过 $_POST 收集数据并将其通过电子邮件发送给出版物编辑(并可能向订阅者发送确认)。
我将在步骤 2 中清理电子邮件并在步骤 3 中清理其他数据。非常感谢您的帮助,
凯文
I'm interning for an NGO in India (Seva Mandir, http://sevamandir.org) and trying to fix their broken "subscribe to newsletter" box. Because the staff isn't very sophisticated and our web host isn't great, I decided to send the relevant data to the publications person via mail() instead of storing it in a MySQL database.
I know that it's best to treat user input as malicious, and I've searched the SO forums for posts relevant to escaping user data for sending in a mail message. I know the data should be escaped; what should I be worried about and what's the best way to sanitize the input before emailing it?
Also note that the org's web host is still using PHP 4, so I can't just use filter_var for strings. I'm working with them to fix the problem, but for now I'd have to use regexes or strip_tags or some other method.
Form flow:
1. User enters email on homepage and clicks Submit
2. User enters name, address, more information on second page (bad usability, I know, but my boss asked me to) and clicks "Submit"
3. Collect the data via $_POST and email it to the publications editor (and possibly send a confirmation to the subscriber).
I am going to sanitize the email in step 2 and the other data in step 3. I appreciate your help,
Kevin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用用户输入的电子邮件地址发送确认信息,请确保他们只输入了一封电子邮件。如果您不小心,垃圾邮件发送者可能会在您的邮件标头中偷偷换行,从而将任意长的
Bcc:
条目插入您的邮件标头中。请参阅电子邮件注入。
If you're using the user-entered email address to send a confirmation, ensure that they've only entered one email. A spammer can sneak line breaks, and therefore arbitrarily long
Bcc:
entries, into your message headers if you don't watch out.See email injection.
您需要注意电子邮件标头注入攻击。
基本上,如果您从
$name
、$from
、中剥离
和\n
和\r
$to$subject
您应该相当安全,但最好采用白名单方法。You need to be aware of Email Header Injection attacks.
Basically if you strip
\n
and\r
from the from the$name
,$from
,$to
and$subject
you should be fairly safe, but it's always best to take a white list approach.据我所知,只要您使用纯文本并将用户输入的数据仅插入到电子邮件正文中,就没有什么需要清理的。
As far I as I know, as long as you're using plain text and insert user entered data only into email body, there is nothing to sanitize.