Skip to content

Validate repo_info before accessing version#92

Open
apermo wants to merge 2 commits intoZodiac1978:developfrom
apermo:fix/validate-repo-info
Open

Validate repo_info before accessing version#92
apermo wants to merge 2 commits intoZodiac1978:developfrom
apermo:fix/validate-repo-info

Conversation

@apermo
Copy link
Copy Markdown
Contributor

@apermo apermo commented Apr 13, 2026

Summary

  • Reject plugins_api() responses missing the version property before storing as repo_info (prevents caching invalid data)
  • Add isset( $report['repo_info']->version ) guard in the version column of render_table_row() (protects against stale cache entries)

This is consistent with how tested, last_updated, num_ratings, and rating are already guarded with isset() on lines 536, 546, 554.

Fixes #56

Context

plugins_api() can return a valid stdClass (not a WP_Error) that lacks expected properties. This happens when a premium plugin's slug collides with a wordpress.org entry that returns invalid data (e.g. Search & Filter Pro — see #56 comments). The object passes the ! is_wp_error() check but accessing ->version triggers PHP warnings.

Test in WordPress Playground

Both Playground instances include a mu-plugin that strips the version property from Classic Editor's plugins_api() response, reproducing the Search & Filter Pro scenario from #56.

Before (develop — shows the bug): Open in WordPress Playground

After (this branch — bug fixed): Open in WordPress Playground

Both instances include a mu-plugin that hooks plugins_api_result to strip the version property from Classic Editor's API response, reproducing the Search & Filter Pro scenario. In the Before instance, this causes PHP warnings that corrupt the AJAX response — the Classic Editor row fails to load. In the After instance, the invalid response is handled gracefully.

Pre-installed plugins:

Test plan

  • Open the Before link — Classic Editor row fails to load or shows PHP warnings
  • Open the After link — Classic Editor shows "No data available" cleanly, no PHP warnings
  • In the After link, verify other plugins (Apermo Admin Bar, Akismet, Hello Dolly) still show full version/update/rating data

@apermo
Copy link
Copy Markdown
Contributor Author

apermo commented Apr 14, 2026

Fixed — moved the isset( $returned_object->version ) check inside the non-error branch so the else is only reached for WP_Error. PHPStan can now narrow the type correctly.

Comment thread rt-plugin-report.php
$report['repo_info'] = $returned_object;
// Cache the report.
set_site_transient( $cache_key, $report, self::CACHE_LIFETIME );
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Zodiac1978 Maybe we could add an else branch here to log the error? Your thoughts?

apermo added 2 commits April 14, 2026 15:42
plugins_api() can return a valid object (not WP_Error)
that lacks expected properties like `version`. This
happens with plugins like Search & Filter Pro whose
slug collides with a wp.org entry returning invalid
data.

Guard against this in two places:
- assemble_plugin_report(): reject API responses
  missing `version` before caching as repo_info
- render_table_row(): add isset() check on version,
  consistent with tested/rating/last_updated guards

Fixes Zodiac1978#56
Move the isset(version) check inside the non-error
branch so the else is only reached for WP_Error,
letting PHPStan narrow the type correctly.
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.

PHP warnings when loading the report screen the second time

1 participant