Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,29 @@ public function resetForWorkerMode(): void
// Reset timing
$this->startTime = null;
$this->totalTime = 0;

$this->resetKintForWorkerMode();
}

/**
* Resets Kint request-specific state for worker mode.
*/
private function resetKintForWorkerMode(): void
{
if (! CI_DEBUG || ! class_exists(Kint::class, false)) {
return;
}

$csp = service('csp');
if ($csp->enabled()) {
RichRenderer::$js_nonce = $csp->getScriptNonce();
RichRenderer::$css_nonce = $csp->getStyleNonce();
} else {
RichRenderer::$js_nonce = null;
RichRenderer::$css_nonce = null;
}

RichRenderer::$needs_pre_render = true;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/system/CodeIgniterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Config\Filters as FiltersConfig;
use Config\Modules;
use Config\Routing;
use Kint\Renderer\RichRenderer;
use PHPUnit\Framework\Attributes\BackupGlobals;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
Expand Down Expand Up @@ -1273,6 +1274,15 @@ public function testRouteAttributesDisabledInConfig(): void

public function testResetForWorkerMode(): void
{
$this->resetServices();

$appConfig = config(App::class);
$appConfig->CSPEnabled = true;

RichRenderer::$js_nonce = 'stale-script-nonce';
RichRenderer::$css_nonce = 'stale-style-nonce';
RichRenderer::$needs_pre_render = false;

$config = new App();
$codeigniter = new MockCodeIgniter($config);

Expand All @@ -1292,5 +1302,11 @@ public function testResetForWorkerMode(): void
$this->assertNull($this->getPrivateProperty($codeigniter, 'controller'));
$this->assertNull($this->getPrivateProperty($codeigniter, 'method'));
$this->assertNull($this->getPrivateProperty($codeigniter, 'output'));

$csp = service('csp');

$this->assertSame($csp->getScriptNonce(), RichRenderer::$js_nonce);
$this->assertSame($csp->getStyleNonce(), RichRenderer::$css_nonce);
$this->assertTrue(RichRenderer::$needs_pre_render);
}
}
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Bugs Fixed
- **CLI:** Fixed a bug where ``CLI::generateDimensions()`` leaked ``stty`` error output (e.g., ``stty: 'standard input': Inappropriate ioctl for device``) to stderr when stdin was not a TTY.
- **Commands:** Fixed a bug in the ``env`` command where passing options only would cause the command to throw a ``TypeError`` instead of showing the current environment.
- **Common:** Fixed a bug where the ``command()`` helper function did not properly clean up output buffers, which could lead to risky tests when exceptions were thrown.
- **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets.
- **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.

See the repo's
Expand Down
Loading