Skip to content

Commit

Permalink
Arbitrary File Actions in import_template.php, make ajax csrf token t…
Browse files Browse the repository at this point in the history
…o be a string, add csrf token to template import
  • Loading branch information
Ngai-E committed Aug 13, 2020
1 parent b685a0c commit 9cf84f6
Show file tree
Hide file tree
Showing 36 changed files with 113 additions and 71 deletions.
8 changes: 4 additions & 4 deletions interface/patient_file/encounter/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
{ amc_id: "patient_edu_amc",
complete: true,
mode: mode,
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>,
object_category: "form_encounter",
object_id: <?php echo htmlspecialchars($encounter,ENT_NOQUOTES); ?>
Expand All @@ -126,7 +126,7 @@
{ amc_id: "provide_sum_pat_amc",
complete: true,
mode: mode,
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>,
object_category: "form_encounter",
object_id: <?php echo htmlspecialchars($encounter,ENT_NOQUOTES); ?>
Expand All @@ -151,7 +151,7 @@
{ amc_id: "med_reconc_amc",
complete: false,
mode: mode,
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>,
object_category: "form_encounter",
object_id: <?php echo htmlspecialchars($encounter,ENT_NOQUOTES); ?>
Expand All @@ -171,7 +171,7 @@
{ amc_id: "med_reconc_amc",
complete: true,
mode: mode,
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>,
object_category: "form_encounter",
object_id: <?php echo htmlspecialchars($encounter,ENT_NOQUOTES); ?>
Expand Down
6 changes: 3 additions & 3 deletions interface/patient_file/reminder/clinical_reminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
type: 'passive_alert',
setting: this.value,
patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>',
token: <?php echo $_SESSION['token'];?>
token: "<?php echo $_SESSION['token'];?>"
});
});

Expand All @@ -254,7 +254,7 @@
type: 'active_alert',
setting: this.value,
patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>',
token: <?php echo $_SESSION['token'];?>
token: "<?php echo $_SESSION['token'];?>"
});
});

Expand All @@ -265,7 +265,7 @@
type: 'normal',
setting: this.value,
patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>',
token: <?php echo $_SESSION['token'];?>
token: "<?php echo $_SESSION['token'];?>"
});
});

Expand Down
9 changes: 5 additions & 4 deletions interface/patient_file/reminder/patient_reminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function sel_patient() {
type: 'patient_reminder',
setting: this.value,
patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>',
token: <?php echo $_SESSION['token'];?>
token: "<?php echo $_SESSION['token'];?>"
});
});

