Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Fixed

- Various minor fixes and hardening

## [1.4.1] - 2025-11-25

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion ajax/extract_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

header('Content-Type: text/html; charset=UTF-8');
Html::header_nocache();
Session::checkLoginUser();
Session::checkRight('config', READ);

if (
!isset($_REQUEST['id'])
Expand Down
2 changes: 1 addition & 1 deletion inc/apiclient.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ public function httpQuery($resource = '', $params = [], $method = 'GET')
'timeout' => 5,
'connect_timeout' => 2,
'debug' => false,
'verify' => false,
'verify' => true,
'query' => [], // url parameter
'body' => '', // raw data to send in body
'json' => [], // json data to send
Expand Down
28 changes: 24 additions & 4 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ public static function showForConfig(Config $config, $withtemplate = 0)
]);

echo self::showField([
'label' => __s('Metabase embedded token (to display dashboard in GLPI)', 'metabase'),
'attrs' => [
'inputtype' => 'password',
'label' => __s('Metabase embedded token (to display dashboard in GLPI)', 'metabase'),
'attrs' => [
'name' => 'embedded_token',
'value' => $current_config['embedded_token'],
'value' => '',
'placeholder' => '',
'required' => false,
],
Expand Down Expand Up @@ -202,7 +203,7 @@ public static function showForConfig(Config $config, $withtemplate = 0)
echo '</ul>';

$error = $apiclient->getLastError();
if (count($error) > 0) {
if ($canedit && count($error) > 0) {
echo '<h1>' . __s('Last Error', 'metabase') . '</h1>';
if (isset($error['exception'])) {
echo $error['exception'];
Expand Down Expand Up @@ -764,6 +765,10 @@ public static function configUpdate($input)
}
}

if (isset($input['embedded_token']) && empty($input['embedded_token'])) {
unset($input['embedded_token']);
}

return $input;
}

Expand Down Expand Up @@ -801,6 +806,21 @@ public static function install(Migration $migration)
Config::deleteConfigurationValues('plugin:metabase', ['is_password_encrypted', 'is_password_random_encrypted']);
}

// Encrypt embedded_token, previously stored in plain text
if (!array_key_exists('is_embedded_token_encrypted', $current_config) || !$current_config['is_embedded_token_encrypted']) {
if (!empty($current_config['embedded_token'])) {
Config::setConfigurationValues(
'plugin:metabase',
[
'embedded_token' => $current_config['embedded_token'],
],
);
}

// Add flag in config to prevent re-encrypt
Config::setConfigurationValues('plugin:metabase', ['is_embedded_token_encrypted' => 1]);
}

// fill config table with default values if missing
foreach (
[
Expand Down
5 changes: 3 additions & 2 deletions inc/dashboard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ function ($dashboard) {
return;
}

if (null === $currentUuid) {
$allowedUuids = array_column($dashboards, 'id');
if (null === $currentUuid || !in_array($currentUuid, $allowedUuids)) {
$firstDashboard = current($dashboards);
$currentUuid = $firstDashboard['id'];
}
Expand All @@ -131,7 +132,7 @@ function ($dashboard) {

$signer_config = Configuration::forSymmetricSigner(
new Sha256(),
InMemory::plainText($config['embedded_token']),
InMemory::plainText((new GLPIKey())->decrypt($config['embedded_token'])),
);
$token = $signer_config->builder()
->withClaim('resource', [
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function plugin_init_metabase()
$PLUGIN_HOOKS['add_javascript']['metabase'] = 'metabase.js';

// Encryption
$PLUGIN_HOOKS['secured_configs']['metabase'] = ['password'];
$PLUGIN_HOOKS['secured_configs']['metabase'] = ['password', 'embedded_token'];
}


Expand Down