apachecgi-bin

cgi-bin is duplicated when form action is called


I have a website on ipage and works fine. I am trying to migrate it to Google Cloud and the cgi-bin is duplicated when called by a form action as shown below:

http://34.28.183.10/cgi-bin/cgi-bin/list_directory_1.cgi?directory=%2CBrasil%2CMinas+Gerais&submit_trailing_directory=

It works if I remove the extra cgi-bin such as:

http://34.28.183.10/cgi-bin/list_directory_1.cgi?directory=%2CBrasil%2CMinas+Gerais&submit_trailing_directory=

I placed the script list_directory_1.cgi in /usr/lib/cgi-bin and the form whose action calls this script looks like this:

print qq(<form action="cgi-bin/list_directory_1.cgi" method="GET">\n);

The apache2 log files shows this:

[Thu Mar 16 14:39:49.939253 2023] [cgid:error] [pid 5389:tid 140165141997312] [client 107.217.8.189:52312] AH01264: script not found or unable to stat: /usr/lib/cgi-bin/cgi-bin, referer: http://34.28.183.10/cgi-bin/list_directory_1.cgi?directory=%2CBrasil&submit_directory=


Solution

  • A URL that starts with a relative path (like cgi-bin/list_directory_1.cgi) is resolved by:

    1. Taking the base URL (http://34.28.183.10/cgi-bin/list_directory_1.cgi?directory=%2CBrasil&submit_directory=)
    2. Removing everything after the last / in the path (http://34.28.183.10/cgi-bin/)
    3. Appending the relative path (http://34.28.183.10/cgi-bin/cgi-bin/list_directory_1.cgi)

    Use an absolute path (starting with a single /) instead:

    <form action="/cgi-bin/list_directory_1.cgi"
    

    These are resolved by:

    1. Taking the base URL (http://34.28.183.10/cgi-bin/list_directory_1.cgi?directory=%2CBrasil&submit_directory=)
    2. Removing everything after and including the whole path (http://34.28.183.10)
    3. Appending the absolute path (http://34.28.183.10/cgi-bin/list_directory_1.cgi)