Safe Tcl
Safe-Tcl is a mechanism that initializes a Tcl interpreter to a safe subset of Tcl commands so that Tcl scripts cannot harm their hosting machine or application. There are also mechanisms to grant privileges to a safe interpreter so the script can do non-trivial things. The set of privileges granted to an untrusted script (i.e., a safe interpreter) is called a security policy.
At one extreme, a security policy can be so limited that an untrusted script can only compute a string. (Even still, an untrusted script might compute a very large string, or take a very long time to compute it. These attacks are considered later.) We are interested in granting non-trivial capabilities to untrusted scripts, such as the ability to display windows on the users screen, fetch URLs from a limited set, send email with limited content to a limited set of addresses, and so on.
The primary mechanism provided by Safe-Tcl to grant privileges is command aliases. An alias is a command in the untrusted interpreter that is really implemented by a different, fully trusted interpreter. This is much like the user-mode and kernel-modes in multiuser operating systems. In Safe-Tcl, an untrusted script is isolated in its interpreter context, and given a few extra commands that are carefully implemented by another Tcl intpreter to ensure safety.
When creating a security policy, there are a number of high-level principles to keep in mind.
open
or file
commands), or to put one or more special case
checks in the C code to take different actions if the current interpreter
is untrusted. However, the C-level approach scatters the implementation
of a particular security policy throughout the C code. This is error-prone
and difficult to analyze. In contrast, moving the policy into a set
of Tcl aliases, the security policy will be concentrated into one place.
It will be easier to analyze, fix errors, and distribute.
safe.tcl
script. Please examine this for flaws and report them to us.
Consider the Tcl file command. This has two sorts of operations. The first sort poke around in the file system. The second set of operations just manipulate file names. It can be argued that the ability to look around the file system is not safe, but it is safe to manipulate file names is safe. (e.g., get the extension of a file name). The basic approach to ensuring safety is to first completely remove the file command from safe interpreters (priniciple 2). It is replaced with a command alias (priniciple 4). The alias restricts what operations it will allow, implements the ones that are ok, and returns the results to the child. The implementation looks like this:
proc Interp_File {operation args} { switch -- $operation { extension - dirname - rootname - tail { return [file $operation [lindex $args 0]] } default { error "Unsupported file operation: $operation" } } } # Now create a safe interpreter and install the alias interp create -safe untrusted interp alias untrusted file {} Interp_File
The Interp_File
command is executed in a trusted interpreter.
It can use the regular file
command to do its work, once
it has determined that the untrusted has asked for a safe operation.
This is easy because there is no state hidden inside the untrusted
interpreter that is needed to implement the functionality.
The Netscape Tcl plugin supports Tcl/Tk applets, also called Tclets. The Tcl plugin implements the standard Safe-Tcl subset, plus a limited version of Tk. The following Tcl commands are removed from the Safe-Tcl interpreter used to run Tcl applets.
vwait
to wait
for variables to change.
image
create photo
command now takes a base64 encoded gif as a string
instead of reading from a file.
The safe.tcl
file in the tcl script library initializes
the safe interpreter. It creates several aliases that add features
on top of the base policy described above. These are manifest as command
aliases.
focus -force
can be used to screw around with the
keyboard focus.
lsort
commands crash Tcl on Solaris
and some other UNIX's.
This is the main Tcl Developer Xchange site,
www.tcl-lang.org .
About this Site |
[email protected]
Home |
About Tcl/Tk |
Software |
Core Development |
Community |
Documentation