From 8463134125160f1b1ec72d0d02f7932cb953d294 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 19 Oct 2020 20:25:08 -0400 Subject: [PATCH] pad: Improve rendering of uncaught exceptions * Use jQuery to build the message HTML so that special characters in the error message, URL, etc. are properly escaped. This helps avoid XSS vulnerabilities. * Use bold text for the error message to make it stand out. * Add a line break between the error message and "in at line " so that the error message stands out more. * Use `

...

` instead of `
` to separate the parts of the popup. * Use CSS for spacing instead of `
`. * Grammar fixes (add a missing comma, "at" instead of "in"). --- src/static/js/pad_utils.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/static/js/pad_utils.js b/src/static/js/pad_utils.js index 4f958a6ca..d200420e6 100644 --- a/src/static/js/pad_utils.js +++ b/src/static/js/pad_utils.js @@ -484,7 +484,6 @@ function setupGlobalExceptionHandler() { globalExceptionHandler = function test (msg, url, linenumber) { var errorId = randomString(20); - var userAgent = padutils.escapeHtml(navigator.userAgent); var msgAlreadyVisible = false; $('.gritter-item .error-msg').each(function() { @@ -494,13 +493,19 @@ function setupGlobalExceptionHandler() { }); if (!msgAlreadyVisible) { - errorMsg = "Please press and hold Ctrl and press F5 to reload this page
\ - If the problem persists please send this error message to your webmaster:

\ -
\ - ErrorId: " + errorId + "
\ - URL: " + padutils.escapeHtml(window.location.href) + "
\ - UserAgent: " + userAgent + "
\ - "+ msg + " in " + url + " at line " + linenumber + '
'; + const txt = document.createTextNode.bind(document); // Convenience shorthand. + const errorMsg = [ + $('

') + .append($('').text('Please press and hold Ctrl and press F5 to reload this page')), + $('

') + .text('If the problem persists, please send this error message to your webmaster:'), + $('

').css('text-align', 'left').css('font-size', '.8em').css('margin-top', '1em') + .append(txt(`ErrorId: ${errorId}`)).append($('
')) + .append(txt(`URL: ${window.location.href}`)).append($('
')) + .append(txt(`UserAgent: ${navigator.userAgent}`)).append($('
')) + .append($('').addClass('error-msg').text(msg)).append($('
')) + .append(txt(`at ${url} at line ${linenumber}`)).append($('
')), + ]; $.gritter.add({ title: "An error occurred",