From c8097f88a5d4fe6b76366c716a4f7088ccdb6f4e Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 8 May 2014 16:14:25 +0800 Subject: [PATCH] MDL-45472 AJAX: Whitelist prototype values form JS Error in exception dialogue --- .../moodle-core-notification-exception-debug.js | 17 ++++++++++++++++- .../moodle-core-notification-exception-min.js | 2 +- .../moodle-core-notification-exception.js | 17 ++++++++++++++++- lib/yui/src/notification/js/exception.js | 17 ++++++++++++++++- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js index c69f9b50bb7..1ff144eb7ca 100644 --- a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js +++ b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js @@ -46,9 +46,24 @@ var EXCEPTION_NAME = 'Moodle exception', * @class M.core.exception * @extends M.core.dialogue */ -EXCEPTION = function(config) { +EXCEPTION = function(c) { + var config = Y.mix({}, c); config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; config.closeButton = true; + + // We need to whitelist some properties which are part of the exception + // prototype, otherwise AttributeCore filters them during value normalisation. + var whitelist = [ + 'message', + 'name', + 'fileName', + 'lineNumber', + 'stack' + ]; + Y.Array.each(whitelist, function(k) { + config[k] = c[k]; + }); + EXCEPTION.superclass.constructor.apply(this, [config]); }; Y.extend(EXCEPTION, M.core.dialogue, { diff --git a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-min.js b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-min.js index 326c1c6514f..44d504af71c 100644 --- a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-min.js +++ b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-min.js @@ -1 +1 @@ -YUI.add("moodle-core-notification-exception",function(e,t){var n,r,i,s,o,u,a;n="moodle-dialogue",r="notificationBase",i="yesLabel",s="noLabel",o="title",u="question",a={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var f="Moodle exception",l;l=function(t){t.width=t.width||M.cfg.developerdebug?Math.floor(e.one(document.body).get("winWidth")/3)+"px":null,t.closeButton=!0,l.superclass.constructor.apply(this,[t])},e.extend(l,M.core.dialogue,{_hideTimeout:null,_keypress:null,initializer:function(t){var n,i=this,s=this.get("hideTimeoutDelay");this.get(r).addClass("moodle-dialogue-exception"),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+t.name+"

",e.WidgetStdMod.REPLACE),n=e.Node.create('
').append(e.Node.create('
'+this.get("message")+"
")).append(e.Node.create('")).append(e.Node.create('")).append(e.Node.create('")),M.cfg.developerdebug&&n.all(".moodle-exception-param").removeClass("hidden"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),s&&(this._hideTimeout=setTimeout(function(){i.hide()},s)),this.after("visibleChange",this.visibilityChanged,this),this.after("destroyedChange",function(){this.get(r).remove()},this),this._keypress=e.on("key",this.hide,window,"down:13,27",this),this.centerDialogue()},visibilityChanged:function(e){if(e.attrName==="visible"&&e.prevVal&&!e.newVal){this._keypress&&this._keypress.detach();var t=this;setTimeout(function(){t.destroy()},1e3)}}},{NAME:f,CSS_PREFIX:n,ATTRS:{message:{value:""},name:{value:""},fileName:{value:""},lineNumber:{value:""},stack:{setter:function(e){var t=e.split("\n"),n=new RegExp("^(.+)@("+M.cfg.wwwroot+")?(.{0,75}).*:(\\d+)$"),r;for(r in t)t[r]=t[r].replace(n,"
ln: $4
$3
$1
");return t.join("")},value:""},hideTimeoutDelay:{validator:e.Lang.isNumber,value:null}}}),M.core.exception=l},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); +YUI.add("moodle-core-notification-exception",function(e,t){var n,r,i,s,o,u,a;n="moodle-dialogue",r="notificationBase",i="yesLabel",s="noLabel",o="title",u="question",a={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var f="Moodle exception",l;l=function(t){var n=e.mix({},t);n.width=n.width||M.cfg.developerdebug?Math.floor(e.one(document.body).get("winWidth")/3)+"px":null,n.closeButton=!0;var r=["message","name","fileName","lineNumber","stack"];e.Array.each(r,function(e){n[e]=t[e]}),l.superclass.constructor.apply(this,[n])},e.extend(l,M.core.dialogue,{_hideTimeout:null,_keypress:null,initializer:function(t){var n,i=this,s=this.get("hideTimeoutDelay");this.get(r).addClass("moodle-dialogue-exception"),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+t.name+"

",e.WidgetStdMod.REPLACE),n=e.Node.create('
').append(e.Node.create('
'+this.get("message")+"
")).append(e.Node.create('")).append(e.Node.create('")).append(e.Node.create('")),M.cfg.developerdebug&&n.all(".moodle-exception-param").removeClass("hidden"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),s&&(this._hideTimeout=setTimeout(function(){i.hide()},s)),this.after("visibleChange",this.visibilityChanged,this),this.after("destroyedChange",function(){this.get(r).remove()},this),this._keypress=e.on("key",this.hide,window,"down:13,27",this),this.centerDialogue()},visibilityChanged:function(e){if(e.attrName==="visible"&&e.prevVal&&!e.newVal){this._keypress&&this._keypress.detach();var t=this;setTimeout(function(){t.destroy()},1e3)}}},{NAME:f,CSS_PREFIX:n,ATTRS:{message:{value:""},name:{value:""},fileName:{value:""},lineNumber:{value:""},stack:{setter:function(e){var t=e.split("\n"),n=new RegExp("^(.+)@("+M.cfg.wwwroot+")?(.{0,75}).*:(\\d+)$"),r;for(r in t)t[r]=t[r].replace(n,"
ln: $4
$3
$1
");return t.join("")},value:""},hideTimeoutDelay:{validator:e.Lang.isNumber,value:null}}}),M.core.exception=l},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js index c69f9b50bb7..1ff144eb7ca 100644 --- a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js +++ b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js @@ -46,9 +46,24 @@ var EXCEPTION_NAME = 'Moodle exception', * @class M.core.exception * @extends M.core.dialogue */ -EXCEPTION = function(config) { +EXCEPTION = function(c) { + var config = Y.mix({}, c); config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; config.closeButton = true; + + // We need to whitelist some properties which are part of the exception + // prototype, otherwise AttributeCore filters them during value normalisation. + var whitelist = [ + 'message', + 'name', + 'fileName', + 'lineNumber', + 'stack' + ]; + Y.Array.each(whitelist, function(k) { + config[k] = c[k]; + }); + EXCEPTION.superclass.constructor.apply(this, [config]); }; Y.extend(EXCEPTION, M.core.dialogue, { diff --git a/lib/yui/src/notification/js/exception.js b/lib/yui/src/notification/js/exception.js index 1d11dc3da1b..ea8f4a5fe3f 100644 --- a/lib/yui/src/notification/js/exception.js +++ b/lib/yui/src/notification/js/exception.js @@ -17,9 +17,24 @@ var EXCEPTION_NAME = 'Moodle exception', * @class M.core.exception * @extends M.core.dialogue */ -EXCEPTION = function(config) { +EXCEPTION = function(c) { + var config = Y.mix({}, c); config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; config.closeButton = true; + + // We need to whitelist some properties which are part of the exception + // prototype, otherwise AttributeCore filters them during value normalisation. + var whitelist = [ + 'message', + 'name', + 'fileName', + 'lineNumber', + 'stack' + ]; + Y.Array.each(whitelist, function(k) { + config[k] = c[k]; + }); + EXCEPTION.superclass.constructor.apply(this, [config]); }; Y.extend(EXCEPTION, M.core.dialogue, {