From f8c012abf4baea04d7e02196ffb71fd4fd6d28eb Mon Sep 17 00:00:00 2001 From: oranges Date: Tue, 18 Jun 2019 19:06:45 +1200 Subject: [PATCH] Revoke JS error handler's right to exist (#44581) unused, vulnerable --- code/modules/client/asset_cache.dm | 1 - code/modules/client/darkmode.dm | 1 - .../browserassets/html/browserOutput.html | 1 - .../browserassets/js/browserOutput.js | 1 - .../goonchat/browserassets/js/errorHandler.js | 34 ------ code/modules/goonchat/jsErrorHandler.dm | 102 ------------------ tgstation.dme | 1 - 7 files changed, 141 deletions(-) delete mode 100644 code/modules/goonchat/browserassets/js/errorHandler.js delete mode 100644 code/modules/goonchat/jsErrorHandler.dm diff --git a/code/modules/client/asset_cache.dm b/code/modules/client/asset_cache.dm index f3c366a4987..e38320d603f 100644 --- a/code/modules/client/asset_cache.dm +++ b/code/modules/client/asset_cache.dm @@ -521,7 +521,6 @@ GLOBAL_LIST_EMPTY(asset_datums) verify = FALSE assets = list( "json2.min.js" = 'code/modules/goonchat/browserassets/js/json2.min.js', - "errorHandler.js" = 'code/modules/goonchat/browserassets/js/errorHandler.js', "browserOutput.js" = 'code/modules/goonchat/browserassets/js/browserOutput.js', "fontawesome-webfont.eot" = 'tgui/assets/fonts/fontawesome-webfont.eot', "fontawesome-webfont.svg" = 'tgui/assets/fonts/fontawesome-webfont.svg', diff --git a/code/modules/client/darkmode.dm b/code/modules/client/darkmode.dm index dc0e3153cf3..2f2355612c7 100644 --- a/code/modules/client/darkmode.dm +++ b/code/modules/client/darkmode.dm @@ -121,7 +121,6 @@ Thanks to spacemaniac and mcdonald for help with the JS side of this. verify = FALSE assets = list( "json2.min.js" = 'code/modules/goonchat/browserassets/js/json2.min.js', - "errorHandler.js" = 'code/modules/goonchat/browserassets/js/errorHandler.js', "browserOutput.js" = 'code/modules/goonchat/browserassets/js/browserOutput.js', "fontawesome-webfont.eot" = 'tgui/assets/fonts/fontawesome-webfont.eot', "fontawesome-webfont.svg" = 'tgui/assets/fonts/fontawesome-webfont.svg', diff --git a/code/modules/goonchat/browserassets/html/browserOutput.html b/code/modules/goonchat/browserassets/html/browserOutput.html index 28387724fed..120feb2d324 100644 --- a/code/modules/goonchat/browserassets/html/browserOutput.html +++ b/code/modules/goonchat/browserassets/html/browserOutput.html @@ -7,7 +7,6 @@ - diff --git a/code/modules/goonchat/browserassets/js/browserOutput.js b/code/modules/goonchat/browserassets/js/browserOutput.js index a2e77558c2b..d1c6280b557 100644 --- a/code/modules/goonchat/browserassets/js/browserOutput.js +++ b/code/modules/goonchat/browserassets/js/browserOutput.js @@ -6,7 +6,6 @@ ******************************************/ //DEBUG STUFF -var triggerError = attachErrorHandler('chatDebug', true); var escaper = encodeURIComponent || escape; var decoder = decodeURIComponent || unescape; window.onerror = function(msg, url, line, col, error) { diff --git a/code/modules/goonchat/browserassets/js/errorHandler.js b/code/modules/goonchat/browserassets/js/errorHandler.js deleted file mode 100644 index ebe7e324112..00000000000 --- a/code/modules/goonchat/browserassets/js/errorHandler.js +++ /dev/null @@ -1,34 +0,0 @@ -(function(window, navigator) { - - var escaper = encodeURIComponent || escape; - - var triggerError = function(msg, url, line, col, error) { - window.onerror(msg, url, line, col, error); - }; - - /** - * Directs JS errors to a byond proc for logging - * - * @param string file Name of the logfile to dump errors in, do not prepend with data/ - * @param boolean overrideDefault True to prevent default JS errors (an big honking error prompt thing) - * @return boolean - */ - var attach = function(file, overrideDefault) { - overrideDefault = typeof overrideDefault === 'undefined' ? false : overrideDefault; - file = escaper(file); - - window.onerror = function(msg, url, line, col, error) { - var extra = !col ? '' : ' | column: ' + col; - extra += !error ? '' : ' | error: ' + error; - extra += !navigator.userAgent ? '' : ' | user agent: ' + navigator.userAgent; - var debugLine = 'Error: ' + msg + ' | url: ' + url + ' | line: ' + line + extra; - window.location = '?action=debugFileOutput&file=' + file + '&message=' + escaper(debugLine); - return overrideDefault; - }; - - return triggerError; - }; - - window.attachErrorHandler = attach; - -}(window, window.navigator)); \ No newline at end of file diff --git a/code/modules/goonchat/jsErrorHandler.dm b/code/modules/goonchat/jsErrorHandler.dm deleted file mode 100644 index 3dcaebe0293..00000000000 --- a/code/modules/goonchat/jsErrorHandler.dm +++ /dev/null @@ -1,102 +0,0 @@ -/** -* This is a generic handler for logging your dumb JS errors generated by html popups -* -* 1. Add your logfile to the validFiles list -* 2. Include the "browserassets/js/errorHandler.js" file in your html file (if using chui, skip this step) (look at browserOutput.html for an example) -* 3. Call attachErrorHandler('yourLogFile'); at the top of your JS (again see browserOutput.js for an example) -*/ - -/datum/debugFileOutput - var/directory = "data/popupErrors" //where to shove all the logfiles - var/ext = "log" //file extension - var/logFileLimit = 52428800 //50mb, so yeah pretty permissive - - //Add your dumb file here. This is so some schmuck can't just shit out a bunch of spam logfiles and use all the diskspace. Relative to src.directory - var/list/validFiles = list( - "chatDebug", - "tooltipDebug", - "chemDispenser", - "banPanel", - "stationNamer" - ) - -/datum/debugFileOutput/proc/error(fileName, message, client/C) - if (!fileName || !message) - return 0 - - if (!(fileName in src.validFiles)) - CRASH("Debug log file '[fileName].[src.ext]' is not a valid path.") - - var/logFile = file("[src.directory]/[fileName].[src.ext]") - var/fileSize = length(logFile) - if (fileSize >= src.logFileLimit) - CRASH("Debug Error Handling encountered an error! This is highly ironic! File: '[fileName]' has exceeded the filesize limit of: [src.logFileLimit] bytes") - - message = "\[[time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")]\] Client: \[[C && C.key ? C.key : "Unknown Client"]\] triggered: [message]" - WRITE_FILE(logFile, message) - return 1 - -/datum/debugFileOutput/proc/clear(fileName) - if (!fileName) - return 0 - - if (!fexists("[src.directory]/[fileName].[src.ext]")) - CRASH("Debug log file '[fileName].[src.ext]' does not exist.") - - if (!(fileName in src.validFiles)) - CRASH("Debug log file '[fileName].[src.ext]' is not a valid path.") - - fdel("[src.directory]/[fileName].[src.ext]") - return 1 - -/datum/debugFileOutput/proc/clearAll() - var/list/deleted = new() - for (var/fileName in src.validFiles) - if (fexists("[src.directory]/[fileName].[src.ext]")) - fdel("[src.directory]/[fileName].[src.ext]") - deleted += fileName - - return deleted - - -GLOBAL_DATUM_INIT(debugFileOutput, /datum/debugFileOutput, new) - -/client/Topic(href, href_list) - ..() - - if (href_list["action"] && href_list["action"] == "debugFileOutput" && href_list["file"] && href_list["message"]) - var/file = href_list["file"] - var/message = href_list["message"] - GLOB.debugFileOutput.error(file, message, src) - -/client/proc/deleteJsLogFile(fileName as text) - set category = "Debug" - set name = "Delete JS Logfile" - set desc = "Delete a logfile for JS error reporting. Be sure you want to do this!" - set popup_menu = 0 - if(!holder) - return - if (!fileName) - return - - GLOB.debugFileOutput.clear(fileName) - - log_admin("[key_name(usr)] deleted the '[fileName]' JS logfile") - message_admins("[key_name_admin(usr)] deleted the '[fileName]' JS logfile") - -/client/proc/deleteAllJsLogFiles() - set category = null - set name = "Delete All JS Logfiles" - set desc = "Delete all logfiles for JS error reporting. Be extra sure you want to do this!" - - if(!holder) - return - - if (alert("Are you really sure you want to delete every single JS logfile?", "No", "Yes") == "No") - return - - var/list/summary = GLOB.debugFileOutput.clearAll() - var/friendlySummary = summary.Join(", ") - - log_admin("[key_name(usr)] deleted every JS logfile! ([friendlySummary])") - message_admins("[key_name_admin(usr)] deleted every JS logfile! ([friendlySummary])") diff --git a/tgstation.dme b/tgstation.dme index 7399b048833..b0f47e20f9a 100755 --- a/tgstation.dme +++ b/tgstation.dme @@ -1744,7 +1744,6 @@ #include "code\modules\food_and_drinks\recipes\tablecraft\recipes_spaghetti.dm" #include "code\modules\games\cas.dm" #include "code\modules\goonchat\browserOutput.dm" -#include "code\modules\goonchat\jsErrorHandler.dm" #include "code\modules\holiday\easter.dm" #include "code\modules\holiday\holidays.dm" #include "code\modules\holodeck\area_copy.dm"