Skip to content

Harden the debugbar for production mode - #74

Merged
allrude merged 1 commit into
mainfrom
lane-2/production-hardening
Nov 19, 2026
Merged

allrude merged 1 commit into
mainfrom
lane-2/production-hardening

Conversation

@allrude

@allrude allrude commented Nov 19, 2026

Copy link
Copy Markdown
Member

Hardens the bar for live shops. Developer and default mode behave as before.

In production deploy mode only:

  1. allowed_ips must be non empty, otherwise the bar is off (it used to mean everyone).
  2. The access key is read from the X-Siteation-DebugBar-Key header or the cookie, never the URL parameter. No cookie swap or redirect either.
  3. The enabled switch only counts when set in env.php or config.php (config:set --lock-env), not the admin/database value.
  4. A warning finding ("The debug bar is running in production mode") is added to every profile via a new ProductionModeRule.
  5. Nothing is built while the bar is off: new dependency free CollectionState replaces ProfileManager::isCollecting() in the seven plugins, which now hold the manager and their collectors behind proxies in etc/di.xml.

Breaking in production: a URL key, an empty allowed_ips, or an admin saved switch stops working. Plugin constructors take CollectionState first and ProfileManager takes it before $collectors. Run setup:di:compile after upgrading.

Notes for review:

  • The header stays an accepted channel in production (agents, MCP and curl need it). Only the URL parameter is dropped.
  • The deployment config is read at system/default/... only, not per website or store.
  • The warning is a finding rather than a bar JS change, so the committed bundle is untouched.

Docs: user guide "Production mode", developer guide, README, CHANGELOG. LazyPluginsTest pins the proxy wiring in di.xml.

@allrude

allrude commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review at 3dd8315: FAIL

One docs gap, code otherwise sound. CI: JS and PHP 8.2 to 8.5 all pass at this head, MERGEABLE.

Must fix (docs)

  1. The BC note covers only the 7 plugin constructors. Two more public constructors changed and are not mentioned: ProfileManager (new CollectionState before $collectors) and Config (new DeploymentConfig inserted before $maxProfiles, so positional callers break). Add both to the CHANGELOG line.
  2. Nothing says the next release is a minor. The entry is under Unreleased with no version, and it calls itself breaking in production mode (empty allowed_ips or a URL key or a DB-only enabled now means off). Say it in the CHANGELOG, and tag as 1.6.0, not 1.5.4.
  3. IMP Release 1.5.3 changelog #73 merged after this branch was cut. This diff still sits on the old [Unreleased]: ...1.5.1...main context. Rebase and put the Security block under the new empty Unreleased heading, not under [1.5.3].

Verified

  • Developer and default mode unchanged: the enabled flag check is the same isSetFlag as before when not production; isProduction() is false there, so the URL key is still read and traded for a cookie.
  • Production gating: enabled read only from DeploymentConfig system/default/... (env.php and config.php, accepts true, 1, '1'). Empty allowed_ips returns off. URL key not read in wasPresentedInUrl or the candidate list, so no cookie swap and no redirect.
  • Nothing built with the bar off: all 7 plugin registrations in di.xml (Logger, Event manager, Invoker, Block, Layout, PageCacheKernel, Cache) take ProfileManager and every collector as \Proxy, and ask the dependency free CollectionState first. HttpPlugin already had its proxies. LazyPluginsTest asserts this from the constructor reflection plus di.xml, and that no plugin still calls manager->isCollecting(). Limit: this is a static proof, I did not trace a live object manager.
  • ProductionModeRule registered, warns only when the profile mode is production.

@allrude
allrude force-pushed the lane-2/production-hardening branch from 3dd8315 to 6448fc6 Compare November 19, 2026 22:55
@allrude

allrude commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review at 6448fc6: PASS

Re-review after the earlier FAIL at 3dd8315.

  • CHANGELOG: next release stated as a minor (1.6.0); Security block sits under the new Unreleased, after the merged 1.5.3 changelog (IMP Release 1.5.3 changelog #73).
  • BC note now names all three constructor changes. Checked against the code: plugins take CollectionState first, ProfileManager takes it before $collectors, Config takes DeploymentConfig before $maxProfiles. All match.
  • The old head is no longer fetchable (force push), so I judged the final diff against main: only the expected 27 files, no stray changes from the rebase. Production gates and the lazy plugin proxies in etc/di.xml unchanged in intent from the first review.
  • CI at this head: PHP 8.2, 8.3, 8.4, 8.5 and JS all pass, nothing pending.

@allrude
allrude merged commit 3d38aed into main Nov 19, 2026
5 checks passed
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.

1 participant