Skip to content

Commit

Permalink
Satisfy coding standard.
Browse files Browse the repository at this point in the history
  • Loading branch information
JASchilz committed Feb 5, 2016
1 parent f080b0a commit 923ed7c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/CSRF.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function init()
*/
protected static function generateToken()
{
if (!isset($_SESSION['csrf_token'])) {
if (isset($_SESSION['csrf_token']) === false) {
$_SESSION['csrf_token'] = bin2hex(openssl_random_pseudo_bytes(16));
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ protected static function generateCallback($token)
}

$matches = [];
if (preg_match_all('/<\s*\w*\s*form.*?>/is', $page, $matches, PREG_OFFSET_CAPTURE)) {
if (preg_match_all('/<\s*\w*\s*form.*?>/is', $page, $matches, PREG_OFFSET_CAPTURE) !== 0) {
foreach ($matches[0] as $match) {
$formOpen = strpos($page, $match[0], $match[1]);
$formClose = strpos($page, ">", $formOpen);
Expand All @@ -97,20 +97,20 @@ protected static function generateCallback($token)
protected static function checkCSRF()
{

if (!array_key_exists("csrf_token", $_SESSION)) {
if (array_key_exists("csrf_token", $_SESSION) === false) {
throw new \Exception('No CSRF Token set in $_SESSION. Invoke \UWDOEM\CSRF\CSRF::init before ::checkCSRF');
}

if (in_array($_SERVER['REQUEST_METHOD'], static::$unsafe_methods)) {
if (in_array($_SERVER['REQUEST_METHOD'], static::$unsafe_methods) === true) {

$requestArguments = [];
parse_str(file_get_contents('php://input'), $requestArguments);

$requestArguments = array_merge($_POST, $requestArguments);

if (!array_key_exists("csrf_token", $requestArguments) || $requestArguments['csrf_token'] != static::getToken()) {
print_r(file_get_contents('php://input'));
if (!headers_sent()) {
if (array_key_exists("csrf_token", $requestArguments) === false
|| $requestArguments['csrf_token'] !== static::getToken()) {

if (headers_sent() === false) {
header("HTTP/1.0 403 Forbidden");
}

Expand Down

0 comments on commit 923ed7c

Please sign in to comment.