Skip to content

Commit

Permalink
Unset CSRF token from request data after token validation.
Browse files Browse the repository at this point in the history
This prevents the token being included in query string when using PRG pattern.
  • Loading branch information
ADmad committed Oct 9, 2015
1 parent 7df65e6 commit 5f76c1c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Controller/Component/CsrfComponent.php
Expand Up @@ -94,6 +94,7 @@ public function startup(Event $event)
}
if ($request->is(['patch', 'put', 'post', 'delete'])) {
$this->_validateToken($request);
unset($request->data[$this->_config['field']]);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Controller/Component/CsrfComponentTest.php
Expand Up @@ -156,6 +156,7 @@ public function testValidTokenRequestData($method)
$event = new Event('Controller.startup', $controller);
$result = $this->component->startup($event);
$this->assertNull($result, 'No exception means valid.');
$this->assertFalse(isset($controller->request->data['_csrfToken']));
}

/**
Expand Down

0 comments on commit 5f76c1c

Please sign in to comment.