Skip to content

Conversation

@xecdev
Copy link
Collaborator

@xecdev xecdev commented Nov 25, 2025

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/improve-content-unlocking-security

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.

@Klakurka Klakurka requested a review from Copilot November 25, 2025 20:28
@Klakurka Klakurka self-requested a review November 25, 2025 20:28
Copy link

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 implements a secure content unlocking flow that validates payment transactions on the server before granting access to paywalled content. The key security improvement is the introduction of server-verified unlock tokens that prevent unauthorized content access.

Key Changes:

  • Introduced a two-step validation process: first validating the unlock transaction, then marking payment as successful using a server-issued token
  • Added unlock_token and used fields to the database schema to track transaction validation state
  • Refactored the JavaScript payment flow to use onClose instead of onSuccess for better reliability

Reviewed changes

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

File Description
includes/class-paybutton-ajax.php Added ajax_validate_unlock_tx() endpoint and refactored mark_payment_successful() to verify unlock tokens before granting access
includes/class-paybutton-activator.php Updated database schema to include unlock_token, used flag, and additional indexes for improved query performance
assets/js/paywalled-content.js Restructured payment flow to validate transactions and retrieve unlock tokens before marking payment successful

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

$table_name = $wpdb->prefix . 'paybutton_paywall_unlocked';

$sql = "CREATE TABLE IF NOT EXISTS $table_name (
$sql = "CREATE TABLE $table_name (
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Changing from CREATE TABLE IF NOT EXISTS to CREATE TABLE will cause the activation to fail if the table already exists. This breaks plugin reactivation and updates. Restore the IF NOT EXISTS clause.

Copilot uses AI. Check for mistakes.

$sql_login = "CREATE TABLE IF NOT EXISTS $login_table (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
$sql_login = "CREATE TABLE $login_table (
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Changing from CREATE TABLE IF NOT EXISTS to CREATE TABLE will cause the activation to fail if the table already exists. This breaks plugin reactivation and updates. Restore the IF NOT EXISTS clause.

Suggested change
$sql_login = "CREATE TABLE $login_table (
$sql_login = "CREATE TABLE IF NOT EXISTS $login_table (

Copilot uses AI. Check for mistakes.
configData.onSuccess = function(tx) {
$.ajax({

// Shared state: user wallet add + unlock tx captured in onSuccess, consumed in onClose.
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'add' to 'address'.

Suggested change
// Shared state: user wallet add + unlock tx captured in onSuccess, consumed in onClose.
// Shared state: user wallet address + unlock tx captured in onSuccess, consumed in onClose.

Copilot uses AI. Check for mistakes.
}

/**
* AJAX endpoint to validate a content–unlock transaction.
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Replace en-dash (–) with standard hyphen (-) for consistency with standard naming conventions.

Suggested change
* AJAX endpoint to validate a contentunlock transaction.
* AJAX endpoint to validate a content-unlock transaction.

Copilot uses AI. Check for mistakes.
}

// Generate a random, unguessable token
$raw = random_bytes(18); // ~24 chars base64url
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

The comment states '~24 chars base64url' but the calculation is imprecise. 18 bytes encodes to exactly 24 base64 characters. Consider updating the comment to '24 chars base64url' for accuracy.

Suggested change
$raw = random_bytes(18); // ~24 chars base64url
$raw = random_bytes(18); // 24 chars base64url

Copilot uses AI. Check for mistakes.
Copy link
Member

@Klakurka Klakurka left a comment

Choose a reason for hiding this comment

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

Probably good to merge but we can remove some of this commented out logging.

Comment on lines +167 to +171
// if ($wpdb->last_error) {
// error_log('[paybutton] insert error: ' . $wpdb->last_error);
// } else {
// error_log('[paybutton] insert ok id=' . $wpdb->insert_id);
// }
Copy link
Member

Choose a reason for hiding this comment

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

Remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I will keep it for future reference

@Klakurka Klakurka merged commit 9f39d00 into fix/improve-login-security Nov 26, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants