Urgent.News

What's breaking now, across thousands of outlets.

Editions

Tech

Laravel env() Outside config/: Catch Deployment Bugs Before config:cache

The bug only appears after configuration caching A Laravel application can behave perfectly during development and then fail after deployment because a service class reads an environment variable directly: // app/Services/AcmeClient.php $token = env ( 'ACME_TOKEN' ); Laravel's configuration cache changes the boot process. Once configuration has been cached, the framework does not load the…

After configuration caching, a Laravel application may perform normally during development but fail during deployment due to a service class reading an environment variable directly, as shown in this code snippet from app/Services/AcmeClient.php: $token = env('ACME_TOKEN'); When the Laravel configuration cache alters the boot process, it no longer loads the application's .env file for regular requests or Artisan commands.

Consequently, a direct env() call outside a configuration file may only return an external system value or its fallback value. To resolve this issue, developers should read the environment variable once from a configuration file. In config/services.php, this approach is demonstrated by defining an 'acme' array with a 'token' entry that reads env('ACME_TOKEN'): return [ 'acme' => [ 'token' => env('ACME_TOKEN'), ], ]; This primary fix aims to prevent the bug.

However, developers must also address environment drift, which occurs even when all env() calls are correctly placed. A project might contain multiple .env files, such as .env, .env.testing, .env.production, and .env.sample, each with different environment variables. For example, the .env file may contain APP_NAME=Codegenie ACME_TOKEN=local-secret, while the .env.production file includes APP_NAME=Codegenie.

As these values will differ, missing ACME_TOKEN key indicates an incomplete deployment contract. Other potential issues include duplicate keys, case-sensitive discrepancies, unused keys, and direct getenv() or $_ENV access. To minimize failures, a small manual review can be performed. This review recommends searching application-owned PHP files for env() calls and moving valid reads to config/, comparing key inventories of environment files, and checking phpunit.xml and .env.testing together.

Additionally, developers should review Vite import.meta.env and loadEnv() usage. Running the application with configuration cached before deployment is also recommended. Laravel Env Guard, a tool created by the author to automate this review process, can be installed as a development dependency using Composer. It scans application files for unsafe env() and Illuminate\Support\Env::get() calls outside config/, direct raw environment access, duplicate or case-mismatched keys, and drift across .env files.

By default, Laravel Env Guard runs during local console boots and does not require a separate audit command. The tool blocks findings by default, writing warnings and errors to STDERR during Artisan commands. Laravel Env Guard does not handle secrets, perform telemetry, or modify .env files. It intentionally excludes encrypted environment files, as auditing them requires decryption.

The package is a development guard, not a secret manager or deployment system. The current release, v1.2.1, supports Laravel 12 and 13 across PHP 8.2–8.5 combinations.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The GTA VI leak isn't really about GTA VI — it's an extortion playbook

Originally published in Spanish on El Rack . Browser translation handles the rest of the site fine if you're into homelab/security content.

  • GTA VI leak involves extortion, not accidental release
  • Cyberleek group demands changes in game industry practices
  • Leak follows 2022 attack on Rockstar Games servers

Taking the network away from a Cloud Run job

If you execute other people's code, at some point you have to decide what it is allowed to reach. Mine should reach nothing: no package registry, no pastebin, no callback to a server that tells it the…

  • Use unshare -rn -- ./run-the-untrusted-thing to strip network from Cloud Run job
  • Works only with second-generation Cloud Run environment with microVM
  • Set maxRetries to 0 to prevent automatic retries on failure

A container per job, without a daemon

Some workloads want an image each. A build that needs a specific toolchain, a test that needs a specific database client, a task whose dependencies are described by something other than a human.

  • Individual images for each task without Docker or build daemon
  • Package list provided to tools like apko for reproducible image
  • Eliminates build step, malicious input risk, and build-time entropy

More from Thursday 20 August →