Skip to content

Fix deprecations panel empty check, escape variables panel error, reset $data in serialize loop#1072

Merged
LordSimal merged 1 commit into
5.xfrom
fix-deprecations-panel-and-error-escape
May 13, 2026
Merged

Fix deprecations panel empty check, escape variables panel error, reset $data in serialize loop#1072
LordSimal merged 1 commit into
5.xfrom
fix-deprecations-panel-and-error-escape

Conversation

@dereuromark

Copy link
Copy Markdown
Member

Summary

Three small correctness fixes surfaced during a 5.x audit:

  • DeprecationsPanel template -- the empty-check sum was missing count($other), and the surrounding condition was inverted so the "No deprecations" flash showed up exactly when deprecations existed. Adds $other to the sum and flips to if (!$hasAny).

  • Variables panel template -- $error came through printf %s unescaped. That message can carry serializer-exception text echoing back data from whatever variable failed to serialize, so it's now passed through h(). A use function Cake\Core\h; was added to match the convention used by sibling templates.

  • ToolbarService::saveData -- $data was declared inside the per-panel try. When a panel's data() method itself threw (before the inner serialize()), the catch block's gettype($data ?? null) diagnostic reported the previous panel's data type instead of NULL. Reset $data = null; per loop iteration.

Regression coverage is added in PanelsControllerTest (empty / non-empty / $other-only deprecations, plus <script> escaping in the variables panel) and in ToolbarServiceTest (data() itself throwing, via a new tests/test_app/Panel/ThrowingDataPanel.php fixture).

…et $data in serialize loop

* DeprecationsPanel template: the empty-check sum was missing count($other),
  and the surrounding condition was inverted -- the "No deprecations" flash
  showed up exactly when deprecations existed. Include $other and flip to
  `if (!$hasAny)`.

* Variables panel template: $error came through `printf %s` unescaped. The
  message can carry serializer-exception text that echoes back data from
  whatever variable failed to serialize, so escape it via h().

* ToolbarService::saveData: $data was declared inside `try`, so when a panel's
  data() itself threw, the catch block's `gettype($data ?? null)` diagnostic
  reported the previous iteration's panel data type instead of NULL. Reset
  $data = null per iteration.

Adds integration tests covering each fix (deprecations empty / non-empty /
other-only, variables panel error escaping, panel data() throwing).
@dereuromark dereuromark added this to the 5.x milestone May 13, 2026
@LordSimal LordSimal merged commit 670d0af into 5.x May 13, 2026
6 of 7 checks passed
@LordSimal LordSimal deleted the fix-deprecations-panel-and-error-escape branch May 13, 2026 18:36
LordSimal added a commit that referenced this pull request May 14, 2026
Nits + BC correctness fixes from 5.x audit (followup to #1072)
pmanolak pushed a commit to pmanolak/debug_kit that referenced this pull request Jul 10, 2026
Small, fully backwards-compatible corrections collected from the same audit
pass that produced PR cakephp#1072:

* CredentialsHelper: swap the click handler from `this.innerHTML = this.title`
  to `this.textContent = this.title` so a credential URL that ever carries
  HTML-looking bytes cannot render live HTML when revealed.

* ToolbarController::clearCache: bail with `NotFoundException` when the
  posted cache engine name is not configured, instead of returning 200 with
  `success: false`. The 200/false case was the only way for the endpoint to
  silently misreport failure.

* RequestPanel: collect the GET payload via `$request->getQueryParams()`
  instead of `$_GET` so the panel reflects the request as middleware sees it.

* Templates: escape `$pluginName` in routes_panel, escape the file path in
  request_panel's "headers already sent" warning, guard `end($timers)` in
  timer_panel against an empty array, and replace `extract($package)` in
  packages_panel with explicit destructuring so a future composer.lock schema
  key cannot clobber template locals.

* DebugKitTransport: override the parent `send()` return-type docblock with
  the actual shape (assoc headers array + text/html parts split) so static
  analysis stops papering over the LSP gap, and reject construction without
  a valid `debugKitLog` ArrayObject up front with a clear
  InvalidArgumentException rather than a downstream TypeError.

* ToolbarService::saveData: move `restore_error_handler()` into a `finally`
  block guarded by an `$handlerInstalled` flag, and narrow the captured
  error mask to `E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE`
  so non-serialization warnings raised during `serialize()` aren't
  misreported as panel-serialization failures.

* Drop the now-stale DebugKitTransport return-type entry from the PHPStan
  baseline.

Tests added: CredentialsHelper data provider updated for the new onclick;
ToolbarControllerTest gains an unknown-engine 404 case; DebugKitTransportTest
gains two constructor-rejection cases (missing key, wrong type).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants