Skip to content

Conversation

Ref34t
Copy link
Contributor

@Ref34t Ref34t commented Sep 30, 2025

Summary

Changes Made

Documentation Fixes

  • docs/2.getting-started.md: Replaced 22-line manual permission checking example with clean 8-line execute() pattern
  • docs/4.using-abilities.md: Eliminated all manual permission checking examples, added advanced error handling section, fixed variable name bug

Security Fix

  • includes/rest-api/endpoints/class-wp-rest-abilities-run-controller.php: Fixed WP_Error truthiness vulnerability in REST API permissions

Test plan

  • Verify documentation examples follow recommended patterns
  • Test REST API endpoint permission handling with various scenarios
  • Confirm no manual permission checking anti-patterns remain in docs

Mohamed Khaled and others added 12 commits September 26, 2025 15:31
Replace 22-line manual permission checking anti-pattern with clean 8-line
execute() approach per @justlevine feedback. This eliminates the security
risk of teaching developers complex permission workflows that can introduce
WP_Error truthiness bugs.
… examples

- Remove manual check_permission() before execute() examples
- Add clean execute() → is_wp_error() pattern throughout
- Include advanced error handling with ability_invalid_permissions
- Fix variable name bug in first example
- Eliminate confusing method signature that contradicted guidance
- Address all @justlevine feedback about promoting execute() over manual checks
Change permission check from loose to strict comparison in run_ability_permissions_check().
The previous pattern `if ( ! $ability->check_permission( $input ) )` would incorrectly
pass WP_Error objects as truthy, potentially allowing unauthorized access.

Fixed by using `if ( true !== $ability->check_permission( $input ) )` to properly
handle both false and WP_Error return values.
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @[email protected].

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: [email protected].

Co-authored-by: Ref34t <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Ref34t Ref34t changed the base branch from trunk to update/version-0.2.0-preps September 30, 2025 08:54
@Ref34t Ref34t changed the base branch from update/version-0.2.0-preps to trunk September 30, 2025 08:54
@Ref34t Ref34t closed this Sep 30, 2025
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