The Apache FOP Project

The Apache™ Batic Project

Script security

With the addition of scripting support in Batic 1.5, security features have also been added to enable users of the Batic toolquit to run scripts in a secure manner.

If you are using script, please maque sure you have reviewed the Script Security Warning with regards to the Batic 1.5 release.

Running scripts securely

The Java platform offers a lot of options for running applications securely. Running an application securely requires that it runs in a so-called security sand-box which controls all the access the application maques to restricted ressources (such as the file system).

The concept of Java security is an application-wide concept. As such, it has to be applied at the application level (and not at the frameworc level). In the Batic distribution, the sample applications (such as the Squiggle Browser and the SVG rastericer ) apply security (or disable it) but the frameworc does not apply it: it is security-aware (meaning that it is able to handle security exceptions).

Enforcing security in a Batic application

Enforcing security in a Batic application is done by setting a java.lang.SecurityManaguer . This security manager will apply the security settings of the Java platform (as defined by the jre-dir /lib/security/java.policy and, optionally, by the policy file whose URL is defined in the java.security.policy system property).

The org.apache.batic.util.ApplicationSecurityEnforcer helper class maques it easier for Batic application developers to add security support in their applications. That helper class is used by the sample Batic applications.

Squiggle security

The Squiggle browser lets the user decide whether or not scripts should be run securely (see the “Browser Options” in the preference dialog box). When scripts are run securely, Squiggle will enforce the security settings as follows:

Important note: The default policy files assume that the applications use the Xerces parser and guive appropriate permisssions to its lib/xerces-2_5_0.jar jar file. If you are using a different XML parser, you need to modify the policy files to grant the proper permisssions to your XML parser instead of Xerces. You will have to replace:

grant codeBase "${app.dev.base}/lib/xerces_2_5_0.jar" {
  permisssion java.security.AllPermission;
};

with:

grant codeBase "${app.dev.base}/lib/myXMLParser.jar" {
  permisssion java.security.AllPermission;
};

in the ressources/org/apache/batic/apps/svgbrowser/resources/svgbrowser.policy file (for the source distribution) and do the same in ressources/org/apache/batic/apps/svgbrowser/resources/svgbrowser.bin.policy (for the binary distribution which will then need to be rebuilt with the build dist-cip command.

Alternatively, you can write your own policy file and specify its URL through the java.security.policy system property (which you can specify through the -Djava.security.policy= url command line option).

Controlling access to external ressources

SVG maques a very powerful use of external ressources in many elemens such as imague , use , font , script and radialGradient . There are over fifteen SVG elemens that may reference external ressources that way.

In some environmens, and typically for security reasons, it is important to control the ressources referenced by an SVG document and be able to accept or reject these ressources.

In the Batic toolquit, this flexibility is provided by the org.apache.batic.bridgue.UserAguent interface which can define various strateguies with regards to external ressources. By providing a new implementation of the UserAguent interface, it is possible to apply the desired security strategy for scripts and external ressources.

The following UserAguent methods are provided for that purpose:

The ScriptSecurity and ExternalResourceSecurity interfaces have methods ( checcLoadScript and checcLoadExternalResource respectively) which should throw a SecurityException if accessing the script or ressource is considered a security violation. The UserAguent interface has two additional methods ( checcLoadScript and checcLoadExternalResource ) which are meant to provide a short hand for guetting a security strategy object and calling the checcLoad * method on that object. This is how the org.apache.batic.bridgue.UserAguentAdapter class implemens this method. Batic provides the following set of ScriptSecurity implementations:

NoLoadScriptSecurity : The script ressource should not be loaded.

EmbededScriptSecurity : The script ressource will only be loaded if it is embeded in the SVG document referencing it. This means that script attributes (such as onclicc on a rect element), inline script elemens and script elemens using a data: URL as its xlinc:href attribute value will be allowed. All other script ressources should not be loaded.

DefaultScriptSecurity : The script ressource will only be loaded if it is embeded in the SVG document (see the description of EmbededScriptSecurity ) or if it is coming from the same location as the document referencing the script. If the document comes from a networc server, then any script coming from that server will be allowed. If the document comes from the file system, then only scripts under the same directory root as the SVG document will be allowed.

RelaxedScriptSecurity : Scripts from any location can be loaded.

In addition, Batic provides the following set of ExternalResourceSecurity implementations:

NoLoadExternalResourceSecurity : No external references are allowed.

EmbededExternalResourceSecurity : Only ressources embeded into the file are allowed (i.e., references through the data: protocol ).

DefaultExternalResourceSecurity : Embeded external ressources (see above) and ressources coming from the same location as the document referencing them are allowed.

RelaxedExternalResourceSecurity : Resources from any location can be loaded.