apache - 在调用 CGI 并且 URI 包含没有值的单个查询字符串参数时,Apache2 中是否存在特殊情况?

标签 apache ubuntu cgi query-string

今天我遇到了一个错误并且非常惊讶,因为一切看起来都很好......

我有一个用 C++ 编写的 CGI,它接受带有查询字符串的 URI。查询字符串是选择页面等的内容。CGI 安装在 Ubuntu 安装的标准位置:

/usr/lib/cgi-bin/snapmanager.cgi

今天我完成了添加登录屏幕,一旦登录,我想添加一个注销链接。该链接只是添加了?logout在 URI 的末尾:
http://www.example.com/cgi-bin/snapmanager.cgi?logout

那失败了。

检查错误日志,我得到一个错误,说“注销”实际上出现在命令行上。如果你问我,相当令人惊讶!我试过:
http://www.example.com/cgi-bin/snapmanager.cgi?logout=now

一切都按预期工作。在命令行上没有注销。

我也试过:
http://www.example.com/cgi-bin/snapmanager.cgi?logout&host=foo

这也奏效了。同样,命令行上没有注销。

但是,如果我切换参数位置,它会再次失败:
http://www.example.com/cgi-bin/snapmanager.cgi?host=foo&logout

所以看起来 Apache2 使用 logout 调用我的 CGI当最后定义一个查询字符串名称时,查询字符串作为命令行上的参数。

以防万一,我尝试在名称的开头添加破折号,果然,它在我的日志中显示为命令行开关!
error:snapmanager.cgi: option --logout is not supported.

真的很吓人。如果您知道可以“按您的方式调整”的开关,这将是一个巨大的安全风险......

这在某处有记录吗?

最佳答案

我实际上在 RFC3875 中找到了答案在第 4.4 段中

4.4. The Script Command Line

Some systems support a method for supplying an array of strings to the CGI script. This is only used in the case of an 'indexed' HTTP query, which is identified by a 'GET' or 'HEAD' request with a URI query string that does not contain any unencoded "=" characters. For such a request, the server SHOULD treat the query-string as a search-string and parse it into words, using the rules

 search-string = search-word *( "+" search-word )
 search-word   = 1*schar
 schar         = unreserved | escaped | xreserved
 xreserved     = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "," |
                 "$"

After parsing, each search-word is URL-decoded, optionally encoded in a system-defined manner and then added to the command line argument list.

If the server cannot create any part of the argument list, then the server MUST NOT generate any command line information. For example, the number of arguments may be greater than operating system or server limits, or one of the words may not be representable as an argument.

The script SHOULD check to see if the QUERY_STRING value contains an unencoded "=" character, and SHOULD NOT use the command line arguments if it does.



重点矿

关于apache - 在调用 CGI 并且 URI 包含没有值的单个查询字符串参数时,Apache2 中是否存在特殊情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40481891/

相关文章:

apache - 将 React 应用程序部署到 Apache 服务器

php - 带有 Apache 和 MySQL mysqli_connect 的 Docker PHP 5.6.23 不是添加了扩展的函数

database - 无法连接到 ubuntu 上的 postgres

php - Ubuntu 18.04 : laravel/framework v6. 9.0 需要 ext-mbstring * -> 您的系统中缺少请求的 PHP 扩展 mbstring

shell - qdel是否会全部删除其他用户的作业?

linux - 如何在这里实现设置 ssh 隧道到端口...?

python - 类型 'exceptions.AttributeError' : 'list' object has no attribute 'value'

apache - 如何限制/控制 Apache Jmeter 中的采样率?

java - 从 Android 应用程序与服务器通信时出现各种 HTTPs 错误

linux - 无法使用 Apache 通过 SSH 连接服务器