A Lighter Alternative to Caja: ADsafe
ADsafe is a system that first gained popularity as a utility for cordoning off ads running on a page, since ads are simply one form of self-inflicted cross-site scripting (XSS) attack.
ADsafe’s premise is to prevent a developer from using markup that is deemed unsafe, restrict access to the global page object, and limit access to variable types from the third-party code. Essentially, this creates a sandbox that protects the root site or container from third-party code by limiting the functionality that can exist within an application.
ADsafe removes the following features from JavaScript:
- Global variables
Variables that are defined in the global scope are not allowed within ADsafe. ADsafe does, however, permit limited access to the
Array,Boolean,Number,String, andMathglobal objects of the page.thisSince the use of
thiswithin a function request maintains a binding to the global object, it is restricted in ADsafe.evalevalprovides access to the global scope, much like many of our other restricted tags, and also provides a mechanism for executing insecure code at runtime.argumentsAccess to the
argumentspseudo array is restricted.withSince
withmodifies the scope chain, its use is restricted.- Dangerous methods and properties
Due to capability leakage in some browsers,
arguments,callee,caller,constructor,prototype,stack,unwatch,valueOf, andwatchare not allowed in ADsafe when implemented using dot notation.- Names starting or ending with an ...
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