Skip to content

Commit

Permalink
Presenter: checks $allowedMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 27, 2023
1 parent dca911e commit 83f5144
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ abstract class Presenter extends Control implements Application\IPresenter
/** @var bool use absolute Urls or paths? */
public $absoluteUrls = false;

/** @var string[] */
public $allowedMethods = ['GET', 'POST', 'HEAD', 'PUT', 'DELETE'];

/** @var Nette\Application\Request|null */
private $request;

Expand Down Expand Up @@ -215,6 +218,7 @@ public function run(Application\Request $request): Application\Response
try {
// STARTUP
$this->checkRequirements(static::getReflection());
$this->checkHttpMethod();

This comment has been minimized.

Copy link
@KminekMatej

KminekMatej Aug 28, 2023

Is this a good place to check HTTP method there? This effectively blocks having different actions each with differet set of $allowedMethods
(Sorry for direct comment, couldnt find the issue describing this change)

This comment has been minimized.

Copy link
@dg

dg Aug 28, 2023

Author Member
Arrays::invoke($this->onStartup, $this);
$this->startup();
if (!$this->startupCheck) {
Expand Down Expand Up @@ -333,6 +337,17 @@ public function detectedCsrf(): void
}


protected function checkHttpMethod(): void
{
if ($this->allowedMethods &&
!in_array($method = $this->httpRequest->getMethod(), $this->allowedMethods, true)
) {
$this->httpResponse->setHeader('Allow', implode(',', $this->allowedMethods));
$this->error("Method $method is not allowed", Nette\Http\IResponse::S405_MethodNotAllowed);
}
}


/********************* signal handling ****************d*g**/


Expand Down

0 comments on commit 83f5144

Please sign in to comment.