Web Publishing Using HTTP PUT
Introduction
Besides specifying the well-known GET and POST methods familiar to CGI programmers on the World Wide Web, the HTTP specification also describes the lesser-known PUT method, useful for uploading files to the web server from PUT-capable HTML editors such as Netscape Navigator Gold (http://www.netscape.com) or AOLpress (http://www.aolpress.com). When used properly, the HTTP PUT method provides a useful alternative to FTP uploading and is easily integrated into the robust Apache web server by means of a special CGI program.
How to Use PUT
Installation
Log in to your virtual server in a telnet session.
Update your web server to the most recent version of Apache available by typing
% updateapache
at the server prompt.
Install the PUT CGI distribution on the virtual server by typing
% cd ~ % tar xvf /usr/local/contrib/put.tar
while in your home directory.
Configuration
Decide what directories on the virtual server you wish to make available for PUT publishing. For each directory hierarchy, add a configuration block to your ~/www/conf/ access. conf file similar to the following:
<Directory $PATH> AllowOverride None <Limit PUT> order allow, deny allow from all </Limit> </Directory>
where "$PATH" is replaced with the directory name under your home directory. As an example, if your PUT publishers need to upload to directories under ~/www/htdocs, use "/www/htdocs" for "$PATH" in the configuration block listed above. Exercise caution when allowing overrides, since this may lead to security holes in environments involving multiple content authors by allowing end users to run untrusted CGI scripts.
Now, enable Apache to recognize the HTTP PUT method. Add the following lines to ~/www/conf/srm.conf:
ScriptAlias /auth-cgi-bin /www/ auth-cgi-bin Script PUT /auth-cgi-bin/ put
The PUT CGI relies on the $REMOTE_USER CGI environment variable for authenti-cation purposes, so the CGI needs to reside in a directory protected by HTTP password authentication. The easiest way to provide this is by protecting the ~/www/auth-cgi-bin directory with a .htaccess file. To do so, place a .htaccess file in ~/www/auth-cgi-bin containing the following:
AuthUserFile /etc/passwd AuthGroupFile /dev/null AuthName PUT METHOD UPLOAD AuthType Basic <Limit PUT> order allow, deny allow from all require user $USER </Limit>
where "$USER" is the login name of a PUT author on your virtual server. Additional login names should be added to the end of the "require" line (separated by spaces) as needed. An alternate approach to using "require user" would be to use "require group" (with a valid "AuthGroupFile" directive) or to use "require valid-user" to enable all users that can successfully log in.
Examples
In a virtual server environment where a single trusted author will be developing all web site content the Apache configuration files might resemble the following:
Added to ~/www/conf/access.conf:
<Directory /www/htdocs> AllowOverride All <Limit PUT> order allow, deny allow from all </Limit> </Directory>
Added to ~/www/conf/srm.conf:
ScriptAlias /auth-cgi-bin/www/auth-cgi-bin Script PUT /auth-cgi-bin/put
In ~/www/auth-cgi-bin/.htaccess:
AuthUserFile /etc/passwd AuthGroupFile /dev/null AuthName PUT METHOD UPLOAD AuthType Basic <Limit PUT> order allow, deny allow from all require user fred </Limit>
Notice here that the access. conf file has enabled configuration overrides on a per-directory basis under ~/www/htdocs. PUT uploading is enabled only for a user named "fred" whose password information can be found in ~/etc/passwd (the virtual server password file). In ~/etc/passwd the home directory for user "fred" should be /usr/local/etc/httpd/htdocs, since the PUT method CGI will restrict uploads to Fred's home directory or a subdirectory thereof. Since user "fred" has the ability to enable CGI scripting under ~/www/htdocs and is able to make other access modifications (such as creating password-protected web pages) by virtue of the "AllowOverride All" directive, it is important that you be able to trust Fred and his actions. Be very careful about enabling configuration overrides! Failure to understand the security ramifications of this important web server configuration issue can create very serious security holes on your virtual server. When in doubt, opt for a "denied unless allowed" security policy instead of an "allowed unless denied" policy.
Now suppose instead that you have three users --"ernie", "bert", and "oscar" --that would like to use HTTP PUT to upload their web pages. Assume that the home directory in ~/etc/passwd for each user is a directory under /usr/local/etc/httpd/htdocs named after the user, namely /usr/local/etc/httpd/htdocs/ernie, /usr/local/etc/httpd/htdocs/bert, and /usr/local/etc/httpd/htdocs/oscar. For the sake of this example, assume that Ernie, Bert, and Oscar are untrusted users. Each should be able to upload files under their respective directories, but access control and configuration modification privileges should be denied. The web server files for this example might resemble the following:
Added to ~/ www/ conf/ access. conf:
<Directory /www/htdocs/ernie> AllowOverride None <Limit PUT> order allow, deny allow from all </Limit> </Directory> <Directory /www/htdocs/bert> AllowOverride None <Limit PUT> order allow, deny allow from all </Limit> </Directory> <Directory /www/htdocs/oscar> AllowOverride None <Limit PUT> order allow, deny allow from all </Limit> </Directory>
Added to ~/www/conf/srm.conf:
ScriptAlias /auth-cgi-bin/www/auth-cgi-bin Script PUT /auth-cgi-bin/put
In ~/www/auth-cgi-bin/.htaccess:
AuthUserFile /www/auth-cgi-bin/.htpasswd AuthGroupFile /dev/null AuthName PUT METHOD UPLOAD AuthType Basic <Limit PUT> order allow, deny allow from all require user ernie bert oscar </Limit>
This example demonstrates that the password information for these users can reside in a file other than ~/etc/passwd. In this case, the username and password information is stored in ~/www/auth-cgi-bin/.htpasswd, thus allowing these users to have different passwords for FTP/ POP services (stored in ~/etc/passwd) and for PUT uploading (stored here in ~/www/auth-cgi-bin/.htpasswd). The ~/www/auth-cgi-bin/.htpasswd file is created with the "htpasswd" command, as follows:
% htpasswd -c ~/ www/ auth-cgi-bin/. htpasswd ernie Adding password for ernie. New password: <--type "chickens" Re-type new password: <--type "chickens" % htpasswd ~/www/auth-cgi-bin/.htpasswd bert Adding user bert New password: <--type "pigeons" Re-type new password: <--type "pigeons" % htpasswd ~/ www/ auth-cgi-bin/. htpasswd oscar Adding user oscar New password: <--type "trashcan" Re-type new password: <--type "trashcan" %
where Ernie's password is "chickens", Bert's password is "pigeons", and Oscar's password is "trashcan". Typing "htpasswd" by itself on a command line prints a help message:
% htpasswd Usage: htpasswd [-c] passwordfile username The -c flag creates a new file. %
When finished, the ~/www/auth-cgi-bin/.htpasswd file resembles:
ernie: 3nfbAgvhlAQkA bert: xP/ OZpc77c3iE oscar: gKdDCb7EMFUaM
containing username and DES password pairs separated by a colon.
Additional References
More information about configuring Apache to use the HTTP PUT method and using the PUT method and HTTP in general can be found at the following URLs:
http://www.apacheweek.com/features/put
http://www.mat.uni.torun.pl/~aztoruns/doc/apache-put.html
http://www.w3.org:80/Amaya/User/Put.html
http://www.w3.org:80/Protocols/