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>
This commit is contained in:
Thomas Vincent authored and GitHub committed 2026-03-23 13:07:49 -04:00
1 parent 56b6eee1fc
commit 61d8e93592
3 files changed
+11 -13

No files matched your search

+2 -2
View File
@@ -397,7 +397,7 @@ if ($config['poller_id'] > 1 || isset($rdatabase_hostname)) {
print $li . 'the credentials in config.php are valid.' . $il;
print $lu . $sp;
if (isset($_REQUEST['display_db_errors']) && !empty($config['DATABASE_ERROR'])) { // @phpstan-ignore-line
if (isrv('display_db_errors') && !empty($config['DATABASE_ERROR'])) { // @phpstan-ignore-line
print $ps . 'The following database errors occurred: ' . $ul;
foreach ($config['DATABASE_ERROR'] as $e) { // @phpstan-ignore-line
@@ -419,7 +419,7 @@ if ($config['poller_id'] > 1 || isset($rdatabase_hostname)) {
print $li . 'the credentials in config.php are valid and correct.' . $il;
print $lu . $sp;
if (isset($_REQUEST['display_db_errors']) && !empty($config['DATABASE_ERROR'])) { // @phpstan-ignore-line
if (isrv('display_db_errors') && !empty($config['DATABASE_ERROR'])) { // @phpstan-ignore-line
print $ps . 'The following database errors occurred: ' . $ul;
foreach ($config['DATABASE_ERROR'] as $e) { // @phpstan-ignore-line
+5 -5
View File
@@ -44,19 +44,19 @@ if (!read_config_option('i18n_language_support') && read_config_option('i18n_lan
// Repair legacy language support
if (!empty($config['i18n_force_language'])) {
$_REQUEST['language'] = $config['i18n_force_language'];
set_request_var('language', $config['i18n_force_language']);
}
if (!empty($_REQUEST['language'])) {
$_REQUEST['language'] = repair_locale($_REQUEST['language']);
if (!isempty_request_var('language')) {
set_request_var('language', repair_locale(grv('language')));
}
// determine whether or not we can support the language
$user_locale = '';
if (!empty($_REQUEST['language']) && !empty($lang2locale[$_REQUEST['language']])) {
if (!isempty_request_var('language') && !empty($lang2locale[grv('language')])) {
// user requests another language
$user_locale = apply_locale($_REQUEST['language']);
$user_locale = apply_locale(grv('language'));
unset($_SESSION['sess_current_date1']);
unset($_SESSION['sess_current_date2']);
+4 -6
View File
@@ -89,17 +89,15 @@ switch ($providerName) {
die('Provider missing');
}
if (!isset($_GET['code'])) { // If we don't have an authorization code then get one
if (!isrv('code')) { // If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();
header('Location: ' . $authUrl);
exit;
cacti_redirect($authUrl, false);
// Check given state against previously stored one to mitigate CSRF attack
}
if (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && ($_GET['state'] !== $_SESSION['oauth2state']))) {
if (isempty_request_var('state') || (isset($_SESSION['oauth2state']) && (grv('state') !== $_SESSION['oauth2state']))) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
@@ -107,7 +105,7 @@ if (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && ($_GET['state']
$token = $provider->getAccessToken(
'authorization_code',
[
'code' => $_GET['code']
'code' => grv('code')
]
);