EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Security params form action
Yuriie955003f569b
diff --git a/application/Espo/Core/Utils/Client/ActionRenderer.php b/application/Espo/Core/Utils/Client/ActionRenderer.phpindex 19d96104a8..80c900a943 100644--- a/application/Espo/Core/Utils/Client/ActionRenderer.php+++ b/application/Espo/Core/Utils/Client/ActionRenderer.php@@ -61,11 +61,16 @@ class ActionRendererlogin: $params->login(),);- $securityParams = new SecurityParams(- frameAncestors: $params->getFrameAncestors(),- );+ $securityParams = $params->getSecurityParams();++ if (!$securityParams && $params->getFrameAncestors()) {+ $securityParams = new SecurityParams(+ frameAncestors: $params->getFrameAncestors(),+ );+ }$this->clientManager->writeHeaders($response, $securityParams);+$response->writeBody($body);}diff --git a/application/Espo/Core/Utils/Client/ActionRenderer/Params.php b/application/Espo/Core/Utils/Client/ActionRenderer/Params.phpindex 616a2666a3..e732e9bbf8 100644--- a/application/Espo/Core/Utils/Client/ActionRenderer/Params.php+++ b/application/Espo/Core/Utils/Client/ActionRenderer/Params.php@@ -30,6 +30,7 @@namespace Espo\Core\Utils\Client\ActionRenderer;use Espo\Core\Utils\Client\Script;+use Espo\Core\Utils\Client\SecurityParams;use Espo\Core\Utils\Theme\Direction;/**@@ -48,6 +49,7 @@ class Paramsprivate ?string $theme = null;private ?Direction $direction = null;private bool $login = false;+ private ?SecurityParams $securityParams = null;/*** @param ?array<string, mixed> $data@@ -55,7 +57,7 @@ class Paramspublic function __construct(private string $controller,private string $action,- ?array $data = null+ ?array $data = null,) {$this->data = $data;}@@ -88,8 +90,10 @@ class Params}/**+ * @deprecated As of v10.1.0. Use `withSecurityParams`.* @param string[] $frameAncestors* @since 9.0.0+ * @todo Remove in v11.0.*/public function withFrameAncestors(array $frameAncestors): self{@@ -152,6 +156,17 @@ class Paramsreturn $obj;}+ /**+ * @since 10.1.0+ */+ public function withSecurityParams(?SecurityParams $securityParams): self+ {+ $obj = clone $this;+ $obj->securityParams = $securityParams;++ return $obj;+ }+public function getController(): string{return $this->controller;@@ -176,8 +191,10 @@ class Params}/**+ * @deprecated As of v10.1.0. Use `getSecurityParams`.* @return string[]* @since 9.0.0+ * @todo Remove in v11.0.*/public function getFrameAncestors(): array{@@ -221,4 +238,12 @@ class Params{return $this->login;}++ /**+ * @since 10.1.0+ */+ public function getSecurityParams(): ?SecurityParams+ {+ return $this->securityParams;+ }}diff --git a/application/Espo/Core/Utils/Client/SecurityParams.php b/application/Espo/Core/Utils/Client/SecurityParams.phpindex 154f891cb3..4be02a145e 100644--- a/application/Espo/Core/Utils/Client/SecurityParams.php+++ b/application/Espo/Core/Utils/Client/SecurityParams.php@@ -29,12 +29,14 @@namespace Espo\Core\Utils\Client;-class SecurityParams+readonly class SecurityParams{/*** @param string[] $frameAncestors+ * @param ?string[] $formAction*/public function __construct(- readonly public array $frameAncestors = [],+ public array $frameAncestors = [],+ public ?array $formAction = null,) {}}diff --git a/application/Espo/Core/Utils/ClientManager.php b/application/Espo/Core/Utils/ClientManager.phpindex 34965c07a4..471cb14970 100644--- a/application/Espo/Core/Utils/ClientManager.php+++ b/application/Espo/Core/Utils/ClientManager.php@@ -123,7 +123,16 @@ class ClientManager$string .= ' ' . $src;}- if (!$this->config->get('clientCspFormActionDisabled')) {+ if ($params->formAction !== null) {+ if ($params->formAction !== []) {+ $string .= '; form-action';++ foreach ($params->formAction as $item) {+ $string .= ' ' . $item;+ }+ }++ } else if (!$this->config->get('clientCspFormActionDisabled')) {$string .= "; form-action 'self'";}diff --git a/application/Espo/EntryPoints/LeadCaptureForm.php b/application/Espo/EntryPoints/LeadCaptureForm.phpindex 13db872498..d3e3095835 100644--- a/application/Espo/EntryPoints/LeadCaptureForm.php+++ b/application/Espo/EntryPoints/LeadCaptureForm.php@@ -30,6 +30,7 @@namespace Espo\EntryPoints;use Espo\Core\Utils\Client\Script;+use Espo\Core\Utils\Client\SecurityParams;use Espo\Tools\LeadCapture\FormService;use Espo\Core\Api\Request;use Espo\Core\Api\Response;@@ -72,10 +73,14 @@ class LeadCaptureForm implements EntryPoint);$params = $params- ->withFrameAncestors($leadCapture->getFormFrameAncestors())->withPageTitle($leadCapture->getFormTitle())->withTheme($leadCapture->getFormTheme())- ->withDirection($direction);+ ->withDirection($direction)+ ->withSecurityParams(+ new SecurityParams(+ frameAncestors: $leadCapture->getFormFrameAncestors(),+ )+ );if ($captchaScript) {$params = $params->withScripts([new Script(source: $captchaScript)]);