Skip to content
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

Add a current_user_can check to our cache clearing method #309

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Nov 6, 2024

Description of the Change

In #90 we introduced an admin setting that allows on-demand clearing of avatar cache, useful for situations where image sizes have changed and SLA still has the old image sizes stored.

This setting outputs a button that when clicked, fires an AJAX request to kick off the cache clearing process. This request does pass and validate a proper nonce but doesn't have any user capability check. This means in theory anyone that has a user account on the site can generate a nonce and make a direct request to the proper AJAX endpoint to trigger that cache clearing.

This PR fixes that by adding a current_user_can( 'manage_options' ) check, as only users with that capability can access the Settings > Discussion page to begin with and thus should be the only ones that can initiate this cache clearing.

How to test the Change

  1. Go to Settings > Discussion
  2. Scroll down to the Clear local avatar cache setting and click the Clear cache button
  3. Ensure this process works as expected

The test above ensures things still work as expected but does not verify things are more secure. If desired, can provide details on how to test that, which requires making direct requests to the AJAX endpoint.

Changelog Entry

Security - Run a user capability check before we clear the avatar cache.

Credits

Props @dkotter, @truonghuuphuc

Checklist:

@dkotter dkotter added this to the 2.8.0 milestone Nov 6, 2024
@dkotter dkotter self-assigned this Nov 6, 2024
@dkotter dkotter requested a review from jeffpaul as a code owner November 6, 2024 21:36
@github-actions github-actions bot added the needs:code-review This requires code review. label Nov 6, 2024
@faisal-alvi faisal-alvi merged commit 3912e38 into develop Nov 8, 2024
14 checks passed
@faisal-alvi faisal-alvi deleted the fix/cache-clear-user-privilege-check branch November 8, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:code-review This requires code review.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants