Enhanced security for Stripe cookie handling#2747
Enhanced security for Stripe cookie handling#2747vytisbulkevicius merged 2 commits intodevelopmentfrom
Conversation
Bundle Size Diff
|
|
Plugin build for f227e63 is ready 🛎️!
|
There was a problem hiding this comment.
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 persistingo_stripe_datafor unauthenticated users. - Validates
o_stripe_dataagainst the HMAC on read before decoding/using it.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 ); | ||
| } |
There was a problem hiding this comment.
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.
|
🎉 This PR is included in version 3.1.5 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Closes https://github.com/Codeinwp/otter-internals/issues/267
Summary
Enhanced security for Stripe cookie handling with HMAC validation.
Checklist before the final review