-
Notifications
You must be signed in to change notification settings - Fork 849
VaultPress: avoid fatals when receiving error from VP server #46660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Vaultpress plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
|
@kraftbj Any chance you could take a look? I don't know many people who still run VaultPress, but I assume you may be one of them :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a fatal error that occurs when the VaultPress service returns an error response (as an array) instead of the expected base64-encoded string, which caused base64_decode() to fail with a type error.
Changes:
- Added type checking in
get_messages()to validate the response before decoding - Added fallback to cached messages when an invalid response is received
- Added comprehensive documentation for
get_messages()andcontact_service()functions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| projects/plugins/vaultpress/vaultpress.php | Added type validation before base64_decode() and unserialize() calls in get_messages(), with fallback to cached messages on error. Added PHPDoc comments for get_messages() and contact_service() functions. |
| projects/plugins/vaultpress/changelog/fix-vaultpress-base64-fatal-28504 | Added changelog entry documenting the bug fix |
| $messages = base64_decode( $response ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode | ||
| $messages = unserialize( $messages ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize | ||
| $this->update_option( 'messages_last_contact', time() ); | ||
| $this->update_option( 'messages', $messages ); | ||
| } else { | ||
| // If we got an error (array) or false/empty, fall back to cached messages |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unserialize() call on line 455 could fail and return false if base64_decode() returns invalid data. Consider adding validation after unserialize() to ensure the result is the expected type (likely an array) before updating the options. If unserialize() fails, the code should fall back to cached messages similar to the else block.
| $messages = base64_decode( $response ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode | |
| $messages = unserialize( $messages ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize | |
| $this->update_option( 'messages_last_contact', time() ); | |
| $this->update_option( 'messages', $messages ); | |
| } else { | |
| // If we got an error (array) or false/empty, fall back to cached messages | |
| $decoded_messages = base64_decode( $response, true ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode | |
| if ( false !== $decoded_messages ) { | |
| $unserialized_messages = unserialize( $decoded_messages ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize | |
| if ( is_array( $unserialized_messages ) ) { | |
| $messages = $unserialized_messages; | |
| $this->update_option( 'messages_last_contact', time() ); | |
| $this->update_option( 'messages', $messages ); | |
| } else { | |
| // If unserialization failed or returned an unexpected type, fall back to cached messages. | |
| $messages = $this->get_option( 'messages' ); | |
| } | |
| } else { | |
| // If base64 decoding failed, fall back to cached messages. | |
| $messages = $this->get_option( 'messages' ); | |
| } | |
| } else { | |
| // If we got an error (array) or false/empty, fall back to cached messages. |
| * Get messages from the VP servers | ||
| * | ||
| * @param bool $force_reload Whether to force a reload of the messages. | ||
| * @return array The messages. |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @return documentation should clarify what is returned when cached messages don't exist or are empty. Currently it just states "The messages" but doesn't specify the type or indicate it could be null/false/empty array.
| * @return array The messages. | |
| * @return array|false|null The messages, or the cached value (false/null) if no messages are stored. |
Code Coverage SummaryCoverage changed in 1 file.
|
Fixes #28504
Proposed changes:
In some scenarios, when opening wp-admin you receive a Fatal error:
This can be reproduced on sites with issues with the VaultPress connection.
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
This isn't easy to reproduce, but I believe it can be done on a site where your VaultPress subscription is no longer active (code: VP08).