Skip to content
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 CAS server status check #18734

Merged
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
18 changes: 17 additions & 1 deletion inc/based_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,23 @@
'GLPI_SERVERSIDE_URL_ALLOWLIST' => [
// allowlist (regex format) of URL that can be fetched from server side (used for RSS feeds and external calendars, among others)
// URL will be considered as safe as long as it matches at least one entry of the allowlist
'/^(https?|feed):\/\/[^@:]+(\/.*)?$/', // only accept http/https/feed protocols, and reject presence of @ (username) and : (protocol) in host part of URL

// `http://` URLs
// - without presence of @ (username) and : (protocol) in host part of URL
// - with optional `:80` default port
// - with optional path
'#^http://[^@:]+(:80)?(/.*)?$#',

// `https://` URLs
// - without presence of @ (username) and : (protocol) in host part of URL
// - with optional `:443` default port
// - with optional path
'#^https://[^@:]+(:443)?(/.*)?$#',

// `feed://` URLs
// - without presence of @ (username) and : (protocol) in host part of URL
// - with optional path
'#^feed://[^@:]+(/.*)?$#',
],

// Constants related to GLPI Project / GLPI Network external services
Expand Down
9 changes: 7 additions & 2 deletions phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@
define(
'GLPI_SERVERSIDE_URL_ALLOWLIST',
[
'/^(https?|feed):\/\/[^@:]+(\/.*)?$/', // default allowlist entry
'/^file:\/\/.*\.ics$/', // calendar mockups
// default allowlist entries
'#^http://[^@:]+(:80)?(/.*)?$#',
'#^https://[^@:]+(:443)?(/.*)?$#',
'#^feed://[^@:]+(/.*)?$#',

// calendar mockups
'/^file:\/\/.*\.ics$/',
]
);

Expand Down
18 changes: 15 additions & 3 deletions phpunit/functional/ToolboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1633,13 +1633,17 @@ public static function safeUrlProvider(): iterable
'expected' => false,
];

// http, https and feed URLs are accepted, unless they contains a user or port information
foreach (['http', 'https', 'feed'] as $scheme) {
foreach (['', '/', '/path/to/feed.php'] as $path) {
// http, https and feed URLs are accepted, unless they contains a user or non default port information
foreach (['http' => ':80', 'https' => ':443', 'feed' => ''] as $scheme => $default_port) {
foreach (['', '/', '/path/to/resource.php'] as $path) {
yield [
'url' => sprintf('%s://localhost%s', $scheme, $path),
'expected' => true,
];
yield [
'url' => sprintf('%s://localhost%s%s', $scheme, $default_port, $path),
'expected' => true,
];
yield [
'url' => sprintf('%s://localhost:8080%s', $scheme, $path),
'expected' => false,
Expand All @@ -1648,10 +1652,18 @@ public static function safeUrlProvider(): iterable
'url' => sprintf('%s://test@localhost%s', $scheme, $path),
'expected' => false,
];
yield [
'url' => sprintf('%s://test@localhost%s%s', $scheme, $default_port, $path),
'expected' => false,
];
yield [
'url' => sprintf('%s://test:pass@localhost%s', $scheme, $path),
'expected' => false,
];
yield [
'url' => sprintf('%s://test:pass@localhost%s%s', $scheme, $default_port, $path),
'expected' => false,
];
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/System/Status/StatusChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,14 @@ public static function getCASStatus($public_only = true): array
if ($status === null) {
$status['status'] = self::STATUS_NO_DATA;
if (!empty($CFG_GLPI['cas_host'])) {
$url = $CFG_GLPI['cas_host'];
// Rebuild CAS URL
// see `CAS_Client::_getServerBaseURL()`
$url = 'https://' . $CFG_GLPI['cas_host'];
AdrienClairembault marked this conversation as resolved.
Show resolved Hide resolved
if (!empty($CFG_GLPI['cas_port'])) {
$url .= ':' . (int)$CFG_GLPI['cas_port'];
}
$url .= '/' . $CFG_GLPI['cas_uri'];

if (Toolbox::isUrlSafe($url)) {
$data = Toolbox::getURLContent($url);
if (!empty($data)) {
Expand Down
9 changes: 7 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@
define(
'GLPI_SERVERSIDE_URL_ALLOWLIST',
[
'/^(https?|feed):\/\/[^@:]+(\/.*)?$/', // default allowlist entry
'/^file:\/\/.*\.ics$/', // calendar mockups
// default allowlist entries
'#^http://[^@:]+(:80)?(/.*)?$#',
'#^https://[^@:]+(:443)?(/.*)?$#',
'#^feed://[^@:]+(/.*)?$#',

// calendar mockups
'/^file:\/\/.*\.ics$/',
]
);

Expand Down