Skip to content

Enhanced security for Stripe cookie handling#2747

Merged
vytisbulkevicius merged 2 commits intodevelopmentfrom
bugfix/otter-internal/267
Feb 26, 2026
Merged

Enhanced security for Stripe cookie handling#2747
vytisbulkevicius merged 2 commits intodevelopmentfrom
bugfix/otter-internal/267

Conversation

@girishpanchal30
Copy link
Contributor

Closes https://github.com/Codeinwp/otter-internals/issues/267

Summary

Enhanced security for Stripe cookie handling with HMAC validation.

Checklist before the final review

  • Included E2E or unit tests for the changes in this PR.
  • Visual elements are not affected by independent changes.
  • It is at least compatible with the minimum WordPress version.
  • It loads additional script in frontend only if it is required.
  • Does not impact the Core Web Vitals.
  • In case of deprecation, old blocks are safely migrated.
  • It is usable in Widgets and FSE.
  • Copy/Paste is working if the attributes are modified.
  • PR is following the best practices

@girishpanchal30 girishpanchal30 added the pr-checklist-skip Allow this Pull Request to skip checklist. label Feb 26, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Feb 26, 2026
@pirate-bot
Copy link
Contributor

Bundle Size Diff

Package Old Size New Size Diff
Animations 271.38 KB 271.38 KB 0 B (0.00%)
Blocks 1.54 MB 1.54 MB 0 B (0.00%)
CSS 100.76 KB 100.76 KB 0 B (0.00%)
Dashboard 198.36 KB 198.36 KB 0 B (0.00%)
Onboarding 160.8 KB 160.8 KB 0 B (0.00%)
Export Import 97.73 KB 97.73 KB 0 B (0.00%)
Pro 407.08 KB 407.08 KB 0 B (0.00%)

@pirate-bot
Copy link
Contributor

pirate-bot commented Feb 26, 2026

Plugin build for f227e63 is ready 🛎️!

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

Improves the integrity of guest (non-logged-in) Stripe customer data stored in cookies by adding server-side HMAC validation before trusting cookie contents.

Changes:

  • Adds an HMAC cookie (o_stripe_hmac_data) when persisting o_stripe_data for unauthenticated users.
  • Validates o_stripe_data against the HMAC on read before decoding/using it.

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

Comment on lines +264 to +270
if ( isset( $_COOKIE['o_stripe_data'] ) && ! empty( $_COOKIE['o_stripe_data'] ) && isset( $_COOKIE['o_stripe_hmac_data'] ) && ! empty( $_COOKIE['o_stripe_hmac_data'] ) ) { // phpcs:ignore WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___COOKIE
$data_raw = stripcslashes( $_COOKIE['o_stripe_data'] ); // phpcs:ignore WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___COOKIE, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$hmac_data = sanitize_text_field( $_COOKIE['o_stripe_hmac_data'] ); // phpcs:ignore WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___COOKIE

if ( hash_equals( hash_hmac( 'sha256', $data_raw, wp_salt() ), $hmac_data ) ) {
$data = json_decode( $data_raw, true );
}
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

There are existing PHPUnit tests for Stripe_API, but the new guest-cookie HMAC behavior isn’t covered. Please add unit tests for the unauthenticated path that: (1) reads valid o_stripe_data + o_stripe_hmac_data, (2) returns empty data when the HMAC is missing/invalid, and (3) ideally verifies the cookie-writing path sets both cookies.

Copilot uses AI. Check for mistakes.
@vytisbulkevicius vytisbulkevicius merged commit c72c3a8 into development Feb 26, 2026
12 of 16 checks passed
@vytisbulkevicius vytisbulkevicius deleted the bugfix/otter-internal/267 branch February 26, 2026 16:09
@pirate-bot
Copy link
Contributor

🎉 This PR is included in version 3.1.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist. released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants