PHP 过滤来自 PayPal IPN 的 POST?

发布于 2024-09-12 11:53:40 字数 582 浏览 0 评论 0 原文

我设置了一个 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;
}

I have a PayPal IPN PHP file set up which assigns all of the IPN post contents variables to variables. This file is only 'hit' from paypal.com (ie nobody should know it's url).

My question is should I take the necessary steps to filter and sanitize the POST data from PayPal or is masking my IPN file name (IPN_082j3f08jasdf.php) enough?

Also, could somebody confirm my sanitize code? It's pretty basic. I run it on EVERYTHING sent via POST or GET and my goal is to prevent any kind of MySQL injections or whatever hackers do.

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 技术交流群。

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

发布评论

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

评论(3

吹梦到西洲 2024-09-19 11:53:41

抱歉给了我不好的建议!请忽略这篇文章! - 保持它不被删除,因为它在下面产生了一些有趣的讨论

如果没有人应该知道它的 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, then strip_slashes are automatically done... in your case, it looks like you will double strip slashes.

also mysql_real_escape_string will do the work of strip_slashes() already ...

原来分手还会想你 2024-09-19 11:53:40

混淆文件名永远还不够——是的,您需要过滤 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.

戏剧牡丹亭 2024-09-19 11:53:40

您还可以考虑使用 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

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