Skip to content

Commit f7df426

Browse files
committed
1 parent 6925574 commit f7df426

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Application/UI/Form.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Form extends Nette\Forms\Form implements ISignalReceiver
2020
/** @var callable[]&(callable(Form $sender): void)[]; Occurs when form is attached to presenter */
2121
public $onAnchor;
2222

23+
/** @var bool */
24+
private $sameSiteProtection = true;
25+
2326

2427
/**
2528
* Application form constructor.
@@ -97,6 +100,15 @@ public function isAnchored(): bool
97100
}
98101

99102

103+
/**
104+
* Disables CSRF protection using a SameSite cookie.
105+
*/
106+
public function disableSameSiteProtection(): void
107+
{
108+
$this->sameSiteProtection = false;
109+
}
110+
111+
100112
/**
101113
* Internal: returns submitted HTTP data or null when form was not submitted.
102114
*/
@@ -143,7 +155,7 @@ public function signalReceived(string $signal): void
143155
$class = get_class($this);
144156
throw new BadSignalException("Missing handler for signal '$signal' in $class.");
145157

146-
} elseif (!$this->getPresenter()->getHttpRequest()->isSameSite()) {
158+
} elseif ($this->sameSiteProtection && !$this->getPresenter()->getHttpRequest()->isSameSite()) {
147159
$this->getPresenter()->detectedCsrf();
148160

149161
} elseif (!$this->getPresenter()->getRequest()->hasFlag(Nette\Application\Request::RESTORED)) {

0 commit comments

Comments
 (0)