Tcl HomeTcl Home Hosted by
ActiveState

Google SiteSearch

Safe Tcl

(This page needs to be updated with the newest version 2 and 3 features)

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.

Security Principles

When creating a security policy, there are a number of high-level principles to keep in mind.

  1. Safe-Tcl supports multiple policies. We expect there to be a family of security policies used with Safe-Tcl. There will be a "base policy" that you get by default. Additional policies provide non-trivial functionality to applets that is still safe, to some degree. System designers will appreciate a choice among security policies; one size does not fit all.
  2. Lean towards security and away from features. The mechanisms of Safe-Tcl let us construct any policy. It is better to proceed cautiously and implement policies that tend to be more restrictive as opposed to dumping in features. The more features that are added, the more difficult it is to maintain security. Or, the easier it is to break security.
  3. Whatever your policy, document it well. Each security policy should carefully document the capabilities that it provides. Known weaknesses are especially important to document. All this information is important to applet designers, and to system administrators. The former want to work around problems. The later need to judge the safety of using your policy.
  4. Implement policies in Tcl, not C. The preferred method to providing security is to completely remove unsafe commands and replace them with aliases implemented in Tcl. It is also possible to provide two versions of the C implementation of a command (e.g., the 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.
  5. The Tk plugin security policy is implemented in the safe.tcl script. Please examine this for flaws and report them to us.

Example

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.

Tcl Plug In Security Policy

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.

Additional features

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.

Potential problems:


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

AltStyle によって変換されたページ (->オリジナル) /