Skip to content

Commit 423569f

Browse files
authored
Merge pull request from GHSA-hwxf-qxj7-7rfj
fix: detailed error report is displayed in production environment
2 parents 407c108 + f251a3c commit 423569f

File tree

12 files changed

+74
-7
lines changed

12 files changed

+74
-7
lines changed

app/Config/Boot/development.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
| In development, we want to show as many errors as possible to help
88
| make sure they don't make it to production. And save us hours of
99
| painful debugging.
10+
|
11+
| If you set 'display_errors' to '1', CI4's detailed error report will show.
1012
*/
1113
error_reporting(-1);
1214
ini_set('display_errors', '1');

app/Config/Boot/production.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
|--------------------------------------------------------------------------
77
| Don't show ANY in production environments. Instead, let the system catch
88
| it and display a generic error message.
9+
|
10+
| If you set 'display_errors' to '1', CI4's detailed error report will show.
911
*/
1012
ini_set('display_errors', '0');
1113
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);

app/Config/Boot/testing.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
22

3+
/*
4+
* The environment testing is reserved for PHPUnit testing. It has special
5+
* conditions built into the framework at various places to assist with that.
6+
* You can’t use it for your development.
7+
*/
8+
39
/*
410
|--------------------------------------------------------------------------
511
| ERROR DISPLAY

app/Views/errors/html/error_404.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<?= nl2br(esc($message)) ?>
7878
<?php else : ?>
7979
<?= lang('Errors.sorryCannotFind') ?>
80-
<?php endif ?>
80+
<?php endif; ?>
8181
</p>
8282
</div>
8383
</body>

app/Views/errors/html/error_exception.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<?php endif; ?>
4545
</div>
4646

47+
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) : ?>
4748
<div class="container">
4849

4950
<ul class="tabs" id="tabs">
@@ -66,7 +67,7 @@
6667
<li>
6768
<p>
6869
<!-- Trace info -->
69-
<?php if (isset($row['file']) && is_file($row['file'])) :?>
70+
<?php if (isset($row['file']) && is_file($row['file'])) : ?>
7071
<?php
7172
if (isset($row['function']) && in_array($row['function'], ['include', 'include_once', 'require', 'require_once'], true)) {
7273
echo esc($row['function'] . ' ' . clean_path($row['file']));
@@ -375,14 +376,16 @@
375376
</div> <!-- /tab-content -->
376377

377378
</div> <!-- /container -->
379+
<?php endif; ?>
378380

379381
<div class="footer">
380382
<div class="container">
381383

382384
<p>
383385
Displayed at <?= esc(date('H:i:sa')) ?> &mdash;
384386
PHP: <?= esc(PHP_VERSION) ?> &mdash;
385-
CodeIgniter: <?= esc(CodeIgniter::CI_VERSION) ?>
387+
CodeIgniter: <?= esc(CodeIgniter::CI_VERSION) ?> --
388+
Environment: <?= ENVIRONMENT ?>
386389
</p>
387390

388391
</div>

system/Debug/ExceptionHandler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ protected function determineView(Throwable $exception, string $templatePath): st
129129
// Production environments should have a custom exception file.
130130
$view = 'production.php';
131131

132-
if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') {
132+
if (
133+
in_array(
134+
strtolower(ini_get('display_errors')),
135+
['1', 'true', 'on', 'yes'],
136+
true
137+
)
138+
) {
133139
$view = 'error_exception.php';
134140
}
135141

system/Debug/Exceptions.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ protected function determineView(Throwable $exception, string $templatePath): st
253253
$view = 'production.php';
254254
$templatePath = rtrim($templatePath, '\\/ ') . DIRECTORY_SEPARATOR;
255255

256-
if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') {
256+
if (
257+
in_array(
258+
strtolower(ini_get('display_errors')),
259+
['1', 'true', 'on', 'yes'],
260+
true
261+
)
262+
) {
257263
$view = 'error_exception.php';
258264
}
259265

tests/system/Debug/ExceptionHandlerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ public function testDetermineViewsRuntimeExceptionCode404(): void
7070
$this->assertSame('error_404.php', $viewFile);
7171
}
7272

73+
public function testDetermineViewsDisplayErrorsOffRuntimeException(): void
74+
{
75+
ini_set('display_errors', '0');
76+
77+
$determineView = $this->getPrivateMethodInvoker($this->handler, 'determineView');
78+
79+
$exception = new RuntimeException('Exception');
80+
$templatePath = APPPATH . 'Views/errors/html';
81+
$viewFile = $determineView($exception, $templatePath);
82+
83+
$this->assertSame('production.php', $viewFile);
84+
85+
ini_set('display_errors', '1');
86+
}
87+
7388
public function testCollectVars(): void
7489
{
7590
$collectVars = $this->getPrivateMethodInvoker($this->handler, 'collectVars');

user_guide_src/source/changelogs/v4.4.3.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Release Date: Unreleased
99
:local:
1010
:depth: 3
1111

12+
SECURITY
13+
********
14+
15+
- *Detailed Error Report is Displayed in Production Environment* was fixed.
16+
See the `Security advisory GHSA-hwxf-qxj7-7rfj <https://github.com/codeigniter4/CodeIgniter4/security/advisories/GHSA-hwxf-qxj7-7rfj>`_
17+
for more information.
18+
1219
BREAKING
1320
********
1421

user_guide_src/source/general/environments.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ By default, CodeIgniter has three environments defined.
3030
If you want another environment, e.g., for staging, you can add custom environments.
3131
See `Adding Environments`_.
3232

33+
.. _setting-environment:
34+
3335
*******************
3436
Setting Environment
3537
*******************

0 commit comments

Comments
 (0)