Skip to content

Commit

Permalink
Throw 400 if filter is not properly escaped
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 5, 2024
1 parent dcd7411 commit 93c9343
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
13 changes: 9 additions & 4 deletions application/controllers/ApiV1ChannelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Icinga\Module\Notifications\Controllers;

use Exception;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Util\Environment;
use Icinga\Util\Json;
Expand Down Expand Up @@ -41,8 +42,8 @@ public function indexAction(): void
$this->httpBadRequest('The given identifier is not a valid UUID');
}

$filter = FilterProcessor::assembleFilter(
QueryString::fromString(rawurldecode(Url::fromRequest()->getQueryString()))
try {
$filterRule = QueryString::fromString(rawurldecode(Url::fromRequest()->getQueryString()))
->on(
QueryString::ON_CONDITION,
function (Filter\Condition $condition) {
Expand All @@ -62,8 +63,12 @@ function (Filter\Condition $condition) {
$condition->setColumn('external_uuid');
}
}
)->parse()
);
)->parse();

$filter = FilterProcessor::assembleFilter($filterRule);
} catch (Exception $e) {
$this->httpBadRequest('filter is not escaped properly');
}

$stmt = (new Select())
->distinct()
Expand Down
12 changes: 8 additions & 4 deletions application/controllers/ApiV1ContactgroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function indexAction(): void
$this->httpBadRequest('Filter is only allowed in GET request');
}

$filter = FilterProcessor::assembleFilter(
QueryString::fromString($filterStr)
try {
$filterRule = QueryString::fromString($filterStr)
->on(
QueryString::ON_CONDITION,
function (Filter\Condition $condition) {
Expand All @@ -87,8 +87,12 @@ function (Filter\Condition $condition) {
$condition->setColumn('external_uuid');
}
}
)->parse()
);
)->parse();

$filter = FilterProcessor::assembleFilter($filterRule);
} catch (Exception $e) {
$this->httpBadRequest('filter is not escaped properly');
}

switch ($method) {
case 'GET':
Expand Down
12 changes: 8 additions & 4 deletions application/controllers/ApiV1ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function indexAction(): void
$this->httpBadRequest('Filter is only allowed in GET request');
}

$filter = FilterProcessor::assembleFilter(
QueryString::fromString($filterStr)
try {
$filterRule = QueryString::fromString($filterStr)
->on(
QueryString::ON_CONDITION,
function (Filter\Condition $condition) {
Expand All @@ -92,8 +92,12 @@ function (Filter\Condition $condition) {
$condition->setColumn('external_uuid');
}
}
)->parse()
);
)->parse();

$filter = FilterProcessor::assembleFilter($filterRule);
} catch (Exception $e) {
$this->httpBadRequest('filter is not escaped properly');
}

switch ($method) {
case 'GET':
Expand Down

0 comments on commit 93c9343

Please sign in to comment.