Skip to content

Commit cb47da2

Browse files
dereuromarkclaude
andcommitted
Fix PHPStan failure by only enforcing fullBaseUrl in web context
The security check was throwing an exception during PHPStan static analysis because it runs with debug=false but no HTTP_HOST. Modified the logic to only enforce the fullBaseUrl requirement when in a web request context (HTTP_HOST is present). This allows CLI tools like PHPStan to load the bootstrap without errors while still maintaining the security check for actual web requests in production. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d4574fa commit cb47da2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

config/bootstrap.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@
158158
*/
159159
$fullBaseUrl = Configure::read('App.fullBaseUrl');
160160
if (!$fullBaseUrl) {
161-
if (!Configure::read('debug')) {
161+
$httpHost = env('HTTP_HOST');
162+
163+
/*
164+
* Only enforce fullBaseUrl requirement when we're in a web request context.
165+
* This allows CLI tools (like PHPStan) to load the bootstrap without throwing.
166+
*/
167+
if (!Configure::read('debug') && $httpHost) {
162168
throw new \Cake\Core\Exception\CakeException(
163169
'SECURITY: App.fullBaseUrl is not configured. ' .
164170
'This is required in production to prevent Host Header Injection attacks. ' .
@@ -170,13 +176,11 @@
170176
* Development mode fallback: Use HTTP_HOST for convenience.
171177
* WARNING: This is ONLY safe in development. Never use this pattern in production!
172178
*/
173-
$s = null;
174-
if (env('HTTPS')) {
175-
$s = 's';
176-
}
177-
178-
$httpHost = env('HTTP_HOST');
179179
if ($httpHost) {
180+
$s = null;
181+
if (env('HTTPS')) {
182+
$s = 's';
183+
}
180184
$fullBaseUrl = 'http' . $s . '://' . $httpHost;
181185
}
182186
unset($httpHost, $s);

0 commit comments

Comments
 (0)