Skip to content

Commit 8a2db57

Browse files
VINADES.,JSCvuthao
VINADES.,JSC
authored andcommitted
Fix CSRF for modules database
1 parent e9e8890 commit 8a2db57

File tree

5 files changed

+9
-22
lines changed

5 files changed

+9
-22
lines changed

admin/database/sampledata.php

+2-16
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,13 @@
6565
nv_htmlOutput('Wrong URL');
6666
}
6767
$sname = nv_strtolower(nv_substr($nv_Request->get_title('sname', 'post', ''), 0, 50));
68-
if (preg_match('/^([a-z0-9]+)$/', $sname) and file_exists(NV_ROOTDIR . '/install/samples/data_' . $sname . '.php')) {
68+
if ($nv_Request->get_string('delete', 'post') == md5(NV_CHECK_SESSION . '_' . $module_name . '_' . $op . '_' . $sname) and preg_match('/^([a-z0-9]+)$/', $sname) and file_exists(NV_ROOTDIR . '/install/samples/data_' . $sname . '.php')) {
6969
nv_deletefile(NV_ROOTDIR . '/install/samples/data_' . $sname . '.php');
7070
nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['sampledata'], 'Delete: ' . $sname, $admin_info['userid']);
7171
}
7272
nv_htmlOutput('OK');
7373
}
7474

75-
// Tải về file dữ liệu
76-
if ($nv_Request->isset_request('downloadfile', 'get')) {
77-
$sample_name = nv_strtolower(nv_substr($nv_Request->get_title('sample_name', 'get', ''), 0, 50));
78-
79-
if (!file_exists($file_data_dump) or !preg_match('/^([a-z0-9]+)$/', $sample_name)) {
80-
nv_redirect_location(NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op);
81-
}
82-
83-
nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['sampledata'], 'Manual Download: ' . $sample_name, $admin_info['userid']);
84-
85-
$download = new NukeViet\Files\Download($file_data_dump, NV_ROOTDIR . '/' . NV_TEMP_DIR, 'data_' . $sample_name . '.php');
86-
$download->download_file();
87-
exit();
88-
}
89-
9075
// Tiến trình quét bằng AJAX
9176
if ($nv_Request->isset_request('startwrite', 'get')) {
9277
if ($sys_info['ini_set_support']) {
@@ -355,6 +340,7 @@
355340
$xtpl->parse('main.empty');
356341
} else {
357342
foreach ($array as $row) {
343+
$row['checkss'] = md5(NV_CHECK_SESSION . '_' . $module_name . '_' . $op . '_' . $row['title']);
358344
$xtpl->assign('ROW', $row);
359345
$xtpl->parse('main.data.loop');
360346
}

admin/database/setting.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
$page_title = $lang_global['mod_settings'];
1616
$array_sql_ext = array( 'sql', 'gz' );
1717

18-
$errormess = '';
1918
$array_config_global = array();
2019
$array_config_global['dump_backup_day'] = $global_config['dump_backup_day'];
2120
$array_config_global['dump_backup_ext'] = $global_config['dump_backup_ext'];
2221
$array_config_global['dump_interval'] = $global_config['dump_interval'];
2322

24-
if ($nv_Request->isset_request('submit', 'post')) {
23+
$checkss = md5(NV_CHECK_SESSION . '_' . $module_name . '_' . $op . '_' . $admin_info['userid']);
24+
if ($checkss == $nv_Request->get_string('checkss', 'post')) {
2525
$array_config_global = array();
2626
$array_config_global['dump_backup_ext'] = $nv_Request->get_title('dump_backup_ext', 'post', '', 1);
2727
$array_config_global['dump_autobackup'] = $nv_Request->get_int('dump_autobackup', 'post');
@@ -56,6 +56,7 @@
5656
$xtpl->assign('LANG', $lang_module);
5757
$xtpl->assign('GLANG', $lang_global);
5858
$xtpl->assign('DATA', $array_config_global);
59+
$xtpl->assign('CHECKSS', $checkss);
5960

6061
foreach ($array_sql_ext as $ext_i) {
6162
$xtpl->assign('BACKUPEXTSELECTED', ($ext_i == $array_config_global['dump_backup_ext']) ? ' selected="selected"' : '');

themes/admin_default/js/database.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ function nv_show_highlight(tp) {
8383
return false;
8484
}
8585

86-
function nv_delete_sampledata(sname) {
86+
function nv_delete_sampledata(sname, checkss) {
8787
if (confirm(nv_is_del_confirm[0])) {
88-
$.post(script_name + '?' + nv_name_variable + '=' + nv_module_name + '&' + nv_fc_variable + '=sampledata&nocache=' + new Date().getTime(), 'delete=1&sname=' + encodeURIComponent(sname), function(res) {
88+
$.post(script_name + '?' + nv_name_variable + '=' + nv_module_name + '&' + nv_fc_variable + '=sampledata&nocache=' + new Date().getTime(), 'delete=' + checkss + '&sname=' + encodeURIComponent(sname), function(res) {
8989
window.location.reload(true);
9090
});
9191
}

themes/admin_default/modules/database/sampledata.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<div class="col-sm-16"><strong>{ROW.title}</strong></div>
5454
<div class="col-sm-8">
5555
{ROW.creattime}
56-
<a href="javascript:void(0);" class="pull-right text-danger" onclick="nv_delete_sampledata('{ROW.title}');"><i class="fa fa-trash-o"></i></a>
56+
<a href="javascript:void(0);" class="pull-right text-danger" onclick="nv_delete_sampledata('{ROW.title}', '{ROW.checkss}');"><i class="fa fa-trash-o"></i></a>
5757
</div>
5858
</div>
5959
</div>

themes/admin_default/modules/database/setting.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<table class="table table-striped table-bordered table-hover">
55
<tfoot>
66
<tr>
7-
<td colspan="2"><input type="submit" name="submit" value="{LANG.submit}" class="btn btn-primary" /></td>
7+
<td colspan="2"><input type="hidden" name="checkss" value="{CHECKSS}" /><input type="submit" name="submit" value="{LANG.submit}" class="btn btn-primary" /></td>
88
</tr>
99
</tfoot>
1010
<tbody>

0 commit comments

Comments
 (0)