在 POST 请求中对最少字符进行编码:安全吗?

发布于 2024-08-22 23:25:17 字数 294 浏览 9 评论 0原文

我遇到了一种只对 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 技术交流群。

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

发布评论

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

评论(3

べ映画 2024-08-29 23:25:18

考虑一下:$sql ='DELETE * fromarticlesWHEREid='.$_POST['id'].';

然后您输入以下形式:1' OR '10

然后就变成这样:$sql ='DELETE * fromarticlesWHEREid='1' OR '10';

Consider this: $sql ='DELETE * fromarticlesWHEREid='.$_POST['id'].';

And you enter in the form: 1' OR '10

It then Becomes this : $sql ='DELETE * fromarticlesWHEREid='1' OR '10';

御守 2024-08-29 23:25:17

来自 rfc1738 (如果您使用的是 application/x-www-form -urlencoded 编码传输数据):

不安全:

出于多种原因,角色可能不安全。空格字符是不安全的,因为当 URL 被转录、排版或接受文字处理程序处理时,重要的空格可能会消失,而无关紧要的空格可能会被引入。字符“<”和“>”不安全,因为它们被用作自由文本中 URL 的分隔符;在某些系统中,引号 (""") 用于分隔 URL。字符“#”是不安全的,应始终进行编码,因为它在万维网和其他系统中用于分隔 URL 与片段/锚点其后的标识符是不安全的,因为它用于其他字符的编码,因为网关和其他传输代理有时会修改这些字符。 "、"|"、"\"、"^"、"~"、"["、"]" 和 "`"。

所有不安全字符必须始终在 URL 中进行编码。例如,即使在通常不处理片段或锚标识符的系统中,字符“#”也必须在 URL 中进行编码,因此,如果将 URL 复制到使用它们的另一个系统中,则无需更改URL 编码。

From rfc1738 (if you're using application/x-www-form-urlencoded encoding to transfer data):

Unsafe:

Characters can be unsafe for a number of reasons. The space character is unsafe because significant spaces may disappear and insignificant spaces may be introduced when URLs are transcribed or typeset or subjected to the treatment of word-processing programs. The characters "<" and ">" are unsafe because they are used as the delimiters around URLs in free text; the quote mark (""") is used to delimit URLs in some systems. The character "#" is unsafe and should always be encoded because it is used in World Wide Web and in other systems to delimit a URL from a fragment/anchor identifier that might follow it. The character "%" is unsafe because it is used for encodings of other characters. Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`".

All unsafe characters must always be encoded within a URL. For example, the character "#" must be encoded within URLs even in systems that do not normally deal with fragment or anchor identifiers, so that if the URL is copied into another system that does use them, it will not be necessary to change the URL encoding.

乖乖兔^ω^ 2024-08-29 23:25:17

通常(总是?)进行转义元字符是为了防止注入攻击。不同的系统有不同的元字符,因此每个系统都需要自己的防止注入的方法。不同的系统有不同的转义字符的方式。有些系统不需要转义字符,因为它们具有不同的控制和数据通道(例如准备好的语句)。此外,通常最好在将数据引入系统时执行过滤。

最大的问题是仅转义这四个字符并不能提供完整的保护。过滤你提到的四个字符后,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.

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