The JavaScript Sandbox
When JavaScript was first released, there was understandable concern about opening a web page that would execute a bit of code directly in your machine. What if the JavaScript included something harmful, such as code to delete all Word documents or worse, copy them for the script originator?
To prevent such occurrences and to reassure browser users,
JavaScript was built to operate in a sandbox: a protected environment in which the
script can’t access the resources of the browser’s computer.
In addition, browsers implement security conditions above and
beyond those established as a minimum for the JavaScript language. These
are defined in a browser-specific security
policy, which determines what the script can and cannot do.
One such security policy dictates that a script may not communicate with
pages other than those from the same domain where the script originated.
Most browsers provide the means to customize this policy even further,
making the environment in which the script operates more, or less,
restrictive.
Unfortunately, even with the JavaScript sandbox and browser security policies, JavaScript has had a rough time, and hackers have discovered and exploited several JavaScript errors—some browser-dependent, some not. One of the more serious is known as cross-site scripting (XSS). This is actually a class of security breaks (some coming through JavaScript, others through holes in the browsers, and still others through the server) that can lead to cookie ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access