diff --git a/README.md b/README.md index 975af8b..9a19fe8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # CSRF header checking middleware -This package contains a PHP PSR-15 (http-interop) compliant middleware that checks for CSRF attacks. +This package contains a PHP PSR-15 compliant middleware that checks for CSRF attacks. It implements the [first OWASP general recommendation for guarding your site against cross-site request forgery (Verifying Same Origin with Standard Headers)](https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet). diff --git a/composer.json b/composer.json index 2b927da..6841f48 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "thecodingmachine/csrf-header-check-middleware", - "description": "A PHP PSR-15 (http-interop) compliant middleware that checks for CSRF attacks.", + "description": "A PHP PSR-15 compliant middleware that checks for CSRF attacks.", "license": "MIT", "authors": [ { @@ -9,7 +9,8 @@ } ], "require": { - "http-interop/http-middleware": "^0.4" + "php" : ">=7", + "psr/http-server-middleware": "^1.0" }, "require-dev": { "phpunit/phpunit": "^7.0.2", @@ -30,7 +31,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } } } diff --git a/src/CsrfHeaderCheckMiddleware.php b/src/CsrfHeaderCheckMiddleware.php index a7e5bba..bc9aadd 100644 --- a/src/CsrfHeaderCheckMiddleware.php +++ b/src/CsrfHeaderCheckMiddleware.php @@ -3,10 +3,10 @@ namespace TheCodingMachine\Middlewares; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; use TheCodingMachine\Middlewares\OriginFetchers\SourceOriginInterface; use TheCodingMachine\Middlewares\OriginFetchers\TargetOriginInterface; use TheCodingMachine\Middlewares\SafeRequests\IsSafeHttpRequestInterface; @@ -50,11 +50,11 @@ public function __construct(IsSafeHttpRequestInterface $isSafeHttpRequest, Targe * to the next middleware component to create the response. * * @param ServerRequestInterface $request - * @param DelegateInterface $delegate + * @param RequestHandlerInterface $delegate * @return ResponseInterface * @throws CsrfHeaderCheckMiddlewareException */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, RequestHandlerInterface $delegate): ResponseInterface { $isSafeHttpRequest = $this->isSafeHttpRequest; if (!$isSafeHttpRequest($request)) { @@ -68,6 +68,6 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele throw new CsrfHeaderCheckMiddlewareException('Potential CSRF attack stopped. Source origin and target origin do not match.'); } } - return $delegate->process($request); + return $delegate->handle($request); } } diff --git a/tests/AbstractMiddlewareTest.php b/tests/AbstractMiddlewareTest.php index 8e1b0c2..d661201 100644 --- a/tests/AbstractMiddlewareTest.php +++ b/tests/AbstractMiddlewareTest.php @@ -3,16 +3,17 @@ namespace TheCodingMachine\Middlewares; -use Interop\Http\ServerMiddleware\DelegateInterface; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\RequestHandlerInterface; use Zend\Diactoros\Response\TextResponse; abstract class AbstractMiddlewareTest extends TestCase { - protected function getDelegate() : DelegateInterface + protected function getDelegate() : RequestHandlerInterface { - return new class implements DelegateInterface { + return new class implements RequestHandlerInterface { /** * Dispatch the next available middleware and return the response. @@ -21,7 +22,7 @@ protected function getDelegate() : DelegateInterface * * @return ResponseInterface */ - public function process(ServerRequestInterface $request) + public function handle(ServerRequestInterface $request):ResponseInterface { return new TextResponse('foobar'); } diff --git a/tests/CsrfHeaderCheckMiddlewareTest.php b/tests/CsrfHeaderCheckMiddlewareTest.php index d906e05..95b0391 100644 --- a/tests/CsrfHeaderCheckMiddlewareTest.php +++ b/tests/CsrfHeaderCheckMiddlewareTest.php @@ -3,7 +3,6 @@ namespace TheCodingMachine\Middlewares; -use Interop\Http\ServerMiddleware\DelegateInterface; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;