| 21.1 The Tcl/Tk Plugin |
|
|
The Tcl/Tk plugin is commonly known in the Tcl community as the Netscape plugin but it runs with some other browsers as well. This chapter is based on version 2.0 which was recently released at the time of writing. Over the past couple of years, the plugin has undergone rapid development and change. Earlier versions (including the alpha release of version 2.0) are very different than what is described here. Look for the most recent version of the plugin from Sun or Scriptics. The plugin provides a Tcl/Tk interpreter to execute tclets. After the plugin is installed, it will be loaded whenever your Web browser recognizes that it has downloaded a tclet. The easiest way to ensure such recognition is to give the extension .tcl to the tclet. Although most tclets expect to run in Tk, the .tcl extension is commonly used. As a tclet executes, Tk's root window appears as an entire Web page or as part of another Web page. When a tclet places a widget in the slave's root window, that widget appears in the browser. When the user backs out of this Web page or links to another Web page, the plugin terminates. Each time the user reviews the page, the plugin restarts. A tclet's root window will fill a Web page when it is downloaded as a Web page, for example, if another Web page links to it with the <A> tag. A tclet's root window will be part of a Web page if an <EMBED> tag in the containing page refers to it. In this case, the root window will have the dimensions given with the WIDTH and HEIGHT attributes of the <EMBED> tag. (See above in A Brief HTML Introduction for a description of the <EMBED> tag.) Remark
Figure 21.1a shows an example display which will result if you fetch a URL from this book's Web site with a Netscape browser. This example is similar to the one developed above in Chapter 19, "Canvases." As you drag the dots the line or polygon changes shape. The "Make Smooth" button is used to change the figure from a line or polygon to a similar Bezier curve which is "pulled" in the direction of the dots rather than going through the dots.
The plugin was designed to help you manage risks to your privacy or the integrity of your file system. It permits a tclet like the one that generated Figure 21.1a to run without noticeable constraint because such tclets do not open any files, create any TCP/IP channels, or take any other action that could either access your file system or communicate with another computer. Even so innocuous a form of communication as sending email is prohibited. One reason is that a tclet could use email in a way that damages the reputation of the person whose name appears as the sender. The plugin was not designed to manage all risks. Risks that are not so well managed involve the possibility that a tclet may try to deny you the use of your computer by keeping the processor busy or by using up your disk space. The main denial of service threat which the plugin tries to control is overuse of your disk space. However, the plugin controls some other things as well. For example, it denies a tclet access to a Tk command that is capable of grabbing control over all mouse input. The plugin is managed with a master script that runs in an almost normal
interpreter. The few abnormalities in this master interpreter have to do with
the fact that it runs in an environment initiated by your Web browser. The
master script creates a new slave interpreter to execute each downloaded
tclet. This slave interpreter is called a To make up for the Safe Base interpreter's limitations, the plugin master script gives it a policy command which a tclet can use to request an upgraded interpreter whose additional powers are consistent with some security policy. A tclet may be authorized for more than one security policy but it cannot run under more than one policy during one execution.
Security policies are described in configuration files. In the default installation you will find these files in a directory named config that is a sibling of the directory containing the executables. A policy's configuration file determines which command set will be available to the tclet in the upgraded interpreter. Remark
Here is a list of the security policies whose configuration files are shipped with version 2.0.
These policies have three things in common:
This section continues with three subsections, one devoted to each of these
commonalities.
The configuration file for a policy named NAME is itself named NAME.cfg and it consists of
The major function of most sections is to provide a method of declaring which resources may be used. Resources may be such things as security policies, URLs, host/port pairs, and so forth. This function of a section is supported by the enabling lines which belong to it. Some examples of enabling lines are:
The use of ifallowed is described in the next subsection. This subsection finishes with a description of the section command which is always followed by some arguments. Arguments such as policies, hosts, and ports are in one sense just names for strings which will be tested for acceptability as the configuration file is processed. In another sense, they tell the plugin's master script which section is being described and so they are not arbitrary names. For example, section policies declares a section used to describe which policies are acceptable and section hosts ports declares a section used to describe which hosts and ports are acceptable network connections. When a section is being used to test whether some resource may be used, the test is merely one of whether a string naming the resource fits a pattern. For example, after section urls, the test will be whether a URL fits a pattern. Pattern matching is done glob style. If the string matches the pattern in one of the allow statements in a section but does not match the pattern in any disallow statement, then the resource may be used. Remark
After a section statement with multiple arguments, each argument names a separate string which must be matched. For example after section hosts ports, enabling statements must present two patterns. The first will be used to match a host computer and the second will be used to match a port on that computer. Each pattern must match for an enabling statement to score a match. All lines in a configuration file undergo Tcl-style substitutions. This is the basis for patterns such as $originURL* and $originHomeDirURL*. In these cases a variable made available by the plugin master script is substituted: originURL contains a canonical version of the URL used to fetch the current tclet and originHomeDirURL contains that part originURL up to its file name. A "canonical" version of a URL is a complete URL with occurences of ../ removed from it. A description of the available variables can be found in the on-line documentation for "plugin."
Remarks
There is a way in which string matching does not follow the glob style. Numeric strings matched with a pattern such as >10 or <=90 must be numbers that satisfy the given inequality for a match to occur.
Authorizing a Tclet
Currently, the verification that a tclet may operate under a particular security policy depends on the URL that was used to fetch the tclet. Authorizations are made in plugin.cfg in the enabling statement that allows a particular policy to be used. The following two statements appear in the policies section of plugin.cfg as shipped. allow home allow javascript ifallowed trustedJavascriptURLs $originURLThe first accepts the policy named "home" for any URL. The second needs more explanation. You know from the previous section that an enabling statement will have at least as many arguments as given to the governing section statement. Sometimes there can be more arguments than specified by the section statement. The most important way for this to happen is for the first additional argument to be ifallowed. The enabling statements just shown appear in a policies section so one argument is expected for them. The use of ifallowed above declares that a match with the javascript pattern is not acceptable unless the string contained in originURL meets the criteria declared in the section named trustedJavascriptURLs. A section of this name is included in plugin.cfg for the sole purpose of defining the URLs of those tclets which may run under the javascript policy. It looks like this: section trustedJavascriptURLs allow http://sunscript.sun.com:80/plugin/javascript/*You can edit plugin.cfg and change the enabling statement(s) in this section so that they define exactly those URLs which you wish to have access to the javascript policy on your machine. The default plugin.cfg has no additional section for the home policy because this policy is permitted for any tclet. If you wanted to change that you would define a new section that would accept tclets for the home policy. If the new section is declared with section trustedHomeURLs, you would change allow home to allow home ifallowed trustedHomeURLs $originURL
The inside, outside, and trusted policies, by default, are not permitted for any tclets and so they also lack sections defining which URLs may be used to download tclets for them. To change that you would create those sections and change the appropriate disallow statement to a suitable allow statement. Do not enable the inside or outside policies without first reading below in Combining Features into Policies.
Remark
Persistent Storage for TcletsAll the security policies listed above allow tclets to save and recover a few, size-limited files. Under these policies, a tclet uses the usual file handling commands to work with files but, in reality, these file handling commands are different in that the open command does not permit piping and strips all directory information from file names to enforce the rule that the plugin and not the script determines which directory is used. A tclet can only access files in one particular directory each time it executes. This directory is not chosen in a straightforward way. Luckily you do not need to know the exact method. What you need to know is that the directory name is chosen for a given policy name and URL path by an injection (that is, a one-to-one function). Here "policy name" means the name of the policy under which the tclet is running and "URL path" means the URL from which the tclet was fetched. Knowing the storage directory is a one-to-one function of a policy name and a URL pathname tells you that a tclet is prevented from accessing another tclet's files or from accessing its own files if it stored those files while executing under a different security policy. This observation, however, is slightly wrong because the concept of "URL path" is more flexible than I have explained so far.
Using a technique described below in Writing Tclets, a tclet can change the URL path used for determining its storage directory! However, its freedom in making that change is greatly limited. In particular, a tclet can remove a suffix of the URL path provided that suffix is not so long it includes the part of the URL which determines the server and port. For example, a tclet fetched with this URL, http://www.mapfree.com:80/sbf/tcl/book/safeTk.tclcan arrange for the URL path used in finding its persistent storage directory to be http://www.mapfree.com:80/sbf/tcl/bookThe effect of this would be to permit this tclet to share persistent storage with any other tclet obtained from the same directory on the same server and running under the same security policy. The shortest URL path that this tclet can use is http://www.mapfree.com:80/The effect of using this path would be to permit this tclet to share persistent storage with any other tclet obtained from the same server. Of course, in either case, the other tclet that is sharing the persistent storage must similarly shorten its URL path if data sharing is to occur. What this flexibility means is, when you set up your authorizations to use security policies, you must assume that tclets obtained from the same server and running under the same security policy will be able to share persistent data. As a system administrator, you are concerned with where in your directory tree these persistent-file directories will actually appear. They appear as a subtree that is rooted in the directory declared in a TEMP or TMP environment variable. The root of this subtree is a directory named persist. Remark
|
Author's Home Page |
|
Order from Amazon. |