Skip to content

Commit b93fbf3

Browse files
committed
IcingaObjectHandler: Check for import loop detection during rest api updates
1 parent c92ead6 commit b93fbf3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

library/Director/RestApi/IcingaObjectHandler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Icinga\Module\Director\Objects\IcingaHost;
1414
use Icinga\Module\Director\Objects\IcingaObject;
1515
use Icinga\Module\Director\Resolver\OverrideHelper;
16+
use Icinga\Module\Director\Resolver\TemplateTree;
1617
use InvalidArgumentException;
1718
use RuntimeException;
1819

@@ -139,6 +140,21 @@ protected function handleApiRequest()
139140
], $data);
140141
$object->replaceWith(IcingaObject::createByType($type, $data, $db));
141142
}
143+
144+
if (in_array((int) $object->get('id'), $object->listAncestorIds())) {
145+
throw new RuntimeException(
146+
'Import loop detected for the object '
147+
. $object->getObjectName() . ' -> Imports: '
148+
. implode(', ', $object->getImports())
149+
);
150+
}
151+
152+
if (in_array($object->get('object_name'), $data['imports'])) {
153+
throw new RuntimeException(
154+
'You can not import the same object into itself: ' . $object->getObjectName()
155+
);
156+
}
157+
142158
$this->persistChanges($object);
143159
$this->sendJson($object->toPlainObject(false, true));
144160
} elseif ($allowsOverrides && $type === 'service') {

0 commit comments

Comments
 (0)