Compare commits

..

4 Commits

Author SHA1 Message Date
Simon Sessingø d2de22e5e0 Merge pull request #10 from skipperbent/development
Development
2015-10-22 19:34:57 +02:00
Simon Sessingø 252fb16326 Merge branch 'development' of https://github.com/skipperbent/simple-php-router into development 2015-10-22 19:34:32 +02:00
Simon Sessingø 63dfbb24af [BUGFIX] Bugfix
- Fixed csrf-token cookie not being set on some paths.
- Changed RouterException in BaseCsrfVerifier to TokenMismatchException.
2015-10-22 19:33:20 +02:00
Simon Sessingø 3ccfac9422 Update README.md 2015-10-22 09:57:31 +02:00
3 changed files with 15 additions and 7 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ Add the latest version pf Simple PHP Router to your ```composer.json```
- Global Constraints
- Sub-Domain Routing
- Optional/required parameters
- Required parameters
## Initialising the router
@@ -269,4 +269,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
@@ -0,0 +1,4 @@
<?php
namespace Pecee\Exception;
class TokenMismatchException extends \Exception {}
@@ -1,10 +1,9 @@
<?php
namespace Pecee\Http\Middleware;
use Pecee\CsrfToken;
use Pecee\Exception\TokenMismatchException;
use Pecee\Http\Request;
use Pecee\SimpleRouter\RouterException;
class BaseCsrfVerifier extends Middleware {
@@ -12,6 +11,12 @@ class BaseCsrfVerifier extends Middleware {
const HEADER_KEY = 'X-CSRF-TOKEN';
protected $except;
protected $csrfToken;
public function __construct() {
$this->csrfToken = new CsrfToken();
}
/**
* Check if the url matches the urls in the except property
@@ -52,9 +57,8 @@ class BaseCsrfVerifier extends Middleware {
$token = $request->getHeader(self::HEADER_KEY);
}
$tokenValidator = new CsrfToken();
if( !$tokenValidator->validate( $token ) ) {
throw new RouterException('Invalid csrf-token.');
if( !$this->csrfToken->validate( $token ) ) {
throw new TokenMismatchException('Invalid csrf-token.');
}
}