在 POST 请求中对最少字符进行编码:安全吗?
我遇到了一种只对 POST 参数值中的以下 4 个字符进行编码的方法: #
;
&
+
。如果有的话,它会导致什么问题?
我个人不喜欢这样的黑客行为。我之所以问这个问题,是因为我和它的发明者发生了争执。
更新。澄清一下,这个问题是关于 POST 正文中的编码参数,而不是关于在服务器端转义 POST 参数,例如在将它们输入 shell、数据库、HTML 之前页面或其他任何内容。
I came across an approach to encode just the following 4 characters in the POST parameter's value: #
;
&
+
. What problems can it cause, if any?
Personally I dislike such hacks. The reason why I'm asking about this one is that I have an argument with its inventor.
Update. To clarify, this question is about encoding parameters in the POST body and not about escaping POST parameters on the server side, e. g. before feeding them into shell, database, HTML page or whatever.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
考虑一下:
$sql ='DELETE * from
articlesWHERE
id='.$_POST['id'].';
然后您输入以下形式:
1' OR '10
然后就变成这样:
$sql ='DELETE * from
articlesWHERE
id='1' OR '10';
Consider this:
$sql ='DELETE * from
articlesWHERE
id='.$_POST['id'].';
And you enter in the form:
1' OR '10
It then Becomes this :
$sql ='DELETE * from
articlesWHERE
id='1' OR '10';
来自 rfc1738 (如果您使用的是
application/x-www-form -urlencoded
编码传输数据):From rfc1738 (if you're using
application/x-www-form-urlencoded
encoding to transfer data):通常(总是?)进行转义元字符是为了防止注入攻击。不同的系统有不同的元字符,因此每个系统都需要自己的防止注入的方法。不同的系统有不同的转义字符的方式。有些系统不需要转义字符,因为它们具有不同的控制和数据通道(例如准备好的语句)。此外,通常最好在将数据引入系统时执行过滤。
最大的问题是仅转义这四个字符并不能提供完整的保护。过滤你提到的四个字符后,SQL、HTML 和 shell 注入攻击仍然是可能的。
Escaping metacharacters is usually (always?) done to prevent injection attacks. Different systems have different metacharacters, so each needs its own way of preventing injections. Different systems have different ways of escaping characters. Some systems don't need to escape characters, since they have different channels for control and data (e.g. prepared statements). Additionally, the filtering is usually best performed when the data is introduced to a system.
The biggest problem is that escaping only those four characters won't provide complete protection. SQL, HTML and shell injection attacks are still possible after filtering the four characters you mention.