- Added CSRF through form processing

This commit is contained in:
Dave Mc Nicoll committed 2022-02-25 15:33:40 +00:00
1 parent 97f1f67af1
commit 83fee32ac0
4 files changed
+31 -31

No files matched your search

+22 -2
View File
@@ -9,7 +9,7 @@ class FormContext implements FormContextInterface
{
public string $formName;
public bool $formSent;
public bool $formSent = false;
public bool $formExecuted = false;
@@ -18,6 +18,8 @@ class FormContext implements FormContextInterface
public array $files = [];
public array $messages = [];
public bool $skipCsrf = false;
public ServerRequestInterface $request;
@@ -54,7 +56,25 @@ class FormContext implements FormContextInterface
public function formSent() : bool
{
return $this->formSent;
$valid = true;
if ( ! $this->skipCsrf && ($this->formName ?? false) ) {
$token = $this->get('picea-ui-form')[$this->formName] ?? false;
if ( $token ) {
if ($this->validateCsrfToken) {
$valid = in_array($token, $_SESSION["picea-ui.form:{$this->formName}"] ?? []);
}
else {
$valid = (bool) $token;
}
}
else {
$valid = false;
}
}
return $this->formSent = $valid;
}
public function __set($key, $value)