Skip to content

Commit 61d8e93

Browse files
hardening: standardize input handling with request variable wrappers (#6865) (#6866)
* hardening: standardize input handling with request variable wrappers (#6865) * fix: use !isempty_request_var() for language check to match !empty() semantics isrv() (isset) returns true for empty strings, while the original !empty() returned false. This caused repair_locale() and apply_locale() to be called with empty language strings. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent 56b6eee commit 61d8e93

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

include/global.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@
397397
print $li . 'the credentials in config.php are valid.' . $il;
398398
print $lu . $sp;
399399

400-
if (isset($_REQUEST['display_db_errors']) && !empty($config['DATABASE_ERROR'])) { // @phpstan-ignore-line
400+
if (isrv('display_db_errors') && !empty($config['DATABASE_ERROR'])) { // @phpstan-ignore-line
401401
print $ps . 'The following database errors occurred: ' . $ul;
402402

403403
foreach ($config['DATABASE_ERROR'] as $e) { // @phpstan-ignore-line
@@ -419,7 +419,7 @@
419419
print $li . 'the credentials in config.php are valid and correct.' . $il;
420420
print $lu . $sp;
421421

422-
if (isset($_REQUEST['display_db_errors']) && !empty($config['DATABASE_ERROR'])) { // @phpstan-ignore-line
422+
if (isrv('display_db_errors') && !empty($config['DATABASE_ERROR'])) { // @phpstan-ignore-line
423423
print $ps . 'The following database errors occurred: ' . $ul;
424424

425425
foreach ($config['DATABASE_ERROR'] as $e) { // @phpstan-ignore-line

include/global_languages.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@
4444

4545
// Repair legacy language support
4646
if (!empty($config['i18n_force_language'])) {
47-
$_REQUEST['language'] = $config['i18n_force_language'];
47+
set_request_var('language', $config['i18n_force_language']);
4848
}
4949

50-
if (!empty($_REQUEST['language'])) {
51-
$_REQUEST['language'] = repair_locale($_REQUEST['language']);
50+
if (!isempty_request_var('language')) {
51+
set_request_var('language', repair_locale(grv('language')));
5252
}
5353

5454
// determine whether or not we can support the language
5555
$user_locale = '';
5656

57-
if (!empty($_REQUEST['language']) && !empty($lang2locale[$_REQUEST['language']])) {
57+
if (!isempty_request_var('language') && !empty($lang2locale[grv('language')])) {
5858
// user requests another language
59-
$user_locale = apply_locale($_REQUEST['language']);
59+
$user_locale = apply_locale(grv('language'));
6060
unset($_SESSION['sess_current_date1']);
6161
unset($_SESSION['sess_current_date2']);
6262

oauth2.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,23 @@
8989
die('Provider missing');
9090
}
9191

92-
if (!isset($_GET['code'])) { // If we don't have an authorization code then get one
92+
if (!isrv('code')) { // If we don't have an authorization code then get one
9393
$authUrl = $provider->getAuthorizationUrl($options);
9494
$_SESSION['oauth2state'] = $provider->getState();
95-
header('Location: ' . $authUrl);
96-
97-
exit;
95+
cacti_redirect($authUrl, false);
9896

9997
// Check given state against previously stored one to mitigate CSRF attack
10098
}
10199

102-
if (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && ($_GET['state'] !== $_SESSION['oauth2state']))) {
100+
if (isempty_request_var('state') || (isset($_SESSION['oauth2state']) && (grv('state') !== $_SESSION['oauth2state']))) {
103101
unset($_SESSION['oauth2state']);
104102

105103
exit('Invalid state');
106104
} else { // Try to get an access token (using the authorization code grant)
107105
$token = $provider->getAccessToken(
108106
'authorization_code',
109107
[
110-
'code' => $_GET['code']
108+
'code' => grv('code')
111109
]
112110
);
113111

0 commit comments

Comments
 (0)