Rename www-cgi to ucgi (in nearly all places)
[userv-utils] / ucgi / user-cgi.text
CommitLineData
a33962ba 1Users can arrange to have CGI scripts run by the webserver.
2This is achieved using userv (see
9a7d9296 3<URL:http://www.chiark.greenend.org.uk/~ian/userv/>).
4
5Before you write such scripts you should be aware of the security
a33962ba 6issues involved.
9a7d9296 7
a33962ba 8Paths in the http space of the form
9a7d9296 9 /ucgi/~<username>/<path-to-script>/<extra-stuff>...
10will be taken to refer to the CGI script
11 ~<username>/public-cgi/<path-to-script>
12and /<extra-stuff> will be used as the PATH_INFO (as is
13conventional). For example,
a33962ba 14 http://www.example.com/ucgi/~ijackson/spong/foo?bar=baz
9a7d9296 15will run ~ijackson/public-cgi/spong with PATH_INFO set to `/foo' and
16QUERY_STRING set to `bar=baz'.
17
18You can debug your scripts by using
19 /ucgi-debug/~<username>/<path-to-script>...
20which will return a text/plain document consisting of the standard
21output and standard error of your script and a line at the bottom with
22the high and low bytes of the script's exit status.
23
a33962ba 24Also, /usr/local/lib/user-cgi/cgi/check is a script which will dump
25its arguments and environment as a text/plain output file. This can
26be used to see what input your CGI program ought to expect.
9a7d9296 27
28The default configuration does not enable userv's `set-environment'
29feature, so the environment your scripts in will be rather minimal.
30You can change this it if you want by saying something like
31 if glob service www-cgi
32 set-environment
33 fi
34in your ~/.userv/rc file. This will cause your scripts to be run by a
35shell which has sourced your ~/.environment file, if it exists. See
36the userv documentation for details, and look in /etc/environment.
37
38CGI programs will be run in your account. They will be able to access
39files exactly as if you had run them yourself directly. Their PATH
40and other similar variables will be set correctly (see below) and can
41and should be trusted.
42
43However, their arguments, input and webserver-provided environment
a33962ba 44variables (the full list is in ucgicommon.c) will have come from the
45client WWW browser and are highly untrustworthy. This means you must
46be very careful when writing such programs. Beware particularly of
9a7d9296 47 * buffer overruns in C
48 * trusting data not to have metacharacters.
49 You should generally not pass client-provided data to
50 - eval (Perl or shell)
51 - system (Perl or C) and exec (Perl)
52 - open (Perl) and popen (C)
53 - anything similar.
54
55Safely using untrusted client-provided data in shell scripts is very
56difficult. I would recommend against programming CGI scripts in
57shell. If you must, make sure you use appropriate quoting and
a33962ba 58argument unparsing everywhere (and don't do it if you don't know what
59I mean by argument unparsing).
9a7d9296 60
61The invocation of user-provided CGI scripts is achieved by using userv
62to invoke the `www-cgi' service. The webserver-provided environment
63variables will be passed as userv parameters using
64-DE_<variable>=<value>. The E_PATH_INFO parameter contains the
65portion of the path beyond the username.
66
67The default configuration (/etc/userv/system.default) arranges for
68www-cgi to run /usr/local/lib/user-cgi/target, which removes the
69USERV_E_ from the start of the webserver-provided environment
70variables and adjusts some of them for the script's actual location
71and the calls the actual script. `target' takes one parameter, the
72location of the user's public CGI directory relative to their home
73directory (`public-cgi' in the default configuration). It must be a
74relative path.
75
76You can run your own scripts from the command line by saying
77 userv -DE_PATH_INFO=/<script>[/<path-info>] \
78 -DE_QUERY_STRING=<query> --spoof-user www - www-cgi \
79 [<arg-for-isindex-query>]
80
81CGI programs' path components may not be empty, may not start with a
82full stop `.', and may not end with a hash `#' or tilde `~'.
83
a33962ba 84It is important that the webserver removes /../ components from the
85PATH_INFO - if it doesn't there is a security hole.
86
87
9028e234
IJ
88userv-utils are
89Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
90Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
91Copyright 1999,2003
92 Chancellor Masters and Scholars of the University of Cambridge
93Copyright 2010 Tony Finch <fanf@dotat.at>
94
95All the utilities here are free software; you can redistribute it and/or
96modify it under the terms of the GNU General Public License as published by
97the Free Software Foundation; either version 3 of the License, or (at your
98option) any later version.
a33962ba 99
100This program is distributed in the hope that it will be useful, but
101WITHOUT ANY WARRANTY; without even the implied warranty of
102MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
103General Public License for more details.
104
105You should have received a copy of the GNU General Public License
9028e234 106along with userv-utils; if not, see http://www.gnu.org/licenses/.