[Top] [Prev] [Next] [Last]
|
|
Chapter 10Common Gateway Interface
Environment Variables
- Some environment variables are set by the system or in run command files.
- Environment variables corresponding to HTTP metainformation can be set by CGI programs on the basis of HTTP request headers sent by the client.
- Variables can be set on a per-object basis using the PassEnv and SetEnv directives.
- Variables can be set conditionally, based on any request criteria, using the SetEnvIf and SetEnvIfNoCase directives.
- The special environment variable UNIQUE_ID is set by mod_unique_id, which assigns a unique identifier to every request.
- Variables can be set by CGI programs themselves.
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
- Syntax: SERVER_SOFTWARE=Stronghold/2.4 Apache/1.3
- Context: server
The name and version number of the server software, including its Apache core
GATEWAY_INTERFACE
- Syntax: GATEWAY_INTERFACE=CGI/1.1
- Context: server
SERVER_ADMIN
- Syntax: SERVER_ADMIN=email-address
- Context: server
The server administrator's email address or other information, from httpd.conf
SERVER_ROOT
- Syntax: SERVER_ROOT=path
- Context: server
DOCUMENT_ROOT
- Syntax: DOCUMENT_ROOT=path
- Context: server
Client Request Variables
UNIQUE_ID
- Syntax: UNIQUE_ID IP, PID, time_stamp, counter
- Context: client request
SERVER_NAME
- Syntax: SERVER_NAME=host
- Context: client request
HTTP_HOST
- Syntax: HTTP_HOST=host
- Context: client request
HTTP_ACCEPT
- Syntax: HTTP_ACCEPT=MIME-type[, MIME-type, MIME-type . . . ]
- Context: client request
HTTP_COOKIE
- Syntax: HTTP_COOKIE=cookie
- Context: client request
The cookie presented in the Cookie header of the client request, if any.
HTTP_USER_AGENT
- Syntax: HTTP_USER_AGENT=name/version (platform)
- Context: client request
The name, version number, and platform of the client software
SERVER_PORT
- Syntax: SERVER_PORT=port
- Context: client request
REMOTE_HOST
- Syntax: REMOTE_HOST=host
- Context: client request
The hostname or IP number of the client host or proxy server that originated the request
NOTE: This is only set if Stronghold is not compiled with MINIMAL_DNS, or if HostnameLookups is set to "off."
REMOTE_PORT
- Syntax: REMOTE_PORT=port
- Context: client request
REMOTE_ADDR
- Syntax: REMOTE_ADDR=IP
- Context: client request
REMOTE_USER
- Syntax: REMOTE_USER=username
- Context: client request
The remote username, if the script is subject to basic authentication
REMOTE_IDENT
- Syntax: REMOTE_IDENT=ident
- Context: client request
The remote username as supplied by identd, if available
NOTE: This is only set if IdentityCheck is set to "on."
SERVER_PROTOCOL
- Syntax: SERVER_PROTOCOL=protocol/version
- Context: client request
REQUEST_METHOD
- Syntax: REQUEST_METHOD=method
- Context: client request
AUTH_TYPE
- Syntax: AUTH_TYPE=method
- Context: client request
CONTENT_TYPE
- Syntax: CONTENT_TYPE=MIME-type
- Context: client request
CONTENT_LENGTH
- Syntax: CONTENT_LENGTH=n
- Context: client request
The size, in bytes, of any data attached to the request header
SCRIPT_NAME
- Syntax: SCRIPT_NAME=path/to/script
- Context: client request
SCRIPT_FILENAME
- Syntax: SCRIPT_FILENAME=absolute/path/to/script
- Context: client request
SCRIPT_URI
- Syntax: SCRIPT_URI=method://host/path/to/script
- Context: client request
SCRIPT_URL
- Syntax: SCRIPT_URL=path/to/script
- Context: client request
QUERY_STRING
- Syntax: QUERY_STRING=string
- Context: client request
The query-string for this transaction, embedded in the requested URL
PATH_INFO
- Syntax: PATH_INFO=info
- Context: client request
Extra path information submitted in the request URL and used as input to a CGI program
PATH_TRANSLATED
- Syntax: PATH_TRANSLATED=path
- Context: client request
The absolute path of the requested file, if the value of PATH_INFO can be translated to a file
SSL/TLS Protocol Variables
These variables are specific to SSL and TLS.
SSL_PROTOCOL_VERSION
- Syntax: SSL_PROTOCOL_VERSION=2|3
- Context: SSL/TLS
The version of SSL/TLS used in this transaction, either TLS version 1 or SSL version 2 or 3
SSLEAY_VERSION
- Syntax: SSLEAY_VERSION=n
- Context: SSL/TLS
HTTPS
- Syntax: HTTPS=on|off
- Context: SSL/TLS
HTTPS_SECRETKEYSIZE
- Syntax: HTTPS_SECRETKEYSIZE=n
- Context: SSL/TLS
HTTPS_KEYSIZE
- Syntax: HTTPS_KEYSIZE=n
- Context: SSL/TLS
The full size, in bytes, of the server's public key
NOTE: This is different from HTTPS_SECRETKEYSIZE only if you are using an export-crippled cryptography scheme.
HTTPS_CIPHER
- Syntax: HTTPS_CIPHER=cipher
- Context: SSL/TLS
HTTPS_EXPORT
- Syntax: HTTPS_EXPORT=true|false
- Context: SSL/TLS
SSL_SERVER_SESSIONDIR
- Syntax: SSL_SERVER_SESSIONDIR=path
- Context: SSL/TLS
SSL_SERVER_CERTIFICATELOGDIR
- Syntax: SSL_SERVER_CERTIFICATELOGDIR=path
- Context: SSL/TLS
SSL_CIPHER
- Syntax: SSL_CIPHER=cipher
- Context: SSL/TLS
SSL/TLS Server Variables
SSL_SERVER_CERTFILE
- Syntax: SSL_SERVER_CERTFILE=filename
- Context: SSL/TLS server
SSL_SERVER_KEYFILE
- Syntax: SSL_SERVER_KEYFILE=filename
- Context: SSL/TLS server
SSL_SERVER_KEYFILETYPE
- Syntax: SSL_SERVER_KEYFILETYPE=PEM
- Context: SSL/TLS server
The format of the server's public key file; only PEM is supported
SSL_SERVER_KEY_SIZE
- Syntax: SSL_SERVER_KEY_SIZE=n
- Context: SSL/TLS server
SSL_SERVER_KEY_ALGORITHM
- Syntax: SSL_SERVER_KEY_ALGORITHM=algorithm
- Context: SSL/TLS server
SSL_SERVER_KEY_EXP
- Syntax: SSL_SERVER_KEY_EXP=expiry-time
- Context: SSL/TLS server
The expiration date of the server's public key, in ASN1 format
SSL_SERVER_CERTIFICATE
- Syntax: SSL_SERVER_CERTIFICATE=hash
- Context: SSL/TLS server
SSL_SERVER_CERT_START
- Syntax: SSL_SERVER_CERT_START=date
- Context: SSL/TLS server
The date on which the server certificate becomes valid, in ASN1 format
SSL_SERVER_CERT_END
- Syntax: SSL_SERVER_CERT_END=date
- Context: SSL/TLS server
SSL_SERVER_EMAIL
- Syntax: SSL_SERVER_EMAIL=email-address
- Context: SSL/TLS server
SSL_SERVER_O
- Syntax: SSL_SERVER_O=organization
- Context: SSL/TLS server
The name of the organization to which the server certificate belongs
SSL_SERVER_C
- Syntax: SSL_SERVER_C=country-code
- Context: SSL/TLS server
The two-character code for the country in which the server resides; valid country codes are listed in Appendix C
SSL_SERVER_SP
- Syntax: SSL_SERVER_SP=state|province
- Context: SSL/TLS server
SSL_SERVER_L
- Syntax: SSL_SERVER_L=locality
- Context: SSL/TLS server
The locality, such as a town or city, in which the server resides
SSL_SERVER_SIGNATURE_ALGORITHM
- Syntax: SSL_SERVER_SIGNATURE_ALGORITHM=algorithm
- Context: SSL/TLS server
SSL_SERVER_IO
- Syntax: SSL_SERVER_IO=CA
- Context: SSL/TLS server
SSL_SERVER_IOU
- Syntax: SSL_SERVER_IOU=organizational-unit
- Context: SSL server
SSL_SERVER_IEMAIL
- Syntax: SSL_SERVER_IEMAIL=email-address
- Context: SSL/TLS server
Issuer Email, the contact email address of the CA that signed the server certificate
SSL_SERVER_ICN
- Syntax: SSL_SERVER_ICN=hostname
- Context: SSL/TLS server
Issuer Common Name, the hostname of the CA that issued the server certificate
SSL_SERVER_IL
- Syntax: SSL_SERVER_IL=locality
- Context: SSL/TLS server
Issuer Locality, the locality of the CA that issued the server certificate
SSL_SERVER_ISP
- Syntax: SSL_SERVER_ISP=state|province
- Context: SSL/TLS server
Issuer State/Province, the state or province of the CA that issued the server certificate
SSL_SERVER_IC
- Syntax: SSL_SERVER_IC=country-code
- Context: SSL/TLS server
Issuer Country, the two-character code for the country in which the CA that issued the server certificate resides; valid country codes are listed in Appendix C
SSL/TLS Client Variables
SSL_CLIENT_KEY_ALGORITHM
- Syntax: SSL_CLIENT_KEY_ALGORITHM=algorithm
- Context: SSL/TLS client
SSL_CLIENT_KEY_SIZE
- Syntax: SSL_CLIENT_KEY_SIZE=n
- Context: SSL/TLS client
SSL_CLIENT_KEY_EXP
- Syntax: SSL_CLIENT_KEY_EXP=expiry-time
- Context: SSL/TLS client
SSL_CLIENT_CERTIFICATE
- Syntax: SSL_CLIENT_CERTIFICATE=hash
- Context: SSL/TLS client
SSL_CLIENT_CN
- Syntax: SSL_CLIENT_CN=name
- Context: SSL/TLS client
SSL_CLIENT_EMAIL
- Syntax: SSL_CLIENT_EMAIL=email-address
- Context: SSL/TLS client
SSL_CLIENT_OU
- Syntax: SSL_CLIENT_OU=organizational-unit
- Context: SSL/TLS client
SSL_CLIENT_C
- Syntax: SSL_CLIENT_C=country-code
- Context: SSL/TLS client
The two-character code for the country in which the client resides; valid country codes are listed in Appendix C
SSL_CLIENT_SP
- Syntax: SSL_CLIENT_SP=state|province
- Context: SSL/TLS client
SSL_CLIENT_L
- Syntax: SSL_CLIENT_L=locality
- Context: SSL/TLS client
The locality, such as a city or town, in which the client resides
SSL_CLIENT_CERT_START
- Syntax: SSL_CLIENT_CERT_START=date
- Context: SSL/TLS client
The date on which the client's certificate becomes valid, in ASN1 format
SSL_CLIENT_CERT_END
- Syntax: SSL_CLIENT_CERT_END=date
- Context: SSL/TLS client
The date on which the client's certificate is no longer valid, in ASN1 format
SSL_CLIENT_O
- Syntax: SSL_CLIENT_O=organization
- Context: SSL/TLS client
SSL_CLIENT_IO
- Syntax: SSL_CLIENT_IO=CA
- Context: SSL/TLS client
SSL_CLIENT_IOU
- Syntax: SSL_CLIENT_IOU=organizational-unit
- Context: SSL/TLS client
The name of the organizational unit of the CA that issued the client certificate
SSL_CLIENT_IEMAIL
- Syntax: SSL_CLIENT_IEMAIL=email-address
- Context: SSL/TLS client
The contact email address of the CA that issued the client certificate
SSL_CLIENT_IC
- Syntax: SSL_CLIENT_IC=country-code
- Context: SSL/TLS client
The country in which the CA that issued the client certificate resides; valid country codes are listed in Appendix C
SSL_CLIENT_IL
- Syntax: SSL_CLIENT_IL=locality
- Context: SSL/TLS client
The locality, such as a city or town, of the CA that issued the client certificate
SSL_CLIENT_ICN
- Syntax: SSL_CLIENT_ICN=hostname
- Context: SSL/TLS client
SSL_CLIENT_ISP
- Syntax: SSL_CLIENT_ISP=state|province
- Context: SSL/TLS client
The state or province of the CA that issued the client certificate
SSL_CLIENT_SIGNATURE_ALGORITHM
- Syntax: SSL_CLIENT_SIGNATURE_ALGORITHM=algorithm
- Context: SSL/TLS client
CGI Error Logging
%% [time] request-line
%% HTTP-status-code CGI-script-filename
%%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:
- CGI executes programs on the server platform.
- Intruders can access CGI programs directly, bypassing any HTML interface.
Authoring Tips
- Exercise extreme caution when using system(), popen(), eval(), pipes, and backquotes.
- In all CGI programs, check the input for invalid values, such as selection list values not included in the original list, or values that exceed the length you specified in your HTML form.
- Reject variables whose names are not already defined in the program.
- Reject hidden fields that your program did not create.
- Reject unescaped control characters.
- If your program must spawn a child process, avoid passing user input to that process. If you must, be sure to filter out meta characters.
- If your program allows users to send mail, use /usr/lib/sendmail. Never use /bin/mailx or /usr/ucb/mail.
- If you allow users on your system to use their own CGI programs, screen them carefully before posting them to the CGI directory.
- Secure the CGI directory so that only an administrator can add, remove, or modify programs.
- Delete all backup files that your editor creates while you are authoring programs, and advise users on your system to do the same.
- Although "security through obscurity" is generally inadvisable, it is a very good idea where CGI programs are concerned. Do not allow users to read the CGI programs on your server platform, and do not allow anonymous FTP access to the CGI directory.
- Exercise caution when using CGI programs written by others. If you download a CGI program from a remote site, examine it carefully before implementing it on your own site.
suEXEC
- The UID of the current CGI program must be a valid user on your system.
- The UID of the current CGI program must be the HTTPD_USER.
- The command being executed must not contain a slash (/).
- The command being executed must reside in the DOC_ROOT.
- The current working directory must be an actual directory.
- The current working directory must not be writable by group or other.
- The command being executed must not be a symbolic link.
- The command being executed must not be writable by group or other.
- The command being executed must not be a setuid or setgid program.
- The target UID and group ID (GID) must be a valid user and group on your system.
- The target UID and GID must match the UID and GID of the current working directory.
- The target UID and GID must not be root.
These rules shore up many of the security weaknesses that CGI normally poses.
To compile Stronghold with suEXEC
- Edit ServerRoot/src/support/suexec.h so that the following macros match your server configuration:
- Compile suEXEC:
# gcc suexec.c -o suexec
- Add the following line to the Makefile Configuration section of ServerRoot/src/Configuration:
EXTRA_FLAGS= -DSUEXEC_BIN="/path/to/suexec"
- Recompile Stronghold according to the instructions in "Recompiling Stronghold" on page 8-9.
- Move the suEXEC executable you created in step 2 to the location specified in step 3.
- Set the setuid bit:
# chown root suexec
# chmod 4711 suexec
- Start Stronghold.
On startup, the server should print the following line:
Configuring Apache for use with suexec wrapper.
[Top] [Prev] [Next] [Last]
© 1998 C2Net International
Feedback: [email protected]![]()