Skip to content

fix: cast boolean env() values to prevent type errors - #5046

Open
tuxpiper wants to merge 1 commit into
developfrom
fix/bool-cast-env-config
Open

fix: cast boolean env() values to prevent type errors#5046
tuxpiper wants to merge 1 commit into
developfrom
fix/bool-cast-env-config

Conversation

@tuxpiper

@tuxpiper tuxpiper commented Mar 3, 2026

Copy link
Copy Markdown
Member

Symfony's HtmlErrorRenderer strictly validates that its debug argument is bool|callable, but env() can return strings. Add explicit (bool) casts to all boolean config values sourced from env().

This is one of the most often seen logs in production:

[2026-03-03 04:26:31] production.ERROR: Argument 1 passed to "Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer::__construct()" must be a boolean or a callable, "string" given. {"exception":"[object] (TypeError(code: 0): Argument 1 passed to \"Symfony\\Component\\ErrorHandler\\ErrorRenderer\\HtmlErrorRenderer::__construct()\" must be a boolean or a callable, \"string\" given. at /var/www/vendor/symfony/error-handler/ErrorRenderer/HtmlErrorRenderer.php:53)
[stacktrace]
#0 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(566): Symfony\\Component\\ErrorHandler\\ErrorRenderer\\HtmlErrorRenderer->__construct()
#1 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(520): Illuminate\\Foundation\\Exceptions\\Handler->renderExceptionWithSymfony()
#2 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(503): Illuminate\\Foundation\\Exceptions\\Handler->renderExceptionContent()
#3 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(482): Illuminate\\Foundation\\Exceptions\\Handler->convertExceptionToResponse()
#4 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(356): Illuminate\\Foundation\\Exceptions\\Handler->prepareResponse()
#5 /var/www/app/Exceptions/Handler.php(171): Illuminate\\Foundation\\Exceptions\\Handler->render()
#6 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(51): App\\Exceptions\\Handler->render()
#7 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(172): Illuminate\\Routing\\Pipeline->handleException()
#8 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#9 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#10 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\\Foundation\\Http\\Kernel->handle()
#11 /var/www/httpdocs/index.php(77): Illuminate\\Foundation\\Http\\Kernel->handle()
#12 {main}

Changes

  • config/app.php: debug (the value that directly triggers the crash above)
  • config/database.php: strict, redis.cluster
  • config/routes.php: private_only
  • config/sentry.php: queue_job_transactions, send_default_pii
  • config/session.php: secure — also flows into a strictly-typed Symfony constructor (Cookie). Its default is null, which Laravel treats as "auto-detect from request scheme," so it's only cast to bool when the env var is actually set, to avoid silently forcing it to false.

Test checklist

  • No behavior change for unset env vars — every default value round-trips through its own cast unchanged (false stays false, true stays true, null stays null).

  • Existing test suite passes.

  • I certify that I ran my checklist

Fixes ushahidi/platform# .

Ping @ushahidi/platform

Symfony's HtmlErrorRenderer strictly validates that its debug argument
is bool|callable, but env() can return strings. Add explicit (bool)
casts to all boolean config values sourced from env().

Also fixes config/session.php's 'secure' cookie flag, which flows into
Symfony's Cookie constructor (also strictly bool|null typed). Its
default of null carries auto-detect semantics in Laravel, so it is
cast to bool only when the env var is actually set, rather than
coerced unconditionally like the others.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tuxpiper
tuxpiper force-pushed the fix/bool-cast-env-config branch from 5fe10f9 to 81c76af Compare August 10, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant