woocommerce / woocommerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
https://woocommerce.com
9.15k stars 10.73k forks source link

Add filter to apply Base64 encoding to order attribution cookies #47597

Closed layoutd closed 1 week ago

layoutd commented 2 weeks ago

Changes proposed in this Pull Request:

In the continuing effort to make the order attribution functionality available for stores on any servers, and in light of several recent mentions of different web application firewalls and rulesets that are still being incorrectly triggered, this PR:

Related to #43681 and #43413.

Notes:

How to test the changes in this Pull Request:

👉🏻 Prerequisites: store with products and configured to allow checkouts and with order attribution enabled.

Test1: Order attribution works as normal with the new Sourcebuster version (no filter enabled)

  1. Visit the shop in a new browser session (incognito, for example)
  2. In the dev console, execute the snippet wc_order_attribution.getAttributionData() and see that source data is retrieved (probably source_type:'typein')
  3. Confirm that the sbjs_* cookies are in the original format (URL encoded, param=value|||param=value|||…): image
  4. Add items to the cart and check out.
  5. Confirm in the order edit page that order attribution data is available image

Test 2: Order attribution works with new filter

  1. Add the filter to enable Base64: add_filter( 'wc_order_attribution_use_base64_cookies', '__return_true' );
  2. In a new browser session without existing cookeis (incongnito), visit the shop with UTM params site.com/shop/?utm_source=test_source_base64&utm_campaign=Éürøpãp🅰️&utm_medium=test_medium
  3. Check in the cookies to see that the cookie values are Base64 (just alphanumeric, no % or =). image
  4. In the dev console, execute the snippet wc_order_attribution.getAttributionData() and see that source data is retrieved
  5. Run the JavaScript snippet to confirm data is accurate wc_order_attribution.getAttributionData()
  6. Complete the checkout and confirm that order attribution data was captured. image

Test 3: Order attribution works with for users who have cookies in the old format

  1. Disable the filter.
  2. Visit the shop in a new browser session, UTM params: site.com/shop/?utm_source=test_source_base64&utm_campaign=Éürøpãp🅰️&utm_medium=test_medium
  3. Confirm that all the cookies are in the original format (see test 1, step 3).
  4. Enable the filter.
  5. Navigate to another page.
  6. Confirm that SOME cookies have been updated to Base64 encoding (see explanation in this comment on Sourcebuster PR: https://github.com/woocommerce/sourcebuster-js/pull/6#issuecomment-2108942374) image
  7. In the dev console, execute the snippet wc_order_attribution.getAttributionData() and see that source data is retrieved
  8. Add items to the cart and check out.
  9. Confirm in the order edit page that order attribution data is available image

Test 4: Order attribution works with for users who have cookies in the new format if the filter is disabled

  1. Enable the filter.
  2. Visit the shop in a new browser session, UTM params: site.com/shop/?utm_source=test_source_base64&utm_campaign=Éürøpãp🅰️&utm_medium=test_medium
  3. Confirm that all the cookies are Base64 encoded (see test 2, step 3).
  4. Disable the filter.
  5. Navigate to another page.
  6. Confirm that SOME cookies have been updated to the old format (see explanation in this comment on Sourcebuster PR: https://github.com/woocommerce/sourcebuster-js/pull/6#issuecomment-2108942374) image
  7. In the dev console, execute the snippet wc_order_attribution.getAttributionData() and see that source data is retrieved
  8. Add items to the cart and check out.
  9. Confirm in the order edit page that order attribution data is available image

Test 5: Order attribution works with filter enabled using other checkout type

  1. Change the store checkout type (from Classic to Block, or viceversa).
  2. Repeat steps from Test 2.

Changelog entry

#### Significance - [ ] Patch - [ ] Minor - [ ] Major #### Type - [ ] Fix - Fixes an existing bug - [ ] Add - Adds functionality - [ ] Update - Update existing functionality - [ ] Dev - Development related task - [ ] Tweak - A minor adjustment to the codebase - [ ] Performance - Address performance issues - [ ] Enhancement - Improvement to existing functionality #### Message #### Comment
github-actions[bot] commented 2 weeks ago

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

github-actions[bot] commented 1 week ago

Hi , @woocommerce/ventures

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like: https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

layoutd commented 1 week ago

Thanks @ecgan! I added another note to the PR description.