Skip to content

fix(security): tighten permission_callback on block-discovery + client stub abilities#1308

Merged
superdav42 merged 1 commit into
mainfrom
fix/wp-org-permission-callbacks
May 9, 2026
Merged

fix(security): tighten permission_callback on block-discovery + client stub abilities#1308
superdav42 merged 1 commit into
mainfrom
fix/wp-org-permission-callbacks

Conversation

@superdav42
Copy link
Copy Markdown
Contributor

Summary

WordPress.org plugin-check flagged abilities registered with permission_callback => '__return_true' that expose editor-oriented data publicly. This PR addresses the two genuine issues (list-block-types, get-block-type) plus one related missing-permission case in the client-ability stub registrar.

Changes

  • includes/Abilities/BlockAbilities.php
    • sd-ai-agent/list-block-types: was __return_true → now current_user_can( 'edit_posts' ). The block registry is editor metadata, not public site content.
    • sd-ai-agent/get-block-type: was __return_true → now current_user_can( 'edit_posts' ). Exposes attribute schemas, supports flags, styles, variations, example markup — all editor-oriented.
  • includes/Core/ClientAbilityRouter.php
    • Server-side stubs for client-side (JS) abilities now register with permission_callback => '__return_false'. The callback is a no-op error response by design, so denying execution at the permission layer is correct (and silences the wp.org scanner).

Why these (and not all 42 reported lines)

The original report listed 42 incidences but most are false positives from the wp.org scanner: it cannot follow the ability_class => SomeAbility::class indirection and assumes no permission_callback is set. In reality those abilities (e.g. GetOptionAbility, UpdateOptionAbility, GetThemesAbility, UpdatePluginAbility, ScanThemeHooksAbility, ListModifiedPluginsAbility) all implement protected function permission_callback( $input ): bool on AbstractAbility (verified via rg -n 'permission_callback' includes/Abilities/).

The only registrations that genuinely lacked a check were the two __return_true entries above, plus the ClientAbilityRouter stub which was missing the key entirely.

Verification

  • composer phpcs -- includes/Abilities/BlockAbilities.php includes/Core/ClientAbilityRouter.php → clean.
  • composer phpstan → no errors.
  • Capability chosen (edit_posts) matches the rest of BlockAbilities.php (list-block-patterns, list-block-templates, parse-block-content, validate-block-content, create-block-content all use edit_posts).

Out of scope

  • No legacy ability-name renames or sd-ai-agentsuperdav-ai-agent refactors (would violate canonical-naming rules in AGENTS.md).
  • The 40 false-positive flags from the wp.org tool are not actionable in code; if WP.org reviewers ask, the response is "ability_class hides permission_callback from static scanners — see AbstractAbility::__construct line 83 which wires the protected method into the registration array."

aidevops.sh v3.15.15 plugin for OpenCode v1.14.41 with claude-sonnet-4-6 spent 17h 51m and 40 tokens on this as a headless worker.

…t stub abilities

- list-block-types and get-block-type now require edit_posts; previously
  used __return_true and exposed editor-oriented block-registry detail
  publicly (flagged by WP.org plugin-check).
- ClientAbilityRouter server-side stubs now register with
  permission_callback => '__return_false' to make explicit that JS-side
  abilities must never execute through the server-side ability runner.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 25 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 30fab267-5432-475f-837c-4ab98daf0b46

📥 Commits

Reviewing files that changed from the base of the PR and between 63e7331 and e3d4848.

📒 Files selected for processing (2)
  • includes/Abilities/BlockAbilities.php
  • includes/Core/ClientAbilityRouter.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wp-org-permission-callbacks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the bug Auto-created from TODO.md tag label May 9, 2026
@superdav42 superdav42 merged commit 9db4507 into main May 9, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant