[Top] [Prev] [Next] [Last]
|
|
Chapter 10Common Gateway Interface
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:
- HTTPD_USER
- LOG_EXEC
The path to the suEXEC error log file. Use a separate error file to isolate suEXEC errors.
- DOC_ROOT
- Compile suEXEC:
# gcc suexec.c -o suexec
- Add the following line to the Makefile Configuration section of ServerRoot/src/Configuration:
EXTRA_CFLAGS= -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
- Stop the old Stronghold process.
- Start Stronghold.
NOTE: Restarting does not allow Stronghold to recognize the suEXEC wrapper. It must be stopped and then started.
On startup, the server should print the following line:
Configuring Apache for use with suexec wrapper.
[Top] [Prev] [Next] [Last]
© 1998 C2Net International
Feedback: stronghold-docs@c2.net![]()