Skip to content

Commit d2de22e

Browse files
committed
Merge pull request #10 from skipperbent/development
Development
2 parents 8f2d49f + 252fb16 commit d2de22e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Add the latest version pf Simple PHP Router to your ```composer.json```
3333

3434
- Global Constraints
3535
- Sub-Domain Routing
36-
- Optional/required parameters
36+
- Required parameters
3737

3838
## Initialising the router
3939

@@ -269,4 +269,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
269269
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
270270
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
271271
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
272-
SOFTWARE.
272+
SOFTWARE.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
namespace Pecee\Exception;
3+
4+
class TokenMismatchException extends \Exception {}

src/Pecee/Http/Middleware/BaseCsrfVerifier.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<?php
2-
32
namespace Pecee\Http\Middleware;
43

54
use Pecee\CsrfToken;
5+
use Pecee\Exception\TokenMismatchException;
66
use Pecee\Http\Request;
7-
use Pecee\SimpleRouter\RouterException;
87

98
class BaseCsrfVerifier extends Middleware {
109

1110
const POST_KEY = 'csrf-token';
1211
const HEADER_KEY = 'X-CSRF-TOKEN';
1312

1413
protected $except;
14+
protected $csrfToken;
15+
16+
17+
public function __construct() {
18+
$this->csrfToken = new CsrfToken();
19+
}
1520

1621
/**
1722
* Check if the url matches the urls in the except property
@@ -52,9 +57,8 @@ public function handle(Request $request) {
5257
$token = $request->getHeader(self::HEADER_KEY);
5358
}
5459

55-
$tokenValidator = new CsrfToken();
56-
if( !$tokenValidator->validate( $token ) ) {
57-
throw new RouterException('Invalid csrf-token.');
60+
if( !$this->csrfToken->validate( $token ) ) {
61+
throw new TokenMismatchException('Invalid csrf-token.');
5862
}
5963

6064
}

0 commit comments

Comments
 (0)