Skip to content

fix(content-gate): prevent metering from bypassing account verification requirement#4459

Merged
miguelpeixe merged 2 commits intotrunkfrom
fix/content-gate-require-verification-metering
Feb 10, 2026
Merged

fix(content-gate): prevent metering from bypassing account verification requirement#4459
miguelpeixe merged 2 commits intotrunkfrom
fix/content-gate-require-verification-metering

Conversation

@miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Feb 5, 2026

All Submissions:

Changes proposed in this Pull Request:

The logged-in metering strategy only checks whether the user is logged in to implement its logic, which can bypass the gate's verification requirement.

This PR adds a check to bail out metering when the gate requires verification, and the reader is not verified.

Also introduces unit tests to metering.

How to test the changes in this Pull Request:

  1. While on trunk, create a gate with:
    1. "Registered Access" without metering and require account verification
    2. "Paid Access" with metering
  2. In an anonymous session, navigate to a restricted article
  3. Register via the gate and confirm you unlock the article on refresh (paid access metering)
  4. Checkout this branch, refresh, and confirm the article remains gated
  5. Verify your account and confirm logged-in metering works

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@miguelpeixe miguelpeixe requested a review from a team as a code owner February 5, 2026 19:36
@miguelpeixe miguelpeixe requested review from Copilot and removed request for a team February 5, 2026 19:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a security issue where logged-in metering would bypass the account verification requirement. The fix adds a check to prevent metering from allowing access when the gate requires account verification but the reader has not verified their account.

Changes:

  • Added a new requires_account_verification() method to check if a gate requires account verification
  • Added a verification check in the metering logic to bail out when verification is required but not completed
  • Removed unused code (priority variable and comment)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
includes/content-gate/class-content-gate.php Adds a helper method to check if account verification is required for a gate
includes/content-gate/class-metering.php Implements the verification check in logged-in metering logic and removes unused code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@miguelpeixe miguelpeixe self-assigned this Feb 5, 2026
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Feb 5, 2026
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Works! Tests look good too.

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 9, 2026
@miguelpeixe miguelpeixe merged commit 90aed19 into trunk Feb 10, 2026
13 checks passed
@miguelpeixe miguelpeixe deleted the fix/content-gate-require-verification-metering branch February 10, 2026 15:28
@github-actions
Copy link

Hey @miguelpeixe, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants