From 248a42af7efef7d54b446ccfaa25c99c7e6853ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 1 Mar 2017 09:33:18 +0100 Subject: [PATCH] Fixed javascript confirmation of dangerous queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The confirmations did work properly only in console and not anywhere else. - the check function was expecting textarea, while it got text from other calls - the check for empty form was completely outdated, but that seems to lead only to dead code and no breakage - for the inline editor, the form was not properly focused and restored on confirmation error Signed-off-by: Michal Čihař --- ChangeLog | 1 + js/console.js | 2 +- js/functions.js | 40 +++++++++++++++++++--------------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43e66fc66a..82b0a47beb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -87,6 +87,7 @@ phpMyAdmin - ChangeLog - issue Hide comments on table Structure tab when no comment is set - issue Fixed submission of error reports - issue #13033 Use Referrer-Policy header to specify referrer policy +- issue Fixed javascript confirmation of dangerous queries 4.6.6 (2017-01-23) - issue #12759 Fix Notice regarding 'Undefined index: old_usergroup' diff --git a/js/console.js b/js/console.js index 4101123ce1..40df21e325 100644 --- a/js/console.js +++ b/js/console.js @@ -250,7 +250,7 @@ var PMA_console = { if (options && options.profiling === true) { PMA_console.$requestForm.append(''); } - if (! confirmQuery(PMA_console.$requestForm[0], PMA_console.$requestForm.children('textarea')[0])) { + if (! confirmQuery(PMA_console.$requestForm[0], PMA_console.$requestForm.children('textarea')[0].value)) { return; } PMA_console.$requestForm.children('[name=console_message_id]') diff --git a/js/functions.js b/js/functions.js index 0dbba5ac07..89eefb4a86 100644 --- a/js/functions.js +++ b/js/functions.js @@ -672,7 +672,7 @@ function confirmLink(theLink, theSqlQuery) * This function is called by the 'checkSqlQuery()' js function. * * @param theForm1 object the form - * @param sqlQuery1 object the sql query textarea + * @param sqlQuery1 string the sql query string * * @return boolean whether to run the query or not * @@ -697,15 +697,15 @@ function confirmQuery(theForm1, sqlQuery1) var do_confirm_re_2 = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i'); var do_confirm_re_3 = new RegExp('^\\s*TRUNCATE\\s', 'i'); - if (do_confirm_re_0.test(sqlQuery1.value) || - do_confirm_re_1.test(sqlQuery1.value) || - do_confirm_re_2.test(sqlQuery1.value) || - do_confirm_re_3.test(sqlQuery1.value)) { + if (do_confirm_re_0.test(sqlQuery1) || + do_confirm_re_1.test(sqlQuery1) || + do_confirm_re_2.test(sqlQuery1) || + do_confirm_re_3.test(sqlQuery1)) { var message; - if (sqlQuery1.value.length > 100) { - message = sqlQuery1.value.substr(0, 100) + '\n ...'; + if (sqlQuery1.length > 100) { + message = sqlQuery1.substr(0, 100) + '\n ...'; } else { - message = sqlQuery1.value; + message = sqlQuery1; } var is_confirmed = confirm(PMA_sprintf(PMA_messages.strDoYouReally, message)); // statement is confirmed -> update the @@ -718,7 +718,6 @@ function confirmQuery(theForm1, sqlQuery1) // statement is rejected -> do not submit the form else { window.focus(); - sqlQuery1.focus(); return false; } // end if (handle confirm box result) } // end if (display confirm box) @@ -746,31 +745,30 @@ function checkSqlQuery(theForm) } else { sqlQuery = theForm.elements.sql_query.value; } - var isEmpty = 1; var space_re = new RegExp('\\s+'); if (typeof(theForm.elements.sql_file) != 'undefined' && theForm.elements.sql_file.value.replace(space_re, '') !== '') { return true; } - if (isEmpty && typeof(theForm.elements.id_bookmark) != 'undefined' && + if (typeof(theForm.elements.id_bookmark) != 'undefined' && (theForm.elements.id_bookmark.value !== null || theForm.elements.id_bookmark.value !== '') && theForm.elements.id_bookmark.selectedIndex !== 0) { return true; } + var result = false; // Checks for "DROP/DELETE/ALTER" statements if (sqlQuery.replace(space_re, '') !== '') { - return confirmQuery(theForm, sqlQuery); - } - theForm.reset(); - isEmpty = 1; - - if (isEmpty) { + result = confirmQuery(theForm, sqlQuery); + } else { alert(PMA_messages.strFormEmpty); - codemirror_editor.focus(); - return false; } - return true; + if (codemirror_editor) { + codemirror_editor.focus(); + } else if (codemirror_inline_editor) { + codemirror_inline_editor.focus(); + } + return result; } // end of the 'checkSqlQuery()' function /** @@ -1911,7 +1909,6 @@ AJAX.registerOnload('functions.js', function () { }); $(document).on('click', "input#sql_query_edit_save", function () { - $(".success").hide(); //hide already existing success message var sql_query; if (codemirror_inline_editor) { @@ -1932,6 +1929,7 @@ AJAX.registerOnload('functions.js', function () { if (! checkSqlQuery($fake_form[0])) { return false; } + $(".success").hide(); $fake_form.appendTo($('body')).submit(); });