[Top] [Prev] [Next] [Last]
Download PDF:   US   UK
Download Postscript:   US   UK
Stronghold Web Server 2.4 Administration Guide

Chapter 10

Common Gateway Interface

The Common Gateway Interface (CGI) is a language-independent gateway between a Web server and other programs on the same platform. CGI can invoke executables on your platform and pass variables to it, then return the output to the client. This chapter discusses CGI topics, including

CGI gives you the flexibility to write your Web applications in C, Perl, Java, Python, ksh, tsh, csh, or any other UNIX programming language. It can execute either a binary program or a script (assuming you have an appropriate interpreter). Both binaries and scripts behave identically in the CGI environment, and for the purposes of this chapter we will refer to both as programs.

As of Stronghold 2.4, CGI buffers are flushed whenever they contain data and Stronghold is waiting for more output from the program, allowing clients to receive partial responses while the program is finishing. Previous versions withheld the data until either the buffers were full or the program completed.




Environment Variables

Environment variables provide input for CGI programs. The value of an environment variable can depend on the server, the server platform, the state of the system, the date or time, or HTML form input. environment variables can be set in several ways:

For more information about server configuration directives that set environment variables, see "Environment Variables" on page 7-17. This section provides information about environment variables commonly associated with Stronghold and other Web server software.



Server Variables

These variables pertain to the server software and its current configuration.



SERVER_SOFTWARE



GATEWAY_INTERFACE



SERVER_ADMIN



SERVER_ROOT



DOCUMENT_ROOT



Client Request Variables

These variables are derived from the HTTP headers of client requests. Their values vary with the client software and the nature of the request.



UNIQUE_ID



SERVER_NAME



HTTP_HOST



HTTP_ACCEPT



HTTP_COOKIE



HTTP_USER_AGENT



SERVER_PORT



REMOTE_HOST



REMOTE_PORT



REMOTE_ADDR



REMOTE_USER



REMOTE_IDENT



SERVER_PROTOCOL



REQUEST_METHOD



AUTH_TYPE



CONTENT_TYPE



CONTENT_LENGTH



SCRIPT_NAME



SCRIPT_FILENAME



SCRIPT_URI



SCRIPT_URL



QUERY_STRING



PATH_INFO



PATH_TRANSLATED



SSL/TLS Protocol Variables

These variables are specific to SSL and TLS.



SSL_PROTOCOL_VERSION



SSLEAY_VERSION



HTTPS



HTTPS_SECRETKEYSIZE



HTTPS_KEYSIZE



HTTPS_CIPHER



HTTPS_EXPORT



SSL_SERVER_SESSIONDIR



SSL_SERVER_CERTIFICATELOGDIR



SSL_CIPHER



SSL/TLS Server Variables



SSL_SERVER_CERTFILE



SSL_SERVER_KEYFILE



SSL_SERVER_KEYFILETYPE



SSL_SERVER_KEY_SIZE



SSL_SERVER_KEY_ALGORITHM



SSL_SERVER_KEY_EXP



SSL_SERVER_CERTIFICATE



SSL_SERVER_CERT_START



SSL_SERVER_CERT_END



SSL_SERVER_EMAIL



SSL_SERVER_O



SSL_SERVER_C



SSL_SERVER_SP



SSL_SERVER_L



SSL_SERVER_SIGNATURE_ALGORITHM



SSL_SERVER_IO



SSL_SERVER_IOU



SSL_SERVER_IEMAIL



SSL_SERVER_ICN



SSL_SERVER_IL



SSL_SERVER_ISP



SSL_SERVER_IC



SSL/TLS Client Variables



SSL_CLIENT_KEY_ALGORITHM



SSL_CLIENT_KEY_SIZE



SSL_CLIENT_KEY_EXP



SSL_CLIENT_CERTIFICATE



SSL_CLIENT_CN



SSL_CLIENT_EMAIL



SSL_CLIENT_OU



SSL_CLIENT_C



SSL_CLIENT_SP



SSL_CLIENT_L



SSL_CLIENT_CERT_START



SSL_CLIENT_CERT_END



SSL_CLIENT_O



SSL_CLIENT_IO



SSL_CLIENT_IOU



SSL_CLIENT_IEMAIL



SSL_CLIENT_IC



SSL_CLIENT_IL



SSL_CLIENT_ICN



SSL_CLIENT_ISP



SSL_CLIENT_SIGNATURE_ALGORITHM




CGI Error Logging

For debugging purposes, the CGI module logs standard error data if the ScriptLog directive is set. Each error entry begins with two lines with this format:

%% [time] request-line
%% HTTP-status-code CGI-script-filename

These lines are followed by more specific error information, depending on the nature of the error. If CGI cannot start the script at all, the body of the error entry looks like this:

%%error
error-message

If the script returns incorrect header information, the body of the error entry looks like this:

%request
request-header(s) received by the script
%response
response-header(s) output by the script
%stdout
CGI-standard-output
%stderr
CGI-standard-error

If the script does not output anything on stdout or stderr, those fields may be empty.




CGI Security

Two characteristics of CGI pose security issues for your server:

Since CGI executes programs at the request of users, intruders can arbitrarily invoke programs that can directly influence your platform. By manipulating the input, a clever hacker can turn a benign program into a tool that threatens the integrity of your log files, user accounts, or programs. By bypassing the HTML interface to a CGI program, an intruder avoids its constraints and can freely enter manipulative data or view "hidden" data fields.



Authoring Tips

This section offers some authoring tips that can help you avoid potential security weaknesses on your system:



suEXEC

Stronghold can run CGI programs under user IDs (UIDs) other than its own. For example, if your site hosts a number of users, some of whom have their own CGI programs, Stronghold can execute these under the UIDs of their owners. The suEXEC CGI wrapper provides this functionality.

When CGI programs are confined to the UIDs of their owners, weaknesses cannot be exploited outside the realm of that user's directories and files. In addition, the suEXEC wrapper uses these rules for added security:

These rules shore up many of the security weaknesses that CGI normally poses.

This is an advanced feature; use it with caution. If you configure it improperly, suEXEC can severely compromise the security of your site. However, if you are familiar with setuid programs and their security issues, and you configure suEXEC properly, it reinforces your site's security considerably.



To compile Stronghold with suEXEC

  1. Edit ServerRoot/src/support/suexec.h so that the following macros match your server configuration:

  2. Compile suEXEC:

    # gcc suexec.c -o suexec

  3. Add the following line to the Makefile Configuration section of ServerRoot/src/Configuration:

    EXTRA_FLAGS= -DSUEXEC_BIN="/path/to/suexec"

  4. Recompile Stronghold according to the instructions in "Recompiling Stronghold" on page 8-9.

  5. Move the suEXEC executable you created in step 2 to the location specified in step 3.

  6. Set the setuid bit:

    # chown root suexec
    # chmod 4711 suexec

  7. Start Stronghold.

    On startup, the server should print the following line:

    Configuring Apache for use with suexec wrapper.

    Stronghold can now implement suEXEC. However, if this line does not appear, suEXEC is incorrectly configured.

With suEXEC in place, Stronghold sets the UID of each CGI program to that of the user directory in which the program resides. For CGI programs that belong to a virtual host, use the User and Group directives to set the UID for that host's CGI programs.






[Top] [Prev] [Next] [Last]
© 1998 C2Net International
Feedback: [email protected]
C2Net Logo