Skip to content

Commit

Permalink
PB-32932 Fix reflective HTML injection vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanvyas22 committed Apr 11, 2024
1 parent 1a06527 commit 5c53784
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
8 changes: 6 additions & 2 deletions templates/Error/error400.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php
/**
* @var \App\View\AppView $this
* @var string $message
*/
use Cake\Core\Configure;
use Cake\Error\Debugger;

$this->layout = 'error';
$this->assign('title', $message);
$this->assign('title', __('Error'));
$this->assign('pageClass', 'error-404');
?>
<div class="grid">
Expand Down Expand Up @@ -31,5 +35,5 @@
<?= $this->element('auto_table_warning') ?>
<?php if (extension_loaded('xdebug')): xdebug_print_function_stack(); endif; ?>
</div>
<?php endif;?>
<?php endif; ?>
</div>
6 changes: 5 additions & 1 deletion templates/Error/error500.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php
/**
* @var \App\View\AppView $this
* @var string $message
*/
use Cake\Core\Configure;
use Cake\Error\Debugger;

$this->layout = 'error';
$this->assign('pageClass', 'error-500');
$this->assign('title', $message);
$this->assign('title', __('Error'));
?>
<div class="grid">
<div class="row">
Expand Down
64 changes: 64 additions & 0 deletions tests/TestCase/Controller/ErrorControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);

/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
* @since 4.7.0
*/
namespace App\Test\TestCase\Controller;

use App\Test\Lib\AppIntegrationTestCase;
use Cake\Core\Configure;

/**
* @covers \App\Controller\ErrorController
*/
class ErrorControllerTest extends AppIntegrationTestCase
{
public function testErrorController_HTML_404(): void
{
Configure::write('debug', false);

$this->get('/a-route-that-is-not-found');

$resultHtml = $this->_getBodyAsString();
$this->assertResponseError();
$this->assertResponseCode(404);
$this->assertTextContains('<title>Passbolt | Error</title>', $resultHtml);
$this->assertTextContains('<h2>Not Found</h2>', $resultHtml);
$this->assertTextContains('The requested address was not found on this server.', $resultHtml);
}

public function testErrorController_HTML_400_TitleAndErrorMessagePurified(): void
{
$this->get('/users/?sort=1</title></br></br><h1>Defaced</h1>');

$this->assertResponseError();
$this->assertResponseCode(400);
$resultHtml = $this->_getBodyAsString();
$this->assertTextContains('<title>Passbolt | Error</title>', $resultHtml);
$expectedFilteredMsg = 'Invalid order. ' . h('"1</title></br></br><h1>Defaced</h1>"') . ' is not in the list of allowed order';
$this->assertTextContains($expectedFilteredMsg, $resultHtml);
}

public function testErrorController_HTML_500(): void
{
Configure::write('passbolt.healthcheck.error', true);

$this->get('/healthcheck/error');

$this->assertResponseCode(500);
$resultHtml = $this->_getBodyAsString();
$this->assertTextContains('<title>Passbolt | Error</title>', $resultHtml);
$this->assertTextContains('<h2>An Internal Error Has Occurred</h2>', $resultHtml);
}
}

0 comments on commit 5c53784

Please sign in to comment.