Skip to content

Instantly share code, notes, and snippets.

@quickredfox
Created March 16, 2012 17:31
Show Gist options
  • Save quickredfox/2051295 to your computer and use it in GitHub Desktop.
Save quickredfox/2051295 to your computer and use it in GitHub Desktop.
dirty sandboxing
var callForJS = $.ajax( {
complete: function( jqXhr ){
var unsafeResponse = jqXhr.responseText
, empty = {};
new Function( '', jqXhr.responseText ).call( empty ) // empty object as scope
}
} );
// Safer, if you want to restrict access to some globals
var callForJS = $.ajax( {
complete: function( jqXhr ){
var unsafeResponse = jqXhr.responseText
, empty = {};
new Function( 'window', 'jquery', '$', jqXhr.responseText ).call( empty, empty, empty, empty ) // re-define scope and sensitive objects
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment