Skip to content

EspoCRM – Open Source CRM Application

Formula create entity ID check

Yuriie426a8a383a6
diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
index 081280725b..95bd6d7c34 100644
--- a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
+++ b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
@@ -36,6 +36,7 @@ use Espo\Core\Formula\Exceptions\TooFewArguments;
use Espo\Core\Formula\Func;
use Espo\Core\Formula\Utils\EntityUtil;
use Espo\ORM\EntityManager;
+use Espo\ORM\Name\Attribute;
use stdClass;
/**
@@ -73,6 +74,18 @@ class CreateType implements Func
throw new NotAllowedUsage("Cannot write $entityType.$notAllowedAttributes[0].");
}
+ $id = $data[Attribute::ID] ?? null;
+
+ if ($id !== null) {
+ if (!is_string($id) && !is_int($id)) {
+ throw new NotAllowedUsage("Entity ID can be only string or int.");
+ }
+
+ if (is_string($id) && !preg_match('/^[a-zA-Z0-9\-]+$/', $id)) {
+ throw new NotAllowedUsage("Not allowed characters in ID '$id'.");
+ }
+ }
+
$entity = $this->entityManager->getNewEntity($entityType);
$entity->setMultiple($data);
diff --git a/tests/integration/Espo/Core/Formula/FormulaTest.php b/tests/integration/Espo/Core/Formula/FormulaTest.php
index d62c5555c0..107d1a0ae3 100644
--- a/tests/integration/Espo/Core/Formula/FormulaTest.php
+++ b/tests/integration/Espo/Core/Formula/FormulaTest.php
@@ -1579,6 +1579,55 @@ class FormulaTest extends BaseTestCase
$this->assertTrue($thrown);
//
+
+ $script = "
+ \$data = object\\create();
+ \$data['id'] = 10.1;
+ record\\create('Account', \$data);
+ ";
+
+ $thrown = false;
+ try {
+ $fm->run($script, $user);
+ } catch (NotAllowedUsage) {
+ $thrown = true;
+ }
+
+ $this->assertTrue($thrown);
+
+ //
+
+ $script = "
+ \$data = object\\create();
+ \$data['id'] = 'a/b';
+ record\\create('Account', \$data);
+ ";
+
+ $thrown = false;
+ try {
+ $fm->run($script, $user);
+ } catch (NotAllowedUsage) {
+ $thrown = true;
+ }
+
+ $this->assertTrue($thrown);
+
+ //
+
+ $script = "
+ \$data = object\\create();
+ \$data['id'] = 'abc';
+ record\\create('Account', \$data);
+ ";
+
+ $thrown = false;
+ try {
+ $fm->run($script, $user);
+ } catch (NotAllowedUsage) {
+ $thrown = true;
+ }
+
+ $this->assertFalse($thrown);
}
/**