PHP 过滤来自 PayPal IPN 的 POST?
我设置了一个 PayPal IPN PHP 文件,它将所有 IPN 帖子内容变量分配给变量。该文件仅来自 paypal.com(即没有人应该知道它的 URL)。
我的问题是,我应该采取必要的步骤来过滤和清理来自 PayPal 的 POST 数据,还是屏蔽我的 IPN 文件名 (IPN_082j3f08jasdf.php) 就足够了?
另外,有人可以确认我的清理代码吗?这是非常基本的。我在通过 POST 或 GET 发送的所有内容上运行它,我的目标是防止任何类型的 MySQL 注入或黑客所做的任何事情。
function filter($data){
// changes & to &
// changes " to "
// removes \ < >
$data = trim(htmlentities(strip_tags($data)));
if(get_magic_quotes_gpc()){
$data = stripslashes($data);
}
$data = mysql_real_escape_string($data);
return $data;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
抱歉给了我不好的建议!请忽略这篇文章! - 保持它不被删除,因为它在下面产生了一些有趣的讨论
如果没有人应该知道它的 URL,那么 SQL 清理可能不是一个大问题。除非有人劫持了您的目录列表,否则屏蔽您的 IPN 文件就足够了。
htmlentities()
需要有一个 ENT_QUOTES 标志来转换引号。如果
get_magic_quotes_gpc()
开启,则strip_slashes
会自动完成......在您的情况下,看起来您将双条斜杠。mysql_real_escape_string
也将完成strip_slashes()
的工作...Sorry for the bad advice! Please disregard this post! - keeping it undeleted, as it's generated some interesting discussion below
If no one should know its URL, the SQL-sanitize is probably not that big of an issue. Masking your IPN file should be enough unless someone hijacks your directory listing.
htmlentities()
will need to have an ENT_QUOTES flag to convert quotes.if
get_magic_quotes_gpc()
is on, thenstrip_slashes
are automatically done... in your case, it looks like you will double strip slashes.also
mysql_real_escape_string
will do the work ofstrip_slashes()
already ...混淆文件名永远还不够——是的,您需要过滤 POST 数据。假设不是 PayPal 调用该脚本,直到您能证明这一点。
卫生看起来不错——如果你的代码变得很长,我倾向于分两步对其进行清理——开头的 strip_tags 和基本卫生,以及在你联系数据库的同时 mysql 转义——这使得维护IMO更容易。
obfuscating the filename is never enough -- you need to filter the POST data, yes. Assume it is not PayPal calling the script until you can prove it.
the sanitation looks OK -- if your code becomes quite long though, I would tend to sanitize it in two steps --the strip_tags and basic sanitation at the beginning, and the mysql escaping at the same time you contact the database -- it makes it easier to maintain IMO.
您还可以考虑使用 Kohana PHP 框架也使用的更强大的过滤机制,可以在此处找到:
http://svn.bitflux.ch/repos/public/popoon/trunk/类/externalinput.php
You may also consider using more robust filtration mechanism used also by Kohana php framework which can be found here:
http://svn.bitflux.ch/repos/public/popoon/trunk/classes/externalinput.php