Close the critical holes found in the security audit
- .htaccess: 404 for dotfiles (.git etc.), logs/dumps/archives, composer files, vendor/, documents/, archive/ - Pages::ajax: changeUserStatus, checkUser and refreshLogMonitor now require a logged-in admin or module user; the operator is logged from the session, not the request - Public worker JSON only returns worker_id and worker_name (no ntfy topic or calendar ID) - Admin: the five worker-schedule methods now redirect to login without a session Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3569539376
commit
3440188c0f
@@ -130,6 +130,7 @@ class Admin extends CI_Controller {
|
||||
}
|
||||
|
||||
public function worker_schedule_overrides() {
|
||||
$this->_requireLogin();
|
||||
$this->load->model('Service_model');
|
||||
$data['currentUser'] = $this->User_model->getUserByUsername($_SESSION['username']);
|
||||
$data['workerSchedules'] = $this->Service_model->getWorkerScheduleOverrides();
|
||||
@@ -139,6 +140,7 @@ class Admin extends CI_Controller {
|
||||
}
|
||||
|
||||
public function admin_worker_schedule() {
|
||||
$this->_requireLogin();
|
||||
$this->load->helper('url');
|
||||
$this->load->model('User_model');
|
||||
$this->load->model('Service_model');
|
||||
@@ -174,6 +176,7 @@ class Admin extends CI_Controller {
|
||||
}
|
||||
|
||||
public function store_worker_schedule() {
|
||||
$this->_requireLogin();
|
||||
$this->load->model('Service_model');
|
||||
$this->load->helper('url');
|
||||
|
||||
@@ -212,6 +215,7 @@ class Admin extends CI_Controller {
|
||||
|
||||
|
||||
public function manage_worker_schedule($worker_id = null) {
|
||||
$this->_requireLogin();
|
||||
$this->load->model('Service_model');
|
||||
$data['workers'] = $this->Service_model->getAllWorkers();
|
||||
$data['selectedWorker'] = null;
|
||||
@@ -226,6 +230,7 @@ class Admin extends CI_Controller {
|
||||
}
|
||||
|
||||
public function save_worker_schedule() {
|
||||
$this->_requireLogin();
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$worker_id = $this->input->post('worker_id');
|
||||
@@ -1358,6 +1363,20 @@ class Admin extends CI_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop here unless an admin is logged in. Every public method of this
|
||||
* controller is reachable at /admin/<method> through CodeIgniter's default
|
||||
* routing, routed or not, so each one must check the session itself.
|
||||
*/
|
||||
private function _requireLogin(){
|
||||
$this->load->helper('url');
|
||||
$this->load->model('User_model');
|
||||
if(empty($_SESSION['username']) || !is_object($this->User_model->getUserByUsername($_SESSION['username']))){
|
||||
header("Location:".SITEURL."login");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function _ntfy($title, $message, $workerTopic = null){
|
||||
$this->config->load('google_calendar');
|
||||
$evelinTopic = $this->config->item('ntfy_topic');
|
||||
|
||||
@@ -136,6 +136,23 @@ class Pages extends CI_Controller {
|
||||
|
||||
$data['pageTitle'] = '';
|
||||
|
||||
// Admin-only actions. /ajax is a public endpoint (the booking form uses it),
|
||||
// so these must check the session themselves: without this, anyone could
|
||||
// disable the admin accounts, enumerate usernames or read the full system
|
||||
// log (guest names, e-mails, phones). Same access rule as UserManagement:
|
||||
// admins, or users granted the module.
|
||||
$adminActions = array(
|
||||
'changeUserStatus' => 'user-management',
|
||||
'checkUser' => 'user-management',
|
||||
'refreshLogMonitor' => 'log-monitor',
|
||||
);
|
||||
if(isset($_POST['action']) && is_string($_POST['action']) && isset($adminActions[$_POST['action']])
|
||||
&& !$this->_ajaxUserCan($adminActions[$_POST['action']])){
|
||||
$this->output->set_status_header(403);
|
||||
echo json_encode(array('error' => 'forbidden'));
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($_POST['action']) && $_POST['action'] == 'getAvailableWorkersByServiceCategory' && isset($_POST['serv_cat_slug'])){
|
||||
// The picker must only offer workers who can perform EVERY service the
|
||||
// guest has ticked. service_ids is supplied by the booking form; when it
|
||||
@@ -180,8 +197,21 @@ class Pages extends CI_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Public response: only what the booking page needs. The full worker
|
||||
// rows carry ntfy_topic (anyone knowing it can read every booking
|
||||
// notification) and google_calendar_id.
|
||||
$publicWorkers = array();
|
||||
if(is_array($workers)){
|
||||
foreach($workers as $workerItem){
|
||||
$publicWorkers[] = array(
|
||||
'worker_id' => $workerItem->worker_id,
|
||||
'worker_name' => $workerItem->worker_name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$responseArray = array(
|
||||
'workers' => $workers,
|
||||
'workers' => $publicWorkers,
|
||||
'workerListShow' => $workerListShow
|
||||
);
|
||||
|
||||
@@ -284,10 +314,10 @@ class Pages extends CI_Controller {
|
||||
if(isset($_POST['action']) && $_POST['action'] == 'changeUserStatus' && isset($_POST['user_id']) && isset($_POST['newValue']) && isset($_POST['operator'])){
|
||||
$data['currentUser'] = $this->User_model->getUserById($_POST['user_id']);
|
||||
$userArray = array(
|
||||
'is_enabled' => $_POST['newValue']
|
||||
'is_enabled' => $_POST['newValue'] ? 1 : 0
|
||||
);
|
||||
$this->User_model->updateUser($_POST['user_id'], $userArray);
|
||||
$this->Log_model->addLog('change_user_status', $data['currentUser']->username.' státusza változott - '.($_POST['newValue']?'aktív':'letiltva').' állapotra', $_POST['operator']);
|
||||
$this->Log_model->addLog('change_user_status', $data['currentUser']->username.' státusza változott - '.($_POST['newValue']?'aktív':'letiltva').' állapotra', $_SESSION['username']);
|
||||
}
|
||||
|
||||
if(isset($_POST['action']) && $_POST['action'] == 'checkUser'){
|
||||
@@ -310,6 +340,25 @@ class Pages extends CI_Controller {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* True if the logged-in user may use an admin AJAX action: an enabled admin,
|
||||
* or a user granted the given module.
|
||||
*/
|
||||
private function _ajaxUserCan($moduleSlug){
|
||||
if(empty($_SESSION['username'])){
|
||||
return false;
|
||||
}
|
||||
$user = $this->User_model->getUserByUsername($_SESSION['username']);
|
||||
if(!is_object($user) || !$user->is_enabled){
|
||||
return false;
|
||||
}
|
||||
if($user->permission_slug == 'admin'){
|
||||
return true;
|
||||
}
|
||||
$this->load->model('Module_model');
|
||||
return (bool)$this->Module_model->user_can_access_this_module($moduleSlug, $user->user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a guest-facing error page instead of raw JSON. The public booking
|
||||
* form is a normal full-page POST, so whatever this outputs is what the
|
||||
|
||||
Reference in New Issue
Block a user