Skip to content

Commit 7d02982

Browse files
committed
Presenter: signal must be sent from the same origin unless they have annotation @crossorigin (BC break)
Experimental
1 parent c04f633 commit 7d02982

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Application/UI/Component.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ protected function tryCall(string $method, array $params): bool
104104
*/
105105
public function checkRequirements($element): void
106106
{
107+
if (
108+
$element instanceof \ReflectionMethod
109+
&& substr($element->getName(), 0, 6) === 'handle'
110+
&& !ComponentReflection::parseAnnotation($element, 'crossOrigin')
111+
&& !$this->getPresenter()->getHttpRequest()->isSameSite()
112+
) {
113+
throw new Nette\Application\ForbiddenRequestException('The signal was not sent from the same domain. It can be allowed using @crossOrigin annotation.');
114+
}
107115
}
108116

109117

src/Application/UI/Presenter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ protected function shutdown(Application\IResponse $response)
299299
*/
300300
public function checkRequirements($element): void
301301
{
302+
parent::checkRequirements($element);
302303
$user = (array) ComponentReflection::parseAnnotation($element, 'User');
303304
if (in_array('loggedIn', $user, true)) {
304305
trigger_error(__METHOD__ . '() annotation @User is deprecated', E_USER_DEPRECATED);

0 commit comments

Comments
 (0)