-
-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix permissions issues on main.queries and users.queries. #4400
Changes from 1 commit
955d43e
35e2b47
3433909
7aaf9a1
e46c17a
c7f7f80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -425,26 +425,69 @@ function userHandler(string $post_type, array|null|string $dataReceived, array $ | |
*/ | ||
function mailHandler(string $post_type, /*php8 array|null|string */$dataReceived, array $SETTINGS): string | ||
{ | ||
$session = SessionManager::getSession(); | ||
|
||
switch ($post_type) { | ||
/* | ||
* CASE | ||
* Send email | ||
*/ | ||
* CASE | ||
* Send email | ||
*/ | ||
case 'mail_me'://action_mail | ||
return sendMailToUser( | ||
filter_var($dataReceived['receipt'], FILTER_SANITIZE_FULL_SPECIAL_CHARS), | ||
$dataReceived['body'], | ||
(string) filter_var($dataReceived['subject'], FILTER_SANITIZE_FULL_SPECIAL_CHARS), | ||
(array) filter_var_array( | ||
$dataReceived['pre_replace'], | ||
FILTER_SANITIZE_FULL_SPECIAL_CHARS | ||
// Get info about user to send email | ||
$data_user = DB::queryfirstrow( | ||
'SELECT admin, gestionnaire, can_manage_all_users, isAdministratedByRole FROM ' . prefixTable('users') . ' | ||
WHERE email = %s', | ||
$post_id | ||
); | ||
|
||
// Only administrators and managers can send mails | ||
if ( | ||
// Administrator user | ||
(int) $session->get('user-admin') === 1 | ||
// Manager of basic/ro users in this role but don't allow promote user to admin or managers roles | ||
|| ((int) $session->get('user-manager') === 1 | ||
&& in_array($data_user['isAdministratedByRole'], $session->get('user-roles_array')) | ||
&& (int) $post_is_admin !== 1 && (int) $data_user['admin'] !== 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for $post_is_admin, $post_is_hr and $post_is_manager There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy/paste error. |
||
&& (int) $post_is_hr !== 1 && (int) $data_user['can_manage_all_users'] !== 1 | ||
&& (int) $post_is_manager !== 1 && (int) $data_user['gestionnaire'] !== 1) | ||
// Manager of all basic/ro users but don't allow promote user to admin or managers roles | ||
|| ((int) $session->get('user-can_manage_all_users') === 1 | ||
&& (int) $post_is_admin !== 1 && (int) $data_user['admin'] !== 1 | ||
&& (int) $post_is_hr !== 1 && (int) $data_user['can_manage_all_users'] !== 1 | ||
&& (int) $post_is_manager !== 1 && (int) $data_user['gestionnaire'] !== 1) | ||
) { | ||
return sendMailToUser( | ||
filter_var($dataReceived['receipt'], FILTER_SANITIZE_FULL_SPECIAL_CHARS), | ||
$dataReceived['body'], | ||
(string) filter_var($dataReceived['subject'], FILTER_SANITIZE_FULL_SPECIAL_CHARS), | ||
(array) filter_var_array( | ||
$dataReceived['pre_replace'], | ||
FILTER_SANITIZE_FULL_SPECIAL_CHARS | ||
), | ||
true | ||
); | ||
} | ||
|
||
return prepareExchangedData( | ||
array( | ||
'error' => true, | ||
), | ||
true | ||
'encode' | ||
); | ||
/* | ||
* Send emails not sent | ||
*/ | ||
case 'send_waiting_emails'://mail | ||
// Administrative task | ||
if ((int) $session->get('user-admin') !== 1) { | ||
return prepareExchangedData( | ||
array( | ||
'error' => true, | ||
), | ||
'encode' | ||
); | ||
} | ||
|
||
sendEmailsNotSent( | ||
$SETTINGS | ||
); | ||
|
@@ -658,8 +701,8 @@ function systemHandler(string $post_type, array|null|string $dataReceived, array | |
); | ||
|
||
/* | ||
* Sending statistics | ||
*/ | ||
* Sending statistics | ||
*/ | ||
case 'sending_statistics'://action_system | ||
sendingStatistics( | ||
$SETTINGS | ||
|
@@ -675,6 +718,17 @@ function systemHandler(string $post_type, array|null|string $dataReceived, array | |
* Generate BUG report | ||
*/ | ||
case 'generate_bug_report'://action_system | ||
|
||
// Only administrators can see this confidential informations. | ||
if ((int) $session->get('user-admin') !== 1) { | ||
return prepareExchangedData( | ||
array( | ||
'error' => false, | ||
), | ||
'encode' | ||
); | ||
} | ||
|
||
return generateBugReport( | ||
(array) $dataReceived, | ||
$SETTINGS | ||
|
@@ -684,6 +738,17 @@ function systemHandler(string $post_type, array|null|string $dataReceived, array | |
* get_teampass_settings | ||
*/ | ||
case 'get_teampass_settings'://action_system | ||
|
||
// Only administrators can see this confidential informations. | ||
if ((int) $session->get('user-admin') !== 1) { | ||
return prepareExchangedData( | ||
array( | ||
'error' => false, | ||
), | ||
'encode' | ||
); | ||
} | ||
|
||
// Encrypt data to return | ||
return prepareExchangedData( | ||
array_intersect_key( | ||
|
@@ -709,8 +774,8 @@ function systemHandler(string $post_type, array|null|string $dataReceived, array | |
); | ||
|
||
/* | ||
* Generates a TOKEN with CRYPT | ||
*/ | ||
* Generates a TOKEN with CRYPT | ||
*/ | ||
case 'save_token'://action_system | ||
$token = GenerateCryptKey( | ||
null !== filter_input(INPUT_POST, 'size', FILTER_SANITIZE_NUMBER_INT) ? (int) filter_input(INPUT_POST, 'size', FILTER_SANITIZE_NUMBER_INT) : 20, | ||
|
@@ -753,8 +818,8 @@ function utilsHandler(string $post_type, array|null|string $dataReceived, array | |
{ | ||
switch ($post_type) { | ||
/* | ||
* generate_an_otp | ||
*/ | ||
* generate_an_otp | ||
*/ | ||
case 'generate_an_otp'://action_utils | ||
return generateAnOTP( | ||
(string) filter_var($dataReceived['label'], FILTER_SANITIZE_FULL_SPECIAL_CHARS), | ||
|
@@ -764,8 +829,8 @@ function utilsHandler(string $post_type, array|null|string $dataReceived, array | |
|
||
|
||
/* | ||
* Default case | ||
*/ | ||
* Default case | ||
*/ | ||
default : | ||
return prepareExchangedData( | ||
array( | ||
|
@@ -1441,12 +1506,6 @@ function generateBugReport( | |
// Load user's language | ||
$session = SessionManager::getSession(); | ||
$lang = new Language($session->get('user-language') ?? 'english'); | ||
|
||
// Only administrators can see this confidential informations. | ||
if ($session->get('user-admin') !== 1) { | ||
http_response_code(403); | ||
return ""; | ||
} | ||
|
||
// Read config file | ||
$list_of_options = ''; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$post_id isn't initialized at this step
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to replace
$post_id
with$dataReceived['receipt']