Skip to content

Commit

Permalink
🔒️ Don't leak env values into $_SERVER (#598)
Browse files Browse the repository at this point in the history
Updates to using a custom repository for `Dotenv` instead of the default
which includes `ServerConstAdapter`.

The new custom repository *only* includes `EnvConstAdapter`.

The `$_SERVER` superglobal often gets dumped into logs or into
monitoring services so it's better for security to avoid populating it
with secrets contained in `.env`.

Co-authored-by: Ben Word <[email protected]>
  • Loading branch information
swalkinshaw and retlehs authored Dec 14, 2024
1 parent dd56b83 commit d1704f7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion config/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@
? ['.env', '.env.local']
: ['.env'];

$dotenv = Dotenv\Dotenv::createImmutable($root_dir, $env_files, false);
$repository = Dotenv\Repository\RepositoryBuilder::createWithNoAdapters()
->addAdapter(Dotenv\Repository\Adapter\EnvConstAdapter::class)
->addAdapter(Dotenv\Repository\Adapter\PutenvAdapter::class)
->immutable()
->make();

$dotenv = Dotenv\Dotenv::create($repository, $root_dir, $env_files, false);
$dotenv->load();

$dotenv->required(['WP_HOME', 'WP_SITEURL']);
Expand Down

0 comments on commit d1704f7

Please sign in to comment.