From: John Resig Date: Tue, 18 Jan 2011 20:13:09 +0000 (-0500) Subject: Add another tweak for handling CSP - we need to make sure that we don't trigger any... X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;ds=sidebyside;h=9c763ad39d42c54d24f659e7895a8f361a08d27c;p=jquery.git Add another tweak for handling CSP - we need to make sure that we don't trigger any eval on load (not sure if it's the best tweak, definitely not ideal). Add a test page as well so that it's easier to catch problem. --- diff --git a/src/support.js b/src/support.js index f502811..7be28fd 100644 --- a/src/support.js +++ b/src/support.js @@ -75,7 +75,7 @@ jQuery.support.optDisabled = !opt.disabled; jQuery.support.scriptEval = function() { - if ( jQuery.support._scriptEval === null) { + if ( jQuery.support._scriptEval === null ) { var root = document.documentElement, script = document.createElement("script"), id = "script" + jQuery.now(); @@ -101,6 +101,7 @@ // release memory in IE root = script = id = null; } + return jQuery.support._scriptEval; }; @@ -187,6 +188,14 @@ var el = document.createElement("div"); eventName = "on" + eventName; + // We only care about the case where non-standard event systems + // are used, namely in IE. Short-circuiting here helps us to + // avoid an eval call (in setAttribute) which can cause CSP + // to go haywire. See: https://developer.mozilla.org/en/Security/CSP + if ( !el.attachEvent ) { + return true; + } + var isSupported = (eventName in el); if ( !isSupported ) { el.setAttribute(eventName, "return;"); diff --git a/test/csp.php b/test/csp.php new file mode 100644 index 0000000..acf8f32 --- /dev/null +++ b/test/csp.php @@ -0,0 +1,30 @@ + + + + + + CSP Test Page + + + + + + + + + + + + + + + + + + + + + +

CSP Test Page

+ +