Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/production' into production-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Aug 17, 2023
2 parents 5ccc241 + 872b205 commit 9e0dd1e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [2.40.2](https://github.com/rudderlabs/rudder-sdk-js/compare/v2.40.1...v2.40.2) (2023-08-16)


### Bug Fixes

* persisted data decryption for v3 ([#1309](https://github.com/rudderlabs/rudder-sdk-js/issues/1309)) ([76b6075](https://github.com/rudderlabs/rudder-sdk-js/commit/76b60759ec37afb371d18590348572ca8e822070))

### [2.40.1](https://github.com/rudderlabs/rudder-sdk-js/compare/v2.40.0...v2.40.1) (2023-08-16)


Expand Down
4 changes: 4 additions & 0 deletions jest/jest.polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ require('isomorphic-fetch');

// Mocking Math random
global.Math.random = () => 0.5;

import { TextDecoder } from 'util';

Object.assign(global, { TextDecoder });
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-analytics",
"version": "2.40.1",
"version": "2.40.2",
"description": "",
"main": "./dist/browser.min.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-sdk-js",
"version": "2.40.1",
"version": "2.40.2",
"description": "RudderStack Javascript SDK",
"main": "index.js",
"module": "index.es.js",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sonar.qualitygate.wait=false
sonar.projectKey=rudderlabs_rudder-sdk-js
sonar.organization=rudderlabs
sonar.projectName=rudder-sdk-js
sonar.projectVersion=2.40.1
sonar.projectVersion=2.40.2

# Meta-data for the project
sonar.links.scm=https://github.com/rudderlabs/rudder-sdk-js
Expand Down
26 changes: 14 additions & 12 deletions src/core/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,18 +1345,20 @@ class Analytics {
? options.polyfillIfRequired
: true;
return (
polyfillIfRequired &&
(!String.prototype.endsWith ||
!String.prototype.startsWith ||
!String.prototype.includes ||
!Array.prototype.find ||
!Array.prototype.includes ||
typeof window.URL !== 'function' ||
typeof Promise === 'undefined' ||
!Object.entries ||
!Object.values ||
!String.prototype.replaceAll ||
!this.isDatasetAvailable())
(polyfillIfRequired &&
(!String.prototype.endsWith ||
!String.prototype.startsWith ||
!String.prototype.includes ||
!Array.prototype.find ||
!Array.prototype.includes ||
typeof window.URL !== 'function' ||
typeof Promise === 'undefined' ||
!Object.entries ||
!Object.values ||
!String.prototype.replaceAll ||
!this.isDatasetAvailable() ||
typeof TextDecoder !== 'function' ||
typeof Uint8Array !== 'function'))
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const INTEGRATION_LOAD_CHECK_INTERVAL = 1000;
const DEFAULT_DATA_PLANE_EVENTS_BUFFER_TIMEOUT_MS = 10000;
const INTG_SUFFIX = '_RS';
const POLYFILL_URL =
'https://polyfill.io/v3/polyfill.min.js?features=Number.isNaN%2CURL%2CArray.prototype.find%2CArray.prototype.includes%2CPromise%2CString.prototype.endsWith%2CString.prototype.includes%2CString.prototype.startsWith%2CObject.entries%2CObject.values%2CElement.prototype.dataset%2CString.prototype.replaceAll';
'https://polyfill.io/v3/polyfill.min.js?features=Number.isNaN%2CURL%2CArray.prototype.find%2CArray.prototype.includes%2CPromise%2CString.prototype.endsWith%2CString.prototype.includes%2CString.prototype.startsWith%2CObject.entries%2CObject.values%2CElement.prototype.dataset%2CString.prototype.replaceAll%2CTextDecoder%2Uint8Array';

const GENERIC_TRUE_VALUES = ['true', 'True', 'TRUE', 't', 'T', '1'];
const GENERIC_FALSE_VALUES = ['false', 'False', 'FALSE', 'f', 'F', '0'];
Expand Down
7 changes: 7 additions & 0 deletions src/utils/storage/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import get from 'get-value';
import logger from '../logUtil';
import { Cookie } from './cookie';
import { Store } from './store';
import { fromBase64 } from './v3DecryptionUtils';

const defaults = {
user_storage_key: 'rl_user_id',
Expand All @@ -17,6 +18,7 @@ const defaults = {
session_info: 'rl_session',
auth_token: 'rl_auth_token',
prefix: 'RudderEncrypt:',
prefixV3: 'RS_ENC_v3_', // prefix for v3 encryption
key: 'Rudder',
};

Expand Down Expand Up @@ -65,6 +67,11 @@ function decryptValue(value) {
if (value.substring(0, defaults.prefix.length) === defaults.prefix) {
return AES.decrypt(value.substring(defaults.prefix.length), defaults.key).toString(Utf8);
}

// Try if it is v3 encrypted value
if (value.substring(0, defaults.prefixV3.length) === defaults.prefixV3) {
return fromBase64(value.substring(defaults.prefixV3.length));
}
return value;
}

Expand Down
19 changes: 19 additions & 0 deletions src/utils/storage/v3DecryptionUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Converts a base64 encoded string to bytes array
* @param base64Str base64 encoded string
* @returns bytes array
*/
const base64ToBytes = (base64Str) => {
const binString = globalThis.atob(base64Str);
const bytes = binString.split('').map((char) => char.charCodeAt(0));
return new Uint8Array(bytes);
};

/**
* Decodes a base64 encoded string
* @param value base64 encoded string
* @returns decoded string
*/
const fromBase64 = (value) => new TextDecoder().decode(base64ToBytes(value));

export { fromBase64 };

0 comments on commit 9e0dd1e

Please sign in to comment.