2

Users paste in over 100 separate number strings into a text box to submit for query. The front end web server is an Ubuntu 18.04 LTS server with Apache 2.4.29 and Php 7.2.19. When submitted, the data goes over the Post query string (not at all ideal) to the backend web server running Apache 2.0.63 The backend Apache server has C code CGI which uses the data for queries.

The frontend Apache server used to be a physical machine running Ubuntu 7.1, PHP 5.2 and Apache 2.2. It's now a fully rebuilt system on VMware ESXi 6.7. The backend server remained unchanged.

The problem is that this terribly long query string used to be posted completely without truncation. On the new frontend system, it is truncated to 790 characters.

What could cause this truncation?

Wireshark on the sending Apache server shows the full untruncated string. The access log on the receiving Apache server shows the full untruncated string. However, the error log on the receiving Apache server shows:

Truncating symbol QUERY_STRING value: followed by the full string, except there is A PIPE SYMBOL | right after 790 CHARACTERS. Why is this?

The backend server's CGI code has had print statements entered to show the string and what was output was the truncated, 790 character string. The I've set LimitRequestLine and LimitRequestFieldSize in apache2.conf on both the sending and receiving Apache servers to 8190. Php Max_Post_size is set to 1024M in php.ini.

This is the PHP code:

<?php
header("content-type: application/xml");
if ($_POST) {
                $params = "";
                $parameter = 0;
                foreach ($_POST as $key => $value) {
                                $parameter++;
                                switch ($parameter) {
                                                case 1:
                                                                $params = $value;
                                                                break;
                                                case 2:
                                                                $params = $params."?".$key."=".urlencode($value);
                                                                break;
                                                default:
                                                                $params = $params."&".$key."=".urlencode($value);
                                                                break;
                                }
                }
} else {
                $params = $_SERVER["QUERY_STRING"];
}
$request = "http://192.168.xxxxxxx/cgi-bin/".$params;
$result = @join (@file($request), "");
$result = str_replace(array("\n", "\r"), "", $result);
echo $result;
?>

Here is the C code on the backend server. I'm quoting someone who handles that code:

It is just grabs the pointer from where query string is located and passes it to the C code character pointer. Then gets its length. Does not need a buffer setup in C.
So the string length is 970.

char *buf;

long buflen;

buf = getenv("QUERY_STRING");

buflen = (long)strlen(buf);

The encoded string is truncated right at 790 characters as seen by the CGI program after each post. Would this be due to the change in Apache versions, PHP versions, mismatch of Apache from frontend to backend or something else?

  • Possible duplicate of [What is the size limit of a post request?](https://stackoverflow.com/questions/2364840/what-is-the-size-limit-of-a-post-request) There is a limit at the PHP level as well, check that, maybe? – Nic3500 Jul 07 '19 at 23:25
  • I've changed my question title and the description of the problem. – Immersed512 Jul 08 '19 at 19:10

0 Answers0