Created
March 16, 2012 17:31
-
-
Save quickredfox/2051295 to your computer and use it in GitHub Desktop.
dirty sandboxing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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