Skip to content

Fix - Missing capability check on demo-import migration trigger - #146

Open
deepench wants to merge 1 commit into
developfrom
fix/demo-import-migration-missing-capability-check
Open

deepench wants to merge 1 commit into
developfrom
fix/demo-import-migration-missing-capability-check

Conversation

@deepench

Copy link
Copy Markdown
Contributor

Changes proposed in this Pull Request:

Fixes themegrill/spacious-pro#75 (filed against the Pro repo since this same file is shared byte-for-byte between both themes). A migration feature meant for admins had a nonce check but no permission check. This meant any logged-in user, even the lowest-privilege account on the site (for example, a regular customer account on a shop), could trigger a full theme settings reset by visiting a specific link - and this worked on any page of the site, not just admin pages. This fix adds the missing permission check, so only users who are allowed to change theme settings can trigger this.

How to test the changes in this Pull Request:

  1. Log in as an administrator - everything should continue to work exactly as before.
  2. If you have a non-administrator account available (for example, a Subscriber), confirm that visiting the special migration link now shows a clear "you do not have permission" message instead of silently proceeding.

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (modification of the currently available functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Other information:

  • Have you added an explanation of what your changes do and why you would like us to include them?
  • Have you successfully ran tests with your changes locally?
  • Have you updated the documentation accordingly?

Changelog entry

Fix - Missing capability check on demo-import migration trigger.

Adds current_user_can( 'edit_theme_options' ) alongside the existing nonce
verification in the demo-import migration trigger, its notice, and its
dismiss handler. The nonce alone only proved the request came from the
current user's own session, not that they were allowed to run the action -
any logged-in user, regardless of role, could force a site-wide theme_mods
and options rewrite using stale legacy data, since the migration functions
are hooked to after_setup_theme, which fires on the front end too.

Verified live: a subscriber-role account, using a nonce genuinely valid for
their own session, is now correctly rejected with "You do not have
permission to perform this action."
@github-actions

Copy link
Copy Markdown

QA suite — refused, no regression spec

This PR changes product source but adds no spec, so the suite was
refused before booting WordPress — running it just to report the same
thing at the end costs runner minutes for nothing. Run
/claudegrill:verify-fix locally and let write-spec add the guard
to this branch, then push again.

Source files changed with no matching spec
inc/demo-import-migration.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Add the low-privilege regression test and regenerate the translation catalog.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds capability checks to prevent unauthorized users from triggering demo-import migrations or dismissing related notices.

Changes:

  • Restricts migration actions to users with edit_theme_options.
  • Returns a permission error for unauthorized requests.
  • Adds a translatable permission message.
File Summary
inc/​demo-import-migration.php Adds capability checks to migration-related flows.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +89 to +91
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( __( 'You do not have permission to perform this action.', 'spacious' ) );
}
@deepench deepench self-assigned this Sep 25, 2026
@deepench deepench added the bug label Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants