WordPress / WordPress/WordPress-Coding-Standards
Ensure capabilities are checked in metabox saves
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
- For each metabox registered with
add_meta_box, flag if the savecallbackdoes not contain a cap check.
If the callback is a method like array( $obj, 'method' ), it will be to difficult to check programatically. However, if the method is for $this or if a bare global function name or closure is used, then it should be straightforward to locate the function in the same file.
PHPUnit would be a better way to check if a function calls current_user_can, as a test could run and then check to see if the map_meta_cap hook ran during the function's execution.
Per the VIP code review guidelines:
Capability checks need to validate that users can take the requested actions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the rule that inspects registrations made with add_meta_box and review how callback forms are represented. Use the listed cases—$this methods, bare global functions, and closures—as the initial scope, and investigate PHPUnit coverage using current_user_can and the map_meta_cap hook. Done means callbacks that can be inspected are flagged when they lack a capability check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100