|
With the addition of scripting support in Batik 1.5, security features
have also been added to enable users of the Batik toolkit to run
scripts in a secure manner.
If you are using scripts, please make sure you have reviewed the
Script Security
Warning with regards to the Batik 1.5 release.
There are two major script security features in Batik:
|
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 makes to
restricted resources (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 framework level).
In the Batik distribution, the sample applications (such as the
Squiggle Browser or the SVG
rasterizer) apply security (or disable it) but the framework does not
apply it: it is security-aware (meaning that it is able to handle security
exceptions).
|
| | | | Controlling access to external resources | | | | |
SVG makes a very powerful use of external resources in many elements
such as <image>, <use>, <font>, <script> or
<radialGradients> . There are over fifteen SVG elements which
may reference external resources that way.
In some environments, and typically for security reasons, it is
important to control the resources referenced by an SVG document
and be able to accept or reject these resources.
In the Batik toolkit, this flexibility is provided by the
org.apache.batik.bridge.UserAgent interface which
can define various strategies with regards to external resources.
By providing a new implementation of the UserAgent
interface, it is possible to apply the desired security strategy
for scripts and external resources.
The following UserAgent methods a provided for
that purpose:
getScriptSecurity(scriptType, scriptURL, docURL)
should return the ScriptSecurity strategy for
a script of type scriptType (e.g., text/ecmascript )
coming from scriptURL .
when referenced from the document whose url is docURL .
getExternalResourceSecurity(resourceURL, docURL)
should return the ExternalResourceSecurity for
a resource coming from resourceURL referenced
from the document at url docURL
The ScriptSecurity and ExternalResourceSecurity
interfaces have methods (checkLoadScript and
checkLoadExternalResource respectively) which should
throw a SecurityException if the script or resource
is considered a security threat.
| the UserAgent interface has two additional methods
(checkLoadScript and checkLoadExternalResource
which are meant to provide a short hand for getting a security strategy
object and calling the checkLoadXXX method on that object.
This is how the org.apache.batik.bridge.UserAgentAdapter
implements this method.
|
Batik provides the following set of ScriptSecurity implementations:
NoLoadScriptSecurity . The scrip resource should not be
loaded
EmbededScriptSecurity . The script resource will only
be loaded if it is embeded in the SVG document referencing it. This means
that script attributes (such as onclick on a <rect>
element is allowed), inline <script> elements and
<script> elements using a data: url
(i.e., the script content is Base 64 encoded into the script 's
xlink:href 's value) will be allowed. All other script
resources should not be loaded.
DefaultScriptSecurity . The script resource 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 network 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, Batik provides the following set of ExternalResourceSecurity
implementations:
NoLoadExternalResourceSecurity . No external references are allowed
EmbededExternalResourceSecurity . Only resources embeded into the
file are allowed (i.e., references through the data: protocol
DefaultExternalResourceSecurity . Embeded external resources (see above)
and resources coming from the same location as the document referencing them
are allowed.
RelaxedExternalResourceSecurity . Resources from any location
can be loaded.
|
|
|