Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4b1704f
PHPStan: Update to 2.3.5
westonruter Nov 4, 2026
8d4950f
PHPStan: Recommend `--fix` for out-of-date baseline entries
westonruter Nov 4, 2026
c413594
PHPStan: Introduce phpstan-strict-rules
westonruter Nov 6, 2026
c06810d
Legacy Widget: Validate the encoded instance before decoding it
westonruter Nov 6, 2026
f3ba78c
PHPStan: Enable the strict function calls rule
westonruter Nov 6, 2026
ca04efe
Merge branch 'trunk' into update/phpstan-2.3.5
westonruter Nov 6, 2026
50cbbe4
Merge branch 'update/phpstan-2.3.5' into add/phpstan-strict-rules
westonruter Nov 6, 2026
9f47b59
Docs: Give the PHPStan strict rules their own subsection
westonruter Nov 6, 2026
68fd493
Merge branch 'trunk' into update/phpstan-2.3.5
westonruter Nov 10, 2026
c87de46
PHPStan: Add `composer phpstan:fix` to update the baseline
westonruter Nov 10, 2026
ffbcddd
PHPStan: Point the baseline comment to `composer phpstan:fix`
westonruter Nov 10, 2026
6062faf
Merge branch 'update/phpstan-2.3.5' into add/phpstan-strict-rules
westonruter Nov 10, 2026
dc956bf
Merge branch 'trunk' into add/phpstan-strict-rules
westonruter Nov 11, 2026
407e176
Widgets: Add a changelog entry for the legacy widget instance checks
westonruter Nov 11, 2026
3c3d899
Widgets: Say the legacy widget `TypeError` is specific to PHP 8
westonruter Nov 11, 2026
f90f103
Widgets: Limit the legacy widget `TypeError` entry to an array `encoded`
westonruter Nov 11, 2026
0926ddf
Widgets: Drop strict base64 decoding from the legacy widget changelog
westonruter Nov 11, 2026
29ff6c9
Widgets: Restore strict base64 decoding to the legacy widget changelog
westonruter Nov 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
},
"lock": false
},
"extra": {
"phpstan/extension-installer": {
"ignore": [
"phpstan/phpstan-strict-rules"
]
}
},
"require-dev": {
"phpcompatibility/phpcompatibility-wp": "^2.1.3",
"wp-coding-standards/wpcs": "^3.4.1",
Expand All @@ -35,6 +42,7 @@
"phpstan/extension-installer": "1.4.3",
"phpstan/phpstan": "2.3.5",
"phpstan/phpstan-phpunit": "2.1.1",
"phpstan/phpstan-strict-rules": "2.1.1",
"php-stubs/wordpress-stubs": "@dev",
"php-stubs/wordpress-tests-stubs": "7.1.0",
"szepeviktor/phpstan-wordpress": "2.0.4"
Expand Down
26 changes: 26 additions & 0 deletions docs/contributors/code/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,32 @@ parameters:
- phpunit
```

#### Strict rules

[`phpstan.neon.dist`](https://github.com/WordPress/gutenberg/blob/HEAD/phpstan.neon.dist) also enables the rules from [phpstan-strict-rules](https://github.com/phpstan/phpstan-strict-rules) that the code already complies with, such as those disallowing loose comparisons, short ternaries, and the backtick operator, registering each rule individually. It does not include the package's `rules.neon`, since that file also makes several PHPStan parameters stricter, such as `checkDynamicProperties` and `reportMaybesInMethodSignatures`, even when its rules are disabled. For the same reason, `composer.json` tells `phpstan/extension-installer` to ignore the package, which would otherwise include `rules.neon` automatically. To work toward complying with more of the rules, include `rules.neon` in a `phpstan.neon`, and enable the rules to try. Setting `strictRules.allRules` to `false` enables only the rules set to `true`, but the parameters are still made stricter, so expect some errors from those as well. Either way, disable the rules `phpstan.neon.dist` already registers, or each error they report is reported twice:

```neon
includes:
- phpstan.neon.dist
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
strictRules:
allRules: false
requireParentConstructorCall: true
strictArrayFilter: true

# Already registered in phpstan.neon.dist.
disallowedLooseComparison: false
disallowedBacktick: false
disallowedImplicitArrayCreation: false
disallowedShortTernary: false
closureUsesThis: false
matchingInheritedMethodNames: false
switchConditionsMatchingType: false
strictFunctionCalls: false
illegalConstructorMethodCall: false
```

## GitHub Actions workflow files

GitHub Actions workflows operate in a privileged software supply chain environment, therefore all workflow files must adhere to a high degree of quality and security standards.
Expand Down
4 changes: 4 additions & 0 deletions packages/widgets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- Legacy widget: Render nothing for an `instance` attribute whose `encoded` value is an array, rather than throwing a `TypeError` on PHP 8, and render nothing when `encoded` contains characters outside the base64 alphabet, which were previously skipped ([#86460](https://github.com/WordPress/gutenberg/pull/86460)).

## 5.1.0 (2026-11-04)

### Bug Fixes
Expand Down
9 changes: 7 additions & 2 deletions packages/widgets/src/blocks/legacy-widget/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ function render_block_core_legacy_widget( $attributes ) {
}

if ( isset( $attributes['instance']['encoded'], $attributes['instance']['hash'] ) ) {
$serialized_instance = base64_decode( $attributes['instance']['encoded'] );
if ( ! hash_equals( wp_hash( $serialized_instance ), (string) $attributes['instance']['hash'] ) ) {
$encoded = $attributes['instance']['encoded'];
$hash = $attributes['instance']['hash'];
if ( ! is_string( $encoded ) || ! is_string( $hash ) ) {
return '';
}
$serialized_instance = base64_decode( $encoded, true );
if ( false === $serialized_instance || ! hash_equals( wp_hash( $serialized_instance ), $hash ) ) {
Comment thread
westonruter marked this conversation as resolved.
Resolved
Comment on lines +40 to +46

@westonruter westonruter Nov 11, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramonjd This is a fix in the class of errors you identified in #66598 (comment).

With block attributes, passing a non-string in to base64_decode() would cause a fatal error in PHP 8. For example:

<!-- wp:legacy-widget {"idBase":"text","instance":{"encoded":["x"],"hash":"h"}} /-->

So the is_string() check for the encoded value is the main fix here.

The addition of the strict param further validates that the string is valid base64 data. Since there's also a hash check on the decoded data, it's not really important. But it shouldn't hurt. It would only impact blocks where someone intentionally added stray non-base64 chars to the base64 data.

return '';
}
$instance = unserialize( $serialized_instance );
Expand Down
47 changes: 46 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# PHPStan configuration for Gutenberg
#
# To overload this configuration, copy this file to phpstan.neon and adjust as needed.
# To override this configuration, create a phpstan.neon which includes this file and adjusts its parameters as
# needed, rather than copying it, so that the copy does not go stale. See docs/contributors/code/coding-guidelines.md
# for examples.
#
# https://phpstan.org/config-reference

Expand All @@ -13,6 +15,49 @@ includes:
# https://phpstan.org/user-guide/baseline
- tools/phpstan/baseline.neon

# Rules from phpstan-strict-rules which Gutenberg already complies with. The others are not enabled until the code
# complies with them, but they can be enabled in a local phpstan.neon to work toward that. See
# docs/contributors/code/coding-guidelines.md.
#
# These are registered individually, rather than by including phpstan-strict-rules' rules.neon with only these
# enabled, because that file also makes several PHPStan parameters stricter even when its rules are disabled. That is
# also why composer.json tells phpstan/extension-installer to ignore the package, since it would otherwise include
# rules.neon automatically.
# https://github.com/phpstan/phpstan-strict-rules
rules:
# strictRules.disallowedLooseComparison is registered under `services` below, since it takes an argument.
# strictRules.disallowedBacktick
- PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule
# strictRules.disallowedImplicitArrayCreation
- PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule
# strictRules.disallowedShortTernary
- PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule
# strictRules.closureUsesThis
- PHPStan\Rules\Functions\ClosureUsesThisRule
# strictRules.matchingInheritedMethodNames
- PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule
# strictRules.switchConditionsMatchingType
- PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule
# strictRules.strictFunctionCalls, which for in_array(), array_search(), and array_keys() is also enforced by the
# WordPress.PHP.StrictInArray sniff.
- PHPStan\Rules\StrictCalls\StrictFunctionCallsRule
# strictRules.illegalConstructorMethodCall
- PHPStan\Rules\Methods\IllegalConstructorMethodCallRule
- PHPStan\Rules\Methods\IllegalConstructorStaticCallRule

services:
# strictRules.disallowedLooseComparison, with the argument rules.neon passes it.
-
class: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule
arguments:
includeOperandTypesInErrorMessage: %featureToggles.bleedingEdge%
tags:
- phpstan.rules.rule

# strictRules.numericOperandsInArithmeticOperators is not enabled, although the code complies with it, because its
# rules need a PHPStan\Rules\Operators\OperatorRuleHelper service. Registering one here would leave two once a local
# phpstan.neon includes rules.neon, which also registers one, and PHPStan would then fail to load the configuration.

parameters:
# https://phpstan.org/user-guide/rule-levels
level: 5
Expand Down
Loading