From 681ba6fc3c296cd6cd11050531b8f4e785141786 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Tue, 16 Dec 2014 07:28:48 -0500 Subject: [PATCH] Improve system security by using optional special URL with security token Allows to define separate server/path for image/js/css files Fix bugs where CSRF attacks were still possible on some requests --- program/js/app.js | 43 +++++++++++++++++++++++++++++++++++-------- 1 files changed, 35 insertions(+), 8 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index fd0d2e1..4e65a9c 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -58,7 +58,6 @@ request_timeout: 180, // seconds draft_autosave: 0, // seconds comm_path: './', - blankpage: 'program/resources/blank.gif', recipients_separator: ',', recipients_delimiter: ', ', popup_width: 1150, @@ -162,6 +161,9 @@ this.goto_url('error', '_code=0x199'); return; } + + if (!this.env.blankpage) + this.env.blankpage = this.assets_path('program/resources/blank.gif'); // find all registered gui containers for (n in this.gui_containers) @@ -630,8 +632,9 @@ if (obj && obj.blur && !(event && rcube_event.is_keyboard(event))) obj.blur(); - // do nothing if interface is locked by other command (with exception for searching reset) - if (this.busy && !(command == 'reset-search' && this.last_command == 'search')) + // do nothing if interface is locked by another command + // with exception for searching reset and menu + if (this.busy && !(command == 'reset-search' && this.last_command == 'search') && !command.match(/^menu-/)) return false; // let the browser handle this click (shift/ctrl usually opens the link in a new window/tab) @@ -1405,8 +1408,10 @@ if (task == 'mail') url += '&_mbox=INBOX'; - else if (task == 'logout' && !this.env.server_error) + else if (task == 'logout' && !this.env.server_error) { + url += '&_token=' + this.env.request_token; this.clear_compose_data(); + } this.redirect(url); }; @@ -1416,7 +1421,10 @@ if (!url) url = this.env.comm_path; - return url.replace(/_task=[a-z0-9_-]+/i, '_task='+task); + if (url.match(/[?&]_task=[a-zA-Z0-9_-]+/)) + return url.replace(/_task=[a-zA-Z0-9_-]+/, '_task=' + task); + else + return url.replace(/\?.*$/, '') + '?_task=' + task; }; this.reload = function(delay) @@ -2027,7 +2035,7 @@ } if (flags.forwarded) { status_class += ' forwarded'; - status_label += this.get_label('replied') + ' '; + status_label += this.get_label('forwarded') + ' '; } // update selection @@ -3426,6 +3434,7 @@ this.get_label('restoremessage'), [{ text: this.get_label('restore'), + 'class': 'mainaction', click: function(){ ref.restore_compose_form(key, html_mode); ref.remove_compose_data(key); // remove old copy @@ -3435,6 +3444,7 @@ }, { text: this.get_label('delete'), + 'class': 'delete', click: function(){ ref.remove_compose_data(key); $(this).dialog('close'); @@ -3687,7 +3697,7 @@ $(this).dialog('close'); }; - this.show_popup_dialog(html, this.gettext('newresponse'), buttons); + this.show_popup_dialog(html, this.gettext('newresponse'), buttons, {button_classes: ['mainaction']}); $('#ffresponsetext').val(text); $('#ffresponsename').select(); @@ -5173,6 +5183,7 @@ this.show_popup_dialog(content, this.get_label('newgroup'), [{ text: this.get_label('save'), + 'class': 'mainaction', click: function() { var name; @@ -5200,6 +5211,7 @@ this.show_popup_dialog(content, this.get_label('grouprename'), [{ text: this.get_label('save'), + 'class': 'mainaction', click: function() { var name; @@ -5563,6 +5575,7 @@ this.show_popup_dialog(content, this.get_label('searchsave'), [{ text: this.get_label('save'), + 'class': 'mainaction', click: function() { var name; @@ -6564,6 +6577,11 @@ popup.dialog('option', { height: Math.min(h - 40, height + 75 + (buttons ? 50 : 0)), width: Math.min(w - 20, width + 36) + }); + + // assign special classes to dialog buttons + $.each(options.button_classes || [], function(i, v) { + if (v) $($('.ui-dialog-buttonpane button.ui-button', popup.parent()).get(i)).addClass(v); }); return popup; @@ -8028,7 +8046,7 @@ img.onload = function() { ref.env.browser_capabilities.tif = 1; }; img.onerror = function() { ref.env.browser_capabilities.tif = 0; }; - img.src = 'program/resources/blank.tif'; + img.src = this.assets_path('program/resources/blank.tif'); }; this.pdf_support_check = function() @@ -8085,6 +8103,15 @@ return 0; }; + this.assets_path = function(path) + { + if (this.env.assets_path && !path.startsWith(this.env.assets_path)) { + path = this.env.assets_path + path; + } + + return path; + }; + // Cookie setter this.set_cookie = function(name, value, expires) { -- Gitblit v1.9.1