A Java Filter: Dirk Balfanz Edward W. Felten
A Java Filter: Dirk Balfanz Edward W. Felten
Abstract it wants.
Java has taken a different approach to mobile code se-
Rogue Java applets are currently a major concern for big curity. The Java platform is designed in such a way that
companies and private users alike. While the best protec- all system calls made by a Java program (Java applet) must
tion against them is to turn off Java support in the WWW be routed through a security manager, which can decide
browser, this “solution” is unsatisfying: it deprives users of whether or not certain sensitive operations should be al-
many of the advantages of the Java platform. Other mech- lowed. In the past, the security manager would deny ap-
anisms such as firewalls and code signing have been pro- plets almost any operations that would give them access to
posed to “enhance” security. In this paper we argue that the local system or the network, except to the network host
these mechanisms cannot deliver the security they promise. they were loaded from. This had the effect that Java applets
As an alternative, we describe a simple yet effective way would be executed in a “sandbox” which they could not
to prevent untrusted applets from entering the user’s com- leave. Recently, the security manager has been augmented
puter. At the same time, we allow trusted applets to exe- with fine-grained access control mechanisms that allow it
cute in whatever sandbox the browser provides for them. to make decisions based on who signed the applet and/or
Our technique works by modifying Java class loaders and where it was loaded from [5, 9]. However, it is still the case
can be extended to provide fine-grained access control for that every security-relevant system call is routed through
Java applets. the security manager, and that the security manager may
deny invocation of the respective system call. Breaking
Java security, then, means being able to access the system
1 Introduction (by bypassing the security manager or some other means)
when the security policy would have forbidden that access.
One especially interesting topic in the realm of Inter-
Again, due to implementation errors, oversights, or de-
net security is that of mobile code. While users browse the
sign flaws, ways have been found to break Java security.
World Wide Web, programs — known variously as applets,
The seriousness of possible attacks ranged from unautho-
controls, or scripts — are downloaded onto their comput-
rized network access to the ability to call any system call,
ers as part of Web pages they are viewing. The result is
thus completely exposing the system [3, 6]. All in all,
that untrusted programs are run on the user’s machine. The
there have been at least six flaws in various Java versions
system must protect the user against programs that have
that would have allowed an attacker to completely defeat
hostile intentions. For example, the mobile programs must
the security of the Java Virtual Machine. While all of
be prevented from reading personal information or altering
the reported bugs were fixed promptly, often within a few
the system’s state.
days, the threat of malicious Java applets that might exploit
This is why mobile code technologies such as ActiveX
undiscovered security holes remains.
[1] provide a line of defense: before downloading the mo-
bile code, the user is asked whether or not she really wants Java also suffers from “denial-of-service” attacks, in
to install the software in question. The code can be digi- which an applet does not penetrate the system but merely
tally signed to give the user some evidence as to who wrote crashes it or makes it unusable. This is often done via al-
(or endorsed) it. Security “breaches” of ActiveX take two lowed operations (ones permitted by the security manager),
forms: either the user is tricked into accepting hostile code, for example by opening 50 windows per second until the
or an ActiveX program can (by exploiting some sort of im- window manager software dies. Denial-of-service attacks
plementation error or oversight) transport itself onto the do not constitute a breach of security, but they are a con-
user’s system without the user’s consent. Once an Ac- cern for users. So far, no commercial Java system has pro-
tiveX control is installed on a machine, it can do whatever visions against denial-of-service attacks.
1
1.1 Approaches to Java Security
2
connection, which will make them indistinguishable
from ordinary files to the firewall.
3
Action URL
allow http://www.javasoft.com:80/applets/WordMatch/
deny http://www.javasoft.com/
allow http://www.packet.com/java/hotwired/
deny http://www.earthweb.com/java/Thingy/
deny http://www.cruzio.com/˜sabweb/arcade/
4
Figure 5: This dialog that pops up when an unknown applet Figure 6: Advanced version of the dialog.
is discovered.
list.
up. It displays the URL the applet is about to be loaded
from, and asks to answer two questions: First, we have to 4.3 Implementation
decide whether or not we want this applet to run on our
machine. The default is not to run the applet. Second, we We implemented the Java Filter for Netscape Naviga-
should decide whether that decision is to be “remembered” tor 3.0 and Microsoft Internet Explorer 3.0 on the Win-
for the future, i.e. whether the URL should be included in dows platform. Most of the code could be shared, although
the file that is saved for future use. The default is not to access to the Windows registry and file system (for sav-
remember that decision, which will cause the browser to ing the list of URLs) turned out to be slightly different on
ask the same question again if and when we visit the same each platform. The solution is not “100% pure”, since we
applet during a future session. During a browser session, needed native methods to access file system and Windows
we will usually not be asked again for a specific applet. If registry in Navigator and used Microsoft-specific classes
we choose to make the settings permanent, then the applet for Internet Explorer. The installation, which can be down-
in question will always be allowed on our system (or be loaded from our Web site, will change the applet class
denied entrance - depending on what we chose) - unless loader of the installed browsers and add necessary classes
or until we manually change the file that holds the list of to the class library.
URLs.
We can have more advanced control over which ap- 4.3.1 Changing the Class Library
plets should be allowed into our system, and which applets
How did we change the browser’s class library, in partic-
should be blocked. When we click on the ”Advanced” tab
ular the class loader so that it employs our guard object?
bar, the dialog changes to what we see in Figure 6.
Remember that we do not have source code of the class
The upper half of the dialog lets us answer the same loader. There are several ways to do this:
questions that we saw in the “easy” version. The field
displaying the URL is now editable. We can change One obvious way is to extract the class loader from the
this URL to whatever we like: If we come across class library, decompile, change the Java code, com-
an applet from http://java.sun.com/applets/ pile it, and inject it back into the class library (which is
WordMatch/ we can decide that we trust all applets from a ZIP file). This has some legal issues (which we will
JavaSoft and edit the URL to show http://java.sun. not address in this paper) and is also difficult: A num-
com/. This edited URL, and not the original one, will be ber of decompilers that we tested would either fail on
included in the list of URLs against which the guard object the task of decompiling the class loader or produce
checks applet URLs. obviously incorrect code. However, if a decompiler is
The lower half of the dialog shows the URLs known so available that does the job, this is a valid measure.
far to the system, and whether or not we allowed access
Since our changes to the class loader are minimal (we
for them. Since the list of URLs is searched from top to
basically add one line of code in the constructor) we
bottom, the order in which the URLs occur matters. The
user can change the priority of the current URL within that http://www.cs.princeton/sip/
5
could theoretically change the class file directly. Al- 6 Related Work
though we only add a few bytecode instructions, we
need a program that can parse and write class files: In Section 2 we saw which measures are sometimes
Injecting only a few bytecode instructions can cause taken to “enhance” security. However, we also saw that
complex changes in the class file (e.g. constant pool, these measures are either inconvenient or not effective. Mi-
attributes). crosoft has recently included the notion of security zones
in their Internet Explorer [7]. Depending on what security
One technique that we used is to make trivial changes
zone an applet comes from, it can run with more or less
to the class file of the AppletClassLoader
privileges. Unlike the systems that Netscape and Sun de-
to the effect that the class file then repre-
veloped, the settings for a security zone can actually spec-
sents a class of a different Name (for example
ify that Java code should not be downloaded at all.
XppletClassLoader). Then we create a new
This makes Microsoft’s system very similar to our Java
Java class, called AppletClassLoader that sub-
Filter, except that Microsoft’s system is bigger and in-
classes the original AppletClassLoader (now
cludes more features. On the other hand, the concepts and
XppletClassLoader). In its constructor it calls
tools presented in this paper are simple and general enough
the original constructor and the guard object (which
to be applied almost without changes to any type of appli-
may or may not throw an exception). Since we in-
cation that executes remote Java code.
herit all non-private methods, to the runtime system
the new class is a perfectly valid applet class loader. We also note that the concept of using class loaders
to control Java security can be extended to provide fine-
The other classes that are needed for the Java Filter can grained access control. Instead of blocking the applet, we
just be added to the class library. could (again, by using class loaders) block certain system
We note that these techniques can be used to enable classes from being linked against the applet, thus denying
Java filtering not only for mainstream Web browsers, but access to certain parts of the system. See [9] for details on
also for other types of (Java) applications that execute Java this.
applets but want to be protected from attacks exploiting
weaknesses in the Java implementation.
7 Conclusion
5 Future Work We presented a simple, yet effective protection against
untrusted Java applets that doesn’t have many of the short-
Since the Java Filter is not a pure Java implementation,
comings of other possible approaches. We implemented
ports to other platforms like the Macintosh or UNIX re-
the design and have made available a copy for public down-
quire additional work. Feedback we got from users who
load.
downloaded the Java Filter suggested that we should write
versions of the Java Filter for those platforms.
Also, the current URL pattern matching is not very so-
phisticated. Sometimes companies have many Web servers Acknowledgements
and would like to have a line like this in their URL list:
allow http://*.mycompany.com/ Our work is supported by donations from Sun Mi-
We are looking into providing support for regular ex- crosystems, Bellcore, Microsoft, and Merrill Lynch. Ed-
pressions for that purpose. ward Felten is supported in part by an NSF National Young
In recent versions of their browsers, Netscape and Mi- Investigator award.
crosoft have included code signing and features that are
similar to what the Java Filter offers. We still believe that
not downloading classes in the first place is the best protec- References
tion against malicious Java applets. However, we are not
certain whether a version of the Java Filter for the latest [1] Microsoft Corporation. Proposal for authenticating
versions of Navigator and Internet Explorer is desirable (or code via the internet. http://www.microsoft.
feasible, for that matter: the class libraries are now signed com/security/tech/authcode/
and can no longer be easily altered). authcode-f.htm, April 1996.
This turned out to be valid only for Internet Explorer. In Netscape this
technique did not work, presumably because the runtime system relies on [2] Drew Dean. The security of static typing with dynamic
certain specific internals of the class loader like private fields etc. linking. In Fourth ACM Conference on Computer and
6
Communications Security, Zurich, Switzerland, April
1997.
[3] Drew Dean, Edward Felten, and Dan Wallach. Java
security: From HotJava to Netscape and beyond. In
Proceedings of 1996 IEEE Symposium on Security and
Privacy, Oakland, California, May 1996.
[4] S. Drossopoulou and S. Eisenbach. Java is type safe –
probably. In Proceedings of the Eleventh European
Conference on Object-Oriented Programming, June
1997.