CrossSafe

CrossSafe provides secure cross domain JSON requests and partially implements the JSONRequest specification (the get and cancel methods). XMLHttpRequest follows a same origin policy, and because of this, when developing mashups that involve retrieving data from servers other than the origin, developers have typically had to decide between a secure, but slow connection that through a proxy, or a direct, faster, but unsecure dynamic script tag retrieval of information. CrossSafe allows fast, direct, and secure connections to foreign servers from the browser. CrossSafe uses the JSONRequest API as it provides a subset of the JSONRequest features. CrossSafe does not implement the entire specification. However, developers can use the JSONRequest API in CrossSafe to make cross domain requests (which is one of the primary motivations for JSONRequest), and if and when browsers implement JSONRequest natively, CrossSafe will simply leave the JSONRequest object alone, and code will continue to operate with the benefits of a native implementation. CrossSafe uses a technique for securing communication that is similiar to the Subspace approach which can be read about here.

CrossSafe does have limitations. CrossSafe still requires a callback parameter (like JSONP) to be implemented by foreign servers (it uses sandboxed script tag insertion internally). CrossSafe also requires certain host names on the origin server to be accessible. See the limitations sections for more information.

Setup

  1. Unzip CrossSafe.zip into your web application.
  2. Configure your web server and DNS entries to allow requests from webservice.mydomain.com, webservice1.mydomain.com,... webservicex.mydomain.com, where x is the maximum number of different domains you will access with CrossSafe.
  3. Load CrossSafe in your web page:
    
    
    
    You must ensure that the CrossSafe.directory value is set to the absolute path for the CrossSafe files.
  4. Ensure that the cross domain JSON sources that you will be accessing support a callback parameter. If you are having trouble it may be helpful to set CrossSafe.visibleFrames to true to visually verify that the correct pages are being loaded.
In order for CrossSafe to work properly, it must be able to access it's files (mediator.html and untrusted.html) via http://webservicex.mydomain.com[CrossSafe.directory]mediator.html. The DNS, web server, and CrossSafe.directory value must be setup correctly such that this URL is accessible. Once this configured correctly, one can securely access JSON web services at different domains by simply using JSONRequest.get:
JSONRequest.get(url,done);
JSONRequest.get will request a JSON object from the given URL. The function returns an id value that identifies the current request. The done will be called when the request is completed. The done function will be called with three parameters:
function done(id,object,error)
The id identifies the request, the object is value that was returned, and the error object is included if any errors were encountered. For example:
JSONRequest.get("http://local.yahooapis.com/...?...&output=json",function(id,returnedObject) {
        ... Handle the response from the request
});
JSONRequest.cancel(id) can also be called to cancel a request. Please see the JSONRequest API for more information (note that the post method is not implemented in CrossSafe). The host name "webservice" can be configured to a different value. CrossSafe requires a three part host names (like www.mydomain.com) in order to work properly. By default, it will redirect to a host name with "www" prefix if a page with a two part domain name is loaded (like mydomain.com), to ensure proper security. This can also be configured.

Limitations

CrossSafe does not have all the capabilities of a native implementation of JSONRequest, nor is it even possible with only the capabilities of the current browsers. Current limitations include:

Options