Skip to content

Fix GRAV_CONFIG env override gate to also check $_SERVER/$_ENV - #4285

Closed
wakqasahmed wants to merge 1 commit into
getgrav:developfrom
wakqasahmed:fix/env-fallback-getenv-only-4279
Closed

Fix GRAV_CONFIG env override gate to also check $_SERVER/$_ENV#4285
wakqasahmed wants to merge 1 commit into
getgrav:developfrom
wakqasahmed:fix/env-fallback-getenv-only-4279

Conversation

@wakqasahmed

Copy link
Copy Markdown
Contributor

The GRAV_CONFIG override gate in InitializeProcessor::initializeConfig() checks getenv($prefix), but the body one line below already reads $_ENV + $_SERVER. On Apache with SetEnv or nginx with fastcgi_param, the variable lands in $_SERVER but never in the process environment getenv() reads, so the gate is false and the whole GRAV_CONFIG__* override feature does nothing — same failure mode as #4260/#4275.

Setup.php has the identical pattern for GRAV_ENVIRONMENT, GRAV_SETUP_PATH, GRAV_ENVIRONMENT_PATH and GRAV_ENVIRONMENTS_PATH.

Env.php already solves this correctly ($_SERVER[$key] ?? $_ENV[$key] ?? (getenv($key) ?: null)) and has its own test coverage proving the precedence. This PR applies the same fallback at all five call sites instead of inventing a new pattern.

Added a test that sets the override only in $_SERVER and drives the real initializeConfig() — confirmed it fails against the old code and passes against the fix. Ran the full InitializeProcessorTest and EnvTest suites after, both green (59 tests).

Fixes #4279

…etenv()

Some SAPIs (Apache SetEnv, nginx fastcgi_param) only populate $_SERVER,
never the process environment getenv() reads. The gate at
InitializeProcessor::initializeConfig() checked getenv() alone even
though the body one line below already reads $_ENV + $_SERVER, so the
whole GRAV_CONFIG__* override feature silently did nothing under those
setups. Setup.php had the same getenv()-only pattern for
GRAV_ENVIRONMENT, GRAV_SETUP_PATH, GRAV_ENVIRONMENT_PATH and
GRAV_ENVIRONMENTS_PATH.

Applies the same $_SERVER ?? $_ENV ?? getenv() fallback Env.php already
uses (and already has test coverage for) at all five call sites. Added
a regression test that fails on the old code and passes on the fix.

Fixes getgrav#4279
@wakqasahmed

wakqasahmed commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #4286

@wakqasahmed wakqasahmed closed this Sep 4, 2026
@wakqasahmed
wakqasahmed deleted the fix/env-fallback-getenv-only-4279 branch September 4, 2026 21:05
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.

getenv()-only reads in the bootstrap: the GRAV_CONFIG gate and the GRAV_ENVIRONMENT family

1 participant