Expand All @@ -362,7 +362,7 @@ function ReminderBatch(processType) {

top.restoreSession();
$.get("../../../library/ajax/collect_new_report_id.php",
{token: <?php echo $_SESSION['token'];?>},
{token: "<?php echo $_SESSION['token'];?>"},
function(data){
// Set the report id in page form
$("#form_new_report_id").attr("value",data);
Expand All @@ -374,7 +374,8 @@ function(data){
top.restoreSession();
$.post("../../../library/ajax/execute_pat_reminder.php",
{process_type: processType,
execute_report_id: $("#form_new_report_id").val()
execute_report_id: $("#form_new_report_id").val(),
token: "<?php echo $_SESSION['token'];?>"
});
});

Expand All @@ -386,7 +387,7 @@ function collectStatus(report_id) {
top.restoreSession();
// Do not send the skip_timeout_reset parameter, so don't close window before report is done.
$.post("../../../library/ajax/status_report.php",
{status_report_id: report_id, token: <?php echo $_SESSION['token'];?> },
{status_report_id: report_id, token: "<?php echo $_SESSION['token'];?>" },
function(data){
if (data == "PENDING") {
// Place the pending string in the DOM
Expand Down
4 changes: 2 additions & 2 deletions interface/patient_file/summary/demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ function toggleIndicator(target,div) {
if ( $mode == "<?php echo htmlspecialchars(xl('collapse'),ENT_QUOTES); ?>" ) {
$(target).find(".indicator").text( "<?php echo htmlspecialchars(xl('expand'),ENT_QUOTES); ?>" );
$("#"+div).hide();
$.post( "../../../library/ajax/user_settings.php", { target: div, mode: 0 , token: <?php echo $_SESSION['token'];?> });
$.post( "../../../library/ajax/user_settings.php", { target: div, mode: 0 , token: "<?php echo $_SESSION['token'];?>" });
} else {
$(target).find(".indicator").text( "<?php echo htmlspecialchars(xl('collapse'),ENT_QUOTES); ?>" );
$("#"+div).show();
$.post( "../../../library/ajax/user_settings.php", { target: div, mode: 1 , token: <?php echo $_SESSION['token'];?>});
$.post( "../../../library/ajax/user_settings.php", { target: div, mode: 1 , token: "<?php echo $_SESSION['token'];?>"});
}
}

Expand Down
2 changes: 1 addition & 1 deletion interface/patient_file/summary/stats_full.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function newEncounter() {

$(".noneCheck").click(function() {
top.restoreSession();
$.post( "../../../library/ajax/lists_touch.php", { type: this.name, patient_id: <?php echo htmlspecialchars($pid,ENT_QUOTES); ?> });
$.post( "../../../library/ajax/lists_touch.php", { type: this.name, patient_id: <?php echo htmlspecialchars($pid,ENT_QUOTES); ?>, token: "<?php echo $_SESSION['token'];?>" });
$(this).hide();
});
});
Expand Down
2 changes: 1 addition & 1 deletion interface/patient_file/transaction/record_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{ amc_id: "provide_rec_pat_amc",
complete: false,
mode: "add_force",
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>
}
);
Expand Down
2 changes: 1 addition & 1 deletion interface/patient_tracker/patient_tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ function validateForm() {
}
$.post( "../../library/ajax/drug_screen_completed.php", {
trackerid: this.id,
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
testcomplete: testcomplete_toggle
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function show_all_diags(){
ethnicity:"<?php echo $_POST['ethnicity']; ?>",
age_from:"<?php echo $_POST['age_from'] ; ?>",
age_to:"<?php echo $_POST['age_to'] ; ?>",
token: <?php echo $_SESSION['token'];?>
token: "<?php echo $_SESSION['token'];?>"

}, complete: function(){
$('#image').hide();
Expand Down
2 changes: 1 addition & 1 deletion interface/reports/lab_stats_by_demographics_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function lab_result_details() {
age_to:"<?php echo $_POST['age_to'] ; ?>",
results_per_page: $('#rpp').val(),
page_number: $('#nof').val(),
token: <?php echo $_SESSION['token'];?>
token: "<?php echo $_SESSION['token'];?>"

}, complete: function(){
$('#image').hide();
Expand Down
6 changes: 3 additions & 3 deletions interface/reports/username_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function show_session_times(){
func:"show_session_times",
to_date: "<?php echo $to_date; ?>",
from_date:" <?php echo $from_date; ?> ",
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
}, complete: function(){
$('#image').hide();
}},
Expand Down Expand Up @@ -162,7 +162,7 @@ function show_session_sums()
func:"show_session_sums",
to_date: "<?php echo $to_date; ?>",
from_date:" <?php echo $from_date; ?> ",
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
},
complete: function(){
$('#image').hide();
Expand Down Expand Up @@ -233,7 +233,7 @@ function show_session_details()
func:"show_session_details",
to_date: "<?php echo $to_date; ?>",
from_date:" <?php echo $from_date; ?> ",
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
},
complete: function(){
$('#image').hide();
Expand Down
5 changes: 2 additions & 3 deletions interface/super/edit_globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@

if (!empty($_POST)) {
if (!isset($_POST['token'])) {
error_log('WARNING: A POST request detected with no csrf token found');
die('Authentication failed.');
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfTokenAndCompareHash($_POST['token'], '/edit_globals.php.theform'))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}

Expand Down
5 changes: 2 additions & 3 deletions interface/super/edit_layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ function addOrDeleteColumn($layout_id, $field_id, $add=TRUE) {

if (!empty($_POST)) {
if (!isset($_POST['token'])) {
error_log('WARNING: A POST request detected with no csrf token found');
die('Authentication failed.');
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfTokenAndCompareHash($_POST['token'], '/edit_layout.php.theform'))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}

Expand Down
5 changes: 2 additions & 3 deletions interface/super/edit_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@

if (!empty($_POST)) {
if (!isset($_POST['token'])) {
error_log('WARNING: A POST request detected with no csrf token found');
die('Authentication failed.');
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfTokenAndCompareHash($_POST['token'], '/edit_list.php.theform'))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}

Expand Down
2 changes: 1 addition & 1 deletion interface/super/field_id_popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
if (!isset($_GET['token'])) {
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfToken($_GET['token']))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}
$source = empty($_REQUEST['source']) ? 'D' : $_REQUEST['source'];
Expand Down
2 changes: 1 addition & 1 deletion interface/super/layout_listitems_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if (!isset($_GET['token'])) {
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfToken($_GET['token']))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}
$listid = $_GET['listid'];
Expand Down
5 changes: 2 additions & 3 deletions interface/super/load_codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@

if (!empty($_POST)) {
if (!isset($_POST['token'])) {
error_log('WARNING: A POST request detected with no csrf token found');
die('Authentication failed.');
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfTokenAndCompareHash($_POST['token'], '/load_codes.php.theform'))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}

Expand Down
5 changes: 2 additions & 3 deletions interface/super/manage_document_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@

if (!empty($_POST)) {
if (!isset($_POST['token'])) {
error_log('WARNING: A POST request detected with no csrf token found');
die('Authentication failed.');
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfTokenAndCompareHash($_POST['token'], '/manage_document_templates.php.theform'))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}

Expand Down
5 changes: 2 additions & 3 deletions interface/super/manage_site_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@

if (!empty($_POST)) {
if (!isset($_POST['token'])) {
error_log('WARNING: A POST request detected with no csrf token found');
die('Authentication failed.');
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfTokenAndCompareHash($_POST['token'], '/manage_site_files.php.theform'))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}

Expand Down
10 changes: 5 additions & 5 deletions interface/usergroup/adminacl.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
data: {
control: "acl",
action: "add",
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
title: title,
identifier: identifier,
return_value: return_value,
Expand Down Expand Up @@ -161,7 +161,7 @@
data: {
control: "acl",
action: "remove",
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
title: title,
return_value: return_value
},
Expand Down Expand Up @@ -210,7 +210,7 @@ function membership_show() {
dataType: "xml",
data: {
control: "username",
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
action: "list"
},
success: function(xml){
Expand Down Expand Up @@ -260,7 +260,7 @@ function acl_show() {
dataType: "xml",
data: {
control: "acl",
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
action: "list"
},
success: function(xml){
Expand Down Expand Up @@ -375,7 +375,7 @@ function generic_click(cthis) {
data: {
name: identityFormatted,
control: control,
token: <?php echo $_SESSION['token'];?>,
token: "<?php echo $_SESSION['token'];?>",
action: action,
'selection[]': selected,
return_value: return_value
Expand Down
5 changes: 5 additions & 0 deletions library/CsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ function verifyCsrfToken($token)
//log error and kill the page
function noTokenFoundError() {
error_log('WARNING: A POST request detected with no csrf token found');
header('HTTP/1.1 401 Unauthorized');
die('Authentication failed.');
}
function incorrectToken() {
header('HTTP/1.1 401 Unauthorized');
die('Authentication failed.');
}
// Function to verify a csrf token using with second token
Expand Down
2 changes: 1 addition & 1 deletion library/ajax/adminacl_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
if (!isset($_POST['token'])) {
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfToken($_POST['token']))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}
//Display red alert if Emergency Login ACL is activated for a user.
Expand Down
2 changes: 1 addition & 1 deletion library/ajax/amc_misc_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
if (!isset($_POST['token'])) {
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfToken($_POST['token']))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}

processAmcCall($_POST['amc_id'], $_POST['complete'], $_POST['mode'], $_POST['patient_id'], $_POST['object_category'], $_POST['object_id'], $_POST['date_created']);
Expand Down
2 changes: 1 addition & 1 deletion library/ajax/execute_background_services.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
if (!isset($_POST['token'])) {
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfToken($_POST['token']))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/ajax/payment_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
if (!empty($_REQUEST)) {
if (!isset($_REQUEST['token'])) {
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfToken($_REQUEST['token']))) {
die('Authentication failed.');
} else if (!(CsrfToken::verifyCsrfToken($_POST['token']))) {
CsrfToken::incorrectToken();
}
}
//=================================
Expand Down
2 changes: 1 addition & 1 deletion library/ajax/payment_ajax_jav.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function ajaxFunction(Source,SubmitOrSimple,SourceObject) {
insurance_text_ajax: document.getElementById('type_code') ? document.getElementById('type_code').value : '',
encounter_patient_code:Source=='encounter' ? document.getElementById('hidden_patient_code').value : '',
submit_or_simple_type:SubmitOrSimple,
token: <?php echo $_SESSION['token'];?>
token: "<?php echo $_SESSION['token'];?>",
},
//async: false,
success: function(thedata){
Expand Down
2 changes: 1 addition & 1 deletion library/ajax/plan_setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
if (!isset($_POST['token'])) {
CsrfToken::noTokenFoundError();
} else if (!(CsrfToken::verifyCsrfToken($_POST['token']))) {
die('Authentication failed.');
CsrfToken::incorrectToken();
}
}
//set the rule setting for patient (ensure all variables exist)
Expand Down
Loading

0 comments on commit 9cf84f6

Please sign in to comment.