Skip to content

deleted server-interop, used the PSR-15 MiddlewareInterface #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand All @@ -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",
Expand All @@ -30,7 +31,7 @@
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "2.0.x-dev"
}
}
}
10 changes: 5 additions & 5 deletions src/CsrfHeaderCheckMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
}
9 changes: 5 additions & 4 deletions tests/AbstractMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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');
}
Expand Down
1 change: 0 additions & 1 deletion tests/CsrfHeaderCheckMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down