Environment Guard keeps a staging, development or local copy of a site from acting like production after a database clone: it reroutes or blocks mail, refuses calls to production-only hosts, holds cron jobs and queues, keeps Commerce payment gateways off live providers and refuses webhooks the copy does not own. On production it only reports.
Status: Stable. 1.0.0 is the first release.
Why
A copy of a production database brings production's configuration with it: mail settings, payment keys, ERP and CRM endpoints, cron jobs and queued work. Unless someone remembers every switch, every time, the copy emails customers, calls production systems, charges cards and answers webhooks meant for production. Anything stored in that database would identify the copy as production, so this module decides from settings.php and the hosting platform instead, on every request.
Features
Knowing which environment it is
- The environment comes from
$settings['environment_guard']in settings.php, or from a variable:ENVIRONMENT_GUARD_ENVIRONMENTon any host, a variable you name in settings.php, or the ones Pantheon, Acquia, Platform.sh and Upsun, Lagoon, Tugboat, DDEV and Lando set. Never from the database. - Staging, development and local copies each have their own policy. A production answer loses to any source that recognizes a non-production environment, so a production line copied into a development settings.php cannot switch the guard off.
- An environment nothing identifies gets a lockdown policy built in code: mail blocked, outbound requests refused, cron jobs and queues outside core held, payment gateways disabled and webhook routes refused. A database edit cannot loosen it; only settings.php can.
- Send as addressed, reroute to listed addresses with an optional subject prefix, or block and log. Rerouted mail keeps the original recipients in
X-Environment-Guard-Original-To,-Ccand-Bccheaders. - An "always deliver to" list, with wildcards such as
*@example.com. Every To, Cc and Bcc recipient counts, and a recipient the module cannot read blocks the message. - Core mail, Mail System, Symfony Mailer Lite and Drupal Symfony Mailer Plus are guarded, through
hook_mail_alter()and Symfony Mailer's message event (Mailer Plus with the limits below). Mail waiting in Queue Mail's or Mailgun's queue is checked again when it is sent.
Outbound HTTP
- A Guzzle middleware on Drupal's HTTP client, which also sees every redirect. Refuse the listed hosts, or allow only the listed hosts; the refused list applies in both modes.
- Host patterns:
api.example.com,*.example.com(subdomains),.example.com(the domain and its subdomains), IP addresses, IPv4 and IPv6 ranges such as10.0.0.0/8, or*. - A refused request fails with a Guzzle
RequestException, so existing error handling treats it as a failed call.
Cron jobs and queues
- Skip the cron jobs of chosen modules, and suspend chosen queues by queue worker ID or Advanced Queue queue ID, with wildcards. Suspended queues keep their items. The hold applies to core cron,
drush queue:run, other runners that use Drupal's queue worker manager, and Advanced Queue. - After a database copy, everything outside core is held until someone acknowledges the copy, so work queued on the source (order exports, CRM syncs, queued mail) is not run by the copy's first cron. Core's own housekeeping keeps running. On by default for each environment type.
Payment gateways and webhooks
- Commerce payment gateways are forced into test mode, disabled, or kept as stored, through a configuration override: nothing is written to the database, and the gateway's edit form says what applies on this environment. A gateway the guard disables also has its credentials blanked, so refunds, captures, saved-card deletion and recurring charges cannot reach the provider.
- In test mode, a gateway with a live-format key is disabled (on by default), whether the key is stored, set in settings.php or supplied by the Key module. A gateway saved by code while the override is in force gets its stored values back first, so an export from a copy never carries test mode or blank keys to production.
- Listed webhook routes, by route name with wildcards, are refused before any controller runs; Commerce's
commerce_payment.notifyis listed by default. They are answered with 403 (the default), 404, 410 or 503, or with 200, 202 or 204 to acknowledge and drop. Refused responses are never cached.
Checks and reports
drush environment-guard:check, to run after a database clone, reports the environment and how it was identified, the policy in force, a copied database not yet acknowledged, items waiting in queues outside core, live payment gateways, live-format keys and other credentials stored in configuration, integrations that outbound filtering cannot reach, and an Environment Indicator label that disagrees. It exits 1 on danger, and takes--fail-on-warningand--format=jsonfor pipelines.drush environment-guard:check --acknowledgeclears a reported copy and lets held cron jobs and queues resume.drush environment-guard:statusshows the environment and policy, anddrush environment-guard:activitylists what was blocked, rerouted, skipped or refused.- A report page with the same check, the policy in force and activity counts, and a status report entry with the worst findings.
- For other code: environment and policy resolver services, service tags for your own detectors and checks, an event whenever something is enforced, and the
environment_guard_environmentcache context.
Requirements
- Drupal 11.3 or later, or Drupal 12.
- PHP 8.3 or later.
- No other modules. Optional: Drupal Commerce 3.x or 4.x (Commerce Payment) for the payment policy; Key 1.23 or later, whose credentials are judged like stored ones; Mail System 4.5 or later, Symfony Mailer Lite 2.x and Drupal Symfony Mailer Plus 2.x, whose mail is guarded; Environment Indicator, whose label is checked; Drush, for the commands.
- Any database Drupal supports (MySQL or MariaDB, PostgreSQL, SQLite) and any host. No hosting platform is required.
Installation
Install with Composer, then enable the module:
composer require drupal/environment_guard drush en environment_guard
Declare production in settings.php before you enable the module there, unless your host is detected automatically: an environment nothing identifies gets the lockdown policy, which blocks mail and outbound calls on purpose. Drush and cron run from a crontab see only their shell's environment, so a variable set for the web server alone leaves the command line in lockdown. The README explains both.
Configuration and permissions
The environment is declared in settings.php, never in the admin UI. The policies for staging, development and local copies are at Administration » Configuration » Development » Environment Guard (/admin/config/development/environment-guard). The report, with the post-clone check and the Acknowledge button, is at Reports » Environment Guard (/admin/reports/environment-guard).
- Administer Environment Guard (restricted): change what copies of the site do with mail, outbound HTTP, cron jobs and queues, payment gateways and webhooks, acknowledge a copied database and reset the activity counters. Loosening the policy lets a copy contact real customers and production systems.
- View the Environment Guard report (restricted): see the detected environment, the policy in force, the check's findings and what was blocked, including which configuration objects hold credentials.
What it does not cover
Outbound filtering sits in Drupal's HTTP client, so libraries that build their own client are not filtered: Search API Solr (give each environment its own Solr core in settings.php), Stripe's PHP library (gateways are guarded by the payment override instead), the AWS SDK used by S3 File System and others, Google's API clients, PHP's SoapClient, Symfony HttpClient and raw cURL. The check names Search API Solr, Commerce Stripe and S3 File System when they are installed.
Skipping cron jobs per module works through core's cron service only, so Ultimate Cron's jobs are not skipped; queue suspension still applies. Native mail from Drupal Symfony Mailer Plus is guarded only when its transports dispatch Symfony Mailer's events, as 2.x does with its Mailer Transport module enabled, and the check warns otherwise; native mail from its 1.x branch is not guarded. Host patterns match the host as written, without resolving DNS, so this is a policy about which systems a copy may talk to, not an SSRF filter. Credential detection reads configuration only.
Similar projects
Checked on drupal.org in November 2026.
- Reroute Email reroutes outgoing mail to chosen addresses. Choose it if mail is all you need to control. Its Drupal 11 support is in a 2024 release candidate. Both can be installed: this module runs after it and keeps its record of the original recipients.
- Environment Indicator shows which environment you are on. It enforces nothing; use it together with this module, which warns when the indicator's label disagrees with the detected environment.
- Production check & Production monitor checks whether a site is set up safely for production. Its releases go up to Drupal 10, and it is seeking a new maintainer.
- Configuration Split keeps different configuration for each environment, applied when configuration is imported. It is the right tool for per-environment configuration in general; until the next import, a cloned database still runs production's configuration.
Support and maintenance
Report bugs and ask for features in the issue queue. Each release has notes describing what changed.
This project is not covered by Drupal's security advisory policy. Until it is, security issues are handled in the public issue queue and fixed in ordinary releases.
A read-only mirror is on GitHub at DanePete/drupal-environment-guard; development and issues stay on drupal.org.
Maintainer
Created and maintained by deadnorth (Dead North).
Ask your assistant about Environment Guard
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 1.0.0 | Stable | 11 | PHP >=8.3 | Nov 27, 2026 |