Skip to content

Commit

Permalink
Merge pull request #305 from moe-lk/PenTest
Browse files Browse the repository at this point in the history
Pen test FIXES
  • Loading branch information
mohamednizar authored Dec 3, 2020
2 parents 7b5f13a + 509b947 commit 2beb056
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
<IfModule mod_php7.c>
php_flag session.use_trans_sid off
</IfModule>

8 changes: 7 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,13 @@
* To use database sessions, load the SQL file located at config/Schema/sessions.sql
*/
'Session' => [
'defaults' => 'php',
'defaults' => 'cake',
'timeout' => 30,
'cookieTimeout' => 30,
'ini' => array(
'session.cookie_secure' => true,
'session.cookie_httponly' => true
)
// 'defaults' => 'cache',
],
'debug' => true
Expand Down
22 changes: 10 additions & 12 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
*/
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);



/**
* Connect catchall routes for all controllers.
*
Expand Down Expand Up @@ -203,16 +201,16 @@
});

// For restful session
Router::scope('/session', ['plugin' => 'Restful'], function ($routes) {
$routes->scope('/', ['controller' => 'Session'], function ($routes) {
$routes->extensions(['json']);

$routes->connect('/:key', ['action' => 'check', '_method' => 'CHECK'], ['pass' => ['key']]);
$routes->connect('/:key', ['action' => 'read', '_method' => 'GET'], ['pass' => ['key']]);
$routes->connect('/', ['action' => 'write', '_method' => 'POST']);
$routes->connect('/:key', ['action' => 'delete', '_method' => 'DELETE'], ['pass' => ['key']]);
});
});
// Router::scope('/session', ['plugin' => 'Restful'], function ($routes) {
// $routes->scope('/', ['controller' => 'Session'], function ($routes) {
// $routes->extensions(['json']);

// $routes->connect('/:key', ['action' => 'check', '_method' => 'CHECK'], ['pass' => ['key']]);
// $routes->connect('/:key', ['action' => 'read', '_method' => 'GET'], ['pass' => ['key']]);
// $routes->connect('/', ['action' => 'write', '_method' => 'POST']);
// $routes->connect('/:key', ['action' => 'delete', '_method' => 'DELETE'], ['pass' => ['key']]);
// });
// });

/**
* Load all plugin routes. See the Plugin documentation on
Expand Down
14 changes: 0 additions & 14 deletions plugins/ControllerAction/src/Model/Traits/SecurityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,11 @@ public function paramsDecode($params)
$signature = $this->urlsafeB64Decode($signature);

$payload = json_decode($payload, true);
$sessionId = Security::hash('session_id', 'sha256');
if (!isset($payload[$sessionId])) {
throw new SecurityException('No session id in payload');
} else {
$checkPayload = $payload;
$checkPayload[$sessionId] = session_id();
$checkSignature = Security::hash(json_encode($checkPayload), 'sha256', true);
if ($signature !== $checkSignature) {
throw new SecurityException('Query String has been tampered');
}
}
unset($payload[$sessionId]);
return $payload;
}

public function paramsEncode($params = [])
{
$sessionId = Security::hash('session_id', 'sha256');
$params[$sessionId] = session_id();
$jsonParam = json_encode($params);
$base64Param = $this->urlsafeB64Encode($jsonParam);
$signature = Security::hash($jsonParam, 'sha256', true);
Expand Down
4 changes: 3 additions & 1 deletion webroot/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_php7.c>
php_flag session.use_trans_sid off
</IfModule>

0 comments on commit 2beb056

Please sign in to comment.