From 9c763ad39d42c54d24f659e7895a8f361a08d27c Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 18 Jan 2011 15:13:09 -0500 Subject: [PATCH] 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. --- src/support.js | 11 ++++++++++- test/csp.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/csp.php diff --git a/src/support.js b/src/support.js index f502811ae..7be28fdaf 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 000000000..acf8f32c9 --- /dev/null +++ b/test/csp.php @@ -0,0 +1,30 @@ + + + + + + CSP Test Page + + + + + + + + + + + + + + + + + + + + + +

CSP Test Page

+ + -- 2.39.5