Found in chiark:/info
[userv-utils] / www-cgi / user-cgi.text
CommitLineData
9a7d9296 1Users can now arrange to have CGI scripts run by chiark's webserver.
2This is achieved using userv (see /info/new 183, /usr/doc/userv and
3<URL:http://www.chiark.greenend.org.uk/~ian/userv/>).
4
5Before you write such scripts you should be aware of the security
6issues involved. Please read /info/cgi-security.text !
7
8Note that public-cgi programs (and their source code) should be world
9readable, and in any case by creating them you give me implicit
10permission to read its contents, using my system privilege if
11necessary, without notifying you. See cgi-security.text for full
12details of the policy.
13
14Paths in chiark's http space of the form
15 /ucgi/~<username>/<path-to-script>/<extra-stuff>...
16will be taken to refer to the CGI script
17 ~<username>/public-cgi/<path-to-script>
18and /<extra-stuff> will be used as the PATH_INFO (as is
19conventional). For example,
20 http://www.chiark.greenend.org.uk/ucgi/~ijackson/spong/foo?bar=baz
21will run ~ijackson/public-cgi/spong with PATH_INFO set to `/foo' and
22QUERY_STRING set to `bar=baz'.
23
24You can debug your scripts by using
25 /ucgi-debug/~<username>/<path-to-script>...
26which will return a text/plain document consisting of the standard
27output and standard error of your script and a line at the bottom with
28the high and low bytes of the script's exit status.
29
30Also both of
31 http://www.chiark.greenend.org.uk/ucgicgi/check
32 http://www.chiark.greenend.org.uk/ucgi/~ijackson/check
33are scripts which will dump their arguments and environment as a
34text/plain output file. This can be used to see what input your CGI
35program ought to expect.
36
37The default configuration does not enable userv's `set-environment'
38feature, so the environment your scripts in will be rather minimal.
39You can change this it if you want by saying something like
40 if glob service www-cgi
41 set-environment
42 fi
43in your ~/.userv/rc file. This will cause your scripts to be run by a
44shell which has sourced your ~/.environment file, if it exists. See
45the userv documentation for details, and look in /etc/environment.
46
47CGI programs will be run in your account. They will be able to access
48files exactly as if you had run them yourself directly. Their PATH
49and other similar variables will be set correctly (see below) and can
50and should be trusted.
51
52However, their arguments, input and webserver-provided environment
53variables (the full list is in /usr/local/src/davenant/ucgicommon.c)
54will have come from the client WWW browser and are highly
55untrustworthy. This means you must be very careful when writing such
56programs. Beware particularly of
57 * buffer overruns in C
58 * trusting data not to have metacharacters.
59 You should generally not pass client-provided data to
60 - eval (Perl or shell)
61 - system (Perl or C) and exec (Perl)
62 - open (Perl) and popen (C)
63 - anything similar.
64
65Safely using untrusted client-provided data in shell scripts is very
66difficult. I would recommend against programming CGI scripts in
67shell. If you must, make sure you use appropriate quoting and
68argument unparsing everywhere.
69
70The invocation of user-provided CGI scripts is achieved by using userv
71to invoke the `www-cgi' service. The webserver-provided environment
72variables will be passed as userv parameters using
73-DE_<variable>=<value>. The E_PATH_INFO parameter contains the
74portion of the path beyond the username.
75
76The default configuration (/etc/userv/system.default) arranges for
77www-cgi to run /usr/local/lib/user-cgi/target, which removes the
78USERV_E_ from the start of the webserver-provided environment
79variables and adjusts some of them for the script's actual location
80and the calls the actual script. `target' takes one parameter, the
81location of the user's public CGI directory relative to their home
82directory (`public-cgi' in the default configuration). It must be a
83relative path.
84
85You can run your own scripts from the command line by saying
86 userv -DE_PATH_INFO=/<script>[/<path-info>] \
87 -DE_QUERY_STRING=<query> --spoof-user www - www-cgi \
88 [<arg-for-isindex-query>]
89
90CGI programs' path components may not be empty, may not start with a
91full stop `.', and may not end with a hash `#' or tilde `~'.
92
93Please report problems to webmaster@chiark or sysadmin@chiark.
94Comments on userv should go to userv-maint@chiark.greenend.org.uk.
95
96 - Ian Jackson 14.07.1998