Skip to content

Commit

Permalink
Update PagesController to reflect current app skeleton.
Browse files Browse the repository at this point in the history
Includes security fixes for path traversal.
  • Loading branch information
markstory committed Sep 2, 2017
1 parent cdf7fbb commit b972831
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/Controller/PagesController.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 0.2.9
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace App\Controller;

use Cake\Core\Configure;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;

Expand All @@ -23,26 +24,29 @@
*
* This controller will render views from Template/Pages/
*
* @link http://book.cakephp.org/3.0/en/controllers/pages-controller.html
* @link https://book.cakephp.org/3.0/en/controllers/pages-controller.html
*/
class PagesController extends AppController
{

/**
* Displays a view
*
* @return void|\Cake\Network\Response
* @param array ...$path Path segments.
* @return \Cake\Http\Response|null
* @throws \Cake\Network\Exception\ForbiddenException When a directory traversal attempt.
* @throws \Cake\Network\Exception\NotFoundException When the view file could not
* be found or \Cake\View\Exception\MissingTemplateException in debug mode.
*/
public function display()
public function display(...$path)
{
$path = func_get_args();

$count = count($path);
if (!$count) {
return $this->redirect('/');
}
if (in_array('..', $path, true) || in_array('.', $path, true)) {
throw new ForbiddenException();
}
$page = $subpage = null;

if (!empty($path[0])) {
Expand All @@ -55,9 +59,9 @@ public function display()

try {
$this->render(implode('/', $path));
} catch (MissingTemplateException $e) {
} catch (MissingTemplateException $exception) {
if (Configure::read('debug')) {
throw $e;
throw $exception;
}
throw new NotFoundException();
}
Expand Down

0 comments on commit b972831

Please sign in to comment.