Skip to content

Commit

Permalink
[getversion/kernelvers] Prevent unauthenticated clients from making a…
Browse files Browse the repository at this point in the history
…rbitrary requests, thanks @0x41c
  • Loading branch information
0x41c committed Jan 28, 2023
1 parent f6f85a0 commit 9125f35
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
18 changes: 14 additions & 4 deletions packages/web/service/getversion.php
Expand Up @@ -28,20 +28,30 @@
* @link https://fogproject.org
*/
require '../commons/base.inc.php';
$clientUpdate = (bool)FOGCore::getSetting('FOG_CLIENT_AUTOUPDATE');
$clientUpdate = (bool) FOGCore::getSetting('FOG_CLIENT_AUTOUPDATE');
if (isset($_REQUEST['client'])) {
$ver = (
$clientUpdate ?
$clientUpdate ?
'9.9.99' :
'0.0.0'
);
} elseif (isset($_REQUEST['clientver'])) {
$ver = (
$clientUpdate ?
$clientUpdate ?
FOG_CLIENT_VERSION :
'0.0.0'
);
} elseif (isset($_REQUEST['url'])) {

// Prevent an unauthenticated user from making arbitrary requests.
$unauthorized = !$currentUser->isValid() || empty($_SERVER['HTTP_X_REQUESTED_WITH'])
|| strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest';

if ($unauthorized) {
echo _('Unauthorized');
exit;
}

$url = $_REQUEST['url'];
$res = $FOGURLRequests
->process($_REQUEST['url']);
Expand All @@ -50,4 +60,4 @@
$ver = FOG_VERSION;
}
echo $ver;
exit;
exit;
26 changes: 19 additions & 7 deletions packages/web/status/kernelvers.php
Expand Up @@ -24,16 +24,28 @@
ignore_user_abort(true);
set_time_limit(0);
header('Content-Type: text/event-stream');
$url = filter_input(INPUT_POST, 'url');
if ($url) {

if (isset($_POST['url'])) {

// Prevent an unauthenticated user from making arbitrary requests.
$unauthorized = !$currentUser->isValid() || empty($_SERVER['HTTP_X_REQUESTED_WITH'])
|| strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest';

if ($unauthorized) {
echo _('Unauthorized');
exit;
}

$res = $FOGURLRequests
->process($url);
foreach ((array)$res as &$response) {
->process(filter_input(INPUT_POST, 'url'));
foreach ((array) $res as &$response) {
echo $response;
unset($response);
}

exit;
}

$kernelvers = function ($kernel) {
$currpath = sprintf(
'%s%sservice%sipxe%s%s',
Expand All @@ -57,9 +69,9 @@
);
printf(
"bzImage Version: %s\n",
$kernelvers('bzImage')
$kernelvers('bzImage')
);
printf(
"bzImage32 Version: %s",
$kernelvers('bzImage32')
);
$kernelvers('bzImage32')
);

0 comments on commit 9125f35

Please sign in to comment.