JavaScript security

The security hazard

JavaScript allows executable code to run on the user's machine without his or her knowledge. Web pages are frequently downloaded through firewalls and run on presumably secured inner company networks.

First line of defense: restricted capabilities

Privacy protection in JavaScript

When browsing the Web, you expose this information to any Web site you visit:

The primary purpose of JavaScript security is to prevent scripts from accessing any other information about you besides these basics.

Some capabilities which it is important to deny scripts:

The Same Origin Policy

Scripts can set the domain property of the document object. A script can then access the contents of other windows loaded from the same domain.

However, any "user-defined" properties (variables set by JavaScript in the Web page) may be accessed by scripts from other domains.

Signed Scripts and Privileges

Navigator 4 and up support a security model involving cryptographic signatures. The signatures use public-key encryption to validate that a script originates with a certain principal, e.g.Netscape Communications, Inc. The user can decide whether to grant these scripts the following privilege levels:

None of this works under IE. Scripts are locked down by default and cannot easily be unlocked.

Establishing signed scripts

Netscape provides a signtool for signing scripts, along with some practice certificates. Commercial use requires you to acquire a digital certificate from one of the many digital certificate repository firms such as VeriSign, Inc.