From 8541afa4187326aa35188cbf9fd1a5bf9c523bc4 Mon Sep 17 00:00:00 2001 From: Justin Palmer <228780+layoutd@users.noreply.github.com> Date: Tue, 21 May 2024 01:56:14 +0200 Subject: [PATCH] Add filter to apply Base64 encoding to order attribution cookies (#47597) * Add filter to set Sourcebuster JS base64 configuration value * Use Sourcebuster v1.2.0 * Changelog * Reduce line length for linter --- .../add-order-attribution-base64-encoding-cookies | 4 ++++ .../client/legacy/js/frontend/order-attribution.js | 6 +++++- plugins/woocommerce/client/legacy/package.json | 2 +- .../src/Internal/Orders/OrderAttributionController.php | 10 ++++++++++ pnpm-lock.yaml | 10 +++++----- 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 plugins/woocommerce/changelog/add-order-attribution-base64-encoding-cookies diff --git a/plugins/woocommerce/changelog/add-order-attribution-base64-encoding-cookies b/plugins/woocommerce/changelog/add-order-attribution-base64-encoding-cookies new file mode 100644 index 00000000000..f38060060fa --- /dev/null +++ b/plugins/woocommerce/changelog/add-order-attribution-base64-encoding-cookies @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Filter to apply Base64 encoding to order attribution cookies diff --git a/plugins/woocommerce/client/legacy/js/frontend/order-attribution.js b/plugins/woocommerce/client/legacy/js/frontend/order-attribution.js index 9dad4dc842c..08dee73bd9b 100644 --- a/plugins/woocommerce/client/legacy/js/frontend/order-attribution.js +++ b/plugins/woocommerce/client/legacy/js/frontend/order-attribution.js @@ -82,6 +82,7 @@ sbjs.init( { lifetime: Number( params.lifetime ), session_length: Number( params.session ), + base64: Boolean( params.base64 ), timezone_offset: '0', // utc } ); } @@ -184,7 +185,10 @@ if( input ) { input.value = stringifyFalsyInputValue( this.values[ fieldName ] ); } else { - console.warn( `Field "${fieldName}" not found. Most likely, the '' element was manipulated.`); + console.warn( + `Field "${fieldName}" not found. ` + + `Most likely, the '' element was manipulated.` + ); } } } diff --git a/plugins/woocommerce/client/legacy/package.json b/plugins/woocommerce/client/legacy/package.json index b7b31847afc..a8b96931165 100644 --- a/plugins/woocommerce/client/legacy/package.json +++ b/plugins/woocommerce/client/legacy/package.json @@ -42,7 +42,7 @@ "wireit": "0.14.3" }, "dependencies": { - "sourcebuster": "github:woocommerce/sourcebuster-js#v1.1.2" + "sourcebuster": "github:woocommerce/sourcebuster-js#v1.2.0" }, "wireit": { "build:project:assets": { diff --git a/plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php b/plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php index 9aa0f137e7a..7ad08759562 100644 --- a/plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php +++ b/plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php @@ -288,6 +288,15 @@ class OrderAttributionController implements RegisterHooksInterface { */ $session_length = (int) apply_filters( 'wc_order_attribution_session_length_minutes', 30 ); + /** + * Filter to enable base64 encoding for cookie values. + * + * @since 9.0.0 + * + * @param bool $use_base64_cookies True to enable base64 encoding, default is false. + */ + $use_base64_cookies = apply_filters( 'wc_order_attribution_use_base64_cookies', false ); + /** * Filter to allow tracking. * @@ -302,6 +311,7 @@ class OrderAttributionController implements RegisterHooksInterface { 'params' => array( 'lifetime' => $lifetime, 'session' => $session_length, + 'base64' => $use_base64_cookies, 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'prefix' => $this->field_prefix, 'allowTracking' => 'yes' === $allow_tracking, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1390c775e0e..99efb52ac86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4495,8 +4495,8 @@ importers: plugins/woocommerce/client/legacy: dependencies: sourcebuster: - specifier: github:woocommerce/sourcebuster-js#v1.1.2 - version: https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/411d8dffaa37d7602d678c2ec02baacee93c12d5 + specifier: github:woocommerce/sourcebuster-js#v1.2.0 + version: https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/d7f4616d5a17e17db925ca1842457f309379d861 devDependencies: '@types/node': specifier: ^16.18.68 @@ -22426,8 +22426,8 @@ packages: resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==} engines: {node: '>= 8'} - sourcebuster@https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/411d8dffaa37d7602d678c2ec02baacee93c12d5: - resolution: {tarball: https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/411d8dffaa37d7602d678c2ec02baacee93c12d5} + sourcebuster@https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/d7f4616d5a17e17db925ca1842457f309379d861: + resolution: {tarball: https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/d7f4616d5a17e17db925ca1842457f309379d861} version: 1.1.2 space-separated-tokens@1.1.5: @@ -58636,7 +58636,7 @@ snapshots: source-map@0.7.4: {} - sourcebuster@https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/411d8dffaa37d7602d678c2ec02baacee93c12d5: {} + sourcebuster@https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/d7f4616d5a17e17db925ca1842457f309379d861: {} space-separated-tokens@1.1.5: {}