Skip to content

Commit

Permalink
fix: crash unencrypted message with crypto module (#349)
Browse files Browse the repository at this point in the history
* subscription listener and history api handle plain message when crypto module is configured

* test: subscription listener and history api with plain message along with crypto module

* dist/lib

* fix: AppContext membership apis optional fields only included when explicitly mentioned

* lib/dist files

* PubNub SDK v7.4.5 release.

---------

Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
mohitpubnub and pubnub-release-bot authored Nov 28, 2023
1 parent 6ea105a commit 76bc504
Show file tree
Hide file tree
Showing 24 changed files with 516 additions and 186 deletions.
13 changes: 10 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---
changelog:
- date: 2023-11-28
version: v7.4.5
changes:
- type: bug
text: "Handle unencrypted messages in subscribe with cryptoModule configured."
- type: bug
text: "Fixe for missing parameters to request or filter optional fields for App Context memberships api."
- date: 2023-11-14
version: v7.4.4
changes:
Expand Down Expand Up @@ -922,7 +929,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '7.4.4'
version: '7.4.5'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -938,7 +945,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.4.4.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.4.5.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1609,7 +1616,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v7.4.4/pubnub.7.4.4.js
location: https://github.com/pubnub/javascript/releases/download/v7.4.5/pubnub.7.4.5.js
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v7.4.5
November 28 2023

#### Fixed
- Handle unencrypted messages in subscribe with cryptoModule configured.
- Fixe for missing parameters to request or filter optional fields for App Context memberships api.

## v7.4.4
November 14 2023

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
npm install pubnub
```
* or download one of our builds from our CDN:
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.4.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.4.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.5.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.5.min.js
2. Configure your keys:
Expand Down
135 changes: 86 additions & 49 deletions dist/web/pubnub.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ var default_1 = /** @class */ (function () {
return this;
};
default_1.prototype.getVersion = function () {
return '7.4.4';
return '7.4.5';
};
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
this._PNSDKSuffix[name] = suffix;
Expand Down
9 changes: 2 additions & 7 deletions lib/core/components/subscription_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,7 @@ var default_1 = /** @class */ (function () {
}
catch (e) {
decryptedPayload = null;
if (console && console.log) {
console.log('decryption error', e.message);
}
announce.error = "Error while decrypting message content: ".concat(e.message);
}
if (decryptedPayload !== null) {
msgPayload = decryptedPayload;
Expand Down Expand Up @@ -581,10 +579,7 @@ var default_1 = /** @class */ (function () {
}
catch (e) {
decryptedPayload = null;
// eslint-disable-next-line
if (console && console.log) {
console.log('decryption error', e.message); //eslint-disable-line
}
announce.error = "Error while decrypting message content: ".concat(e.message);
}
if (decryptedPayload != null) {
announce.message = decryptedPayload;
Expand Down
21 changes: 15 additions & 6 deletions lib/core/endpoints/fetch_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ exports.handleResponse = exports.prepareParams = exports.isAuthSupported = expor
var operations_1 = __importDefault(require("../constants/operations"));
var utils_1 = __importDefault(require("../utils"));
function __processMessage(modules, message) {
if (!modules.cryptoModule)
return message;
var result = {};
if (!modules.cryptoModule) {
result.payload = message;
return result;
}
try {
var decryptedData = modules.cryptoModule.decrypt(message);
var decryptedPayload = decryptedData instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decryptedData)) : decryptedData;
return decryptedPayload;
result.payload = decryptedPayload;
return result;
}
catch (e) {
if (console && console.log)
if (modules.config.logVerbosity && console && console.log)
console.log('decryption error', e.message);
return message;
result.payload = message;
result.error = "Error while decrypting message content: ".concat(e.message);
}
return result;
}
function getOperation() {
return operations_1.default.PNFetchMessagesOperation;
Expand Down Expand Up @@ -87,9 +93,10 @@ function handleResponse(modules, serverResponse) {
response.channels[channelName] = [];
(serverResponse.channels[channelName] || []).forEach(function (messageEnvelope) {
var announce = {};
var processedMessgeResult = __processMessage(modules, messageEnvelope.message);
announce.channel = channelName;
announce.timetoken = messageEnvelope.timetoken;
announce.message = __processMessage(modules, messageEnvelope.message);
announce.message = processedMessgeResult.payload;
announce.messageType = messageEnvelope.message_type;
announce.uuid = messageEnvelope.uuid;
if (messageEnvelope.actions) {
Expand All @@ -100,6 +107,8 @@ function handleResponse(modules, serverResponse) {
if (messageEnvelope.meta) {
announce.meta = messageEnvelope.meta;
}
if (processedMessgeResult.error)
announce.error = processedMessgeResult.error;
response.channels[channelName].push(announce);
});
});
Expand Down
21 changes: 15 additions & 6 deletions lib/core/endpoints/history/get_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ exports.handleResponse = exports.prepareParams = exports.isAuthSupported = expor
var operations_1 = __importDefault(require("../../constants/operations"));
var utils_1 = __importDefault(require("../../utils"));
function __processMessage(modules, message) {
if (!modules.cryptoModule)
return message;
var result = {};
if (!modules.cryptoModule) {
result.payload = message;
return result;
}
try {
var decryptedData = modules.cryptoModule.decrypt(message);
var decryptedPayload = decryptedData instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decryptedData)) : decryptedData;
return decryptedPayload;
result.payload = decryptedPayload;
return result;
}
catch (e) {
if (console && console.log)
if (modules.config.logVerbosity && console && console.log)
console.log('decryption error', e.message);
return message;
result.payload = message;
result.error = "Error while decrypting message content: ".concat(e.message);
}
return result;
}
function getOperation() {
return operations_1.default.PNHistoryOperation;
Expand Down Expand Up @@ -76,13 +82,16 @@ function handleResponse(modules, serverResponse) {
};
if (Array.isArray(serverResponse[0])) {
serverResponse[0].forEach(function (serverHistoryItem) {
var processedMessgeResult = __processMessage(modules, serverHistoryItem.message);
var item = {
timetoken: serverHistoryItem.timetoken,
entry: __processMessage(modules, serverHistoryItem.message),
entry: processedMessgeResult.payload,
};
if (serverHistoryItem.meta) {
item.meta = serverHistoryItem.meta;
}
if (processedMessgeResult.error)
item.error = processedMessgeResult.error;
response.messages.push(item);
});
}
Expand Down
39 changes: 24 additions & 15 deletions lib/core/endpoints/objects/member/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var endpoint = {
getOperation: function () { return operations_1.default.PNGetMembersOperation; },
validateParams: function (_, params) {
if (!(params === null || params === void 0 ? void 0 : params.channel)) {
return 'UUID cannot be empty';
return 'channel cannot be empty';
}
},
getURL: function (_a, params) {
Expand All @@ -39,36 +39,45 @@ var endpoint = {
},
isAuthSupported: function () { return true; },
prepareParams: function (_modules, params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
var queryParams = {};
queryParams.include = ['uuid.status', 'uuid.type', 'status'];
queryParams.include = [];
if (params === null || params === void 0 ? void 0 : params.include) {
if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) {
if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.statusField) {
queryParams.include.push('status');
}
if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customFields) {
queryParams.include.push('custom');
}
if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customUUIDFields) {
if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.UUIDFields) {
queryParams.include.push('uuid');
}
if ((_d = params.include) === null || _d === void 0 ? void 0 : _d.customUUIDFields) {
queryParams.include.push('uuid.custom');
}
if ((_d = (_c = params.include) === null || _c === void 0 ? void 0 : _c.UUIDFields) !== null && _d !== void 0 ? _d : true) {
queryParams.include.push('uuid');
if ((_e = params.include) === null || _e === void 0 ? void 0 : _e.UUIDStatusField) {
queryParams.include.push('uuid.status');
}
if ((_f = params.include) === null || _f === void 0 ? void 0 : _f.UUIDTypeField) {
queryParams.include.push('uuid.type');
}
}
queryParams.include = queryParams.include.join(',');
if ((_e = params === null || params === void 0 ? void 0 : params.include) === null || _e === void 0 ? void 0 : _e.totalCount) {
queryParams.count = (_f = params.include) === null || _f === void 0 ? void 0 : _f.totalCount;
if ((_g = params === null || params === void 0 ? void 0 : params.include) === null || _g === void 0 ? void 0 : _g.totalCount) {
queryParams.count = (_h = params.include) === null || _h === void 0 ? void 0 : _h.totalCount;
}
if ((_g = params === null || params === void 0 ? void 0 : params.page) === null || _g === void 0 ? void 0 : _g.next) {
queryParams.start = (_h = params.page) === null || _h === void 0 ? void 0 : _h.next;
if ((_j = params === null || params === void 0 ? void 0 : params.page) === null || _j === void 0 ? void 0 : _j.next) {
queryParams.start = (_k = params.page) === null || _k === void 0 ? void 0 : _k.next;
}
if ((_j = params === null || params === void 0 ? void 0 : params.page) === null || _j === void 0 ? void 0 : _j.prev) {
queryParams.end = (_k = params.page) === null || _k === void 0 ? void 0 : _k.prev;
if ((_l = params === null || params === void 0 ? void 0 : params.page) === null || _l === void 0 ? void 0 : _l.prev) {
queryParams.end = (_m = params.page) === null || _m === void 0 ? void 0 : _m.prev;
}
if (params === null || params === void 0 ? void 0 : params.filter) {
queryParams.filter = params.filter;
}
queryParams.limit = (_l = params === null || params === void 0 ? void 0 : params.limit) !== null && _l !== void 0 ? _l : 100;
queryParams.limit = (_o = params === null || params === void 0 ? void 0 : params.limit) !== null && _o !== void 0 ? _o : 100;
if (params === null || params === void 0 ? void 0 : params.sort) {
queryParams.sort = Object.entries((_m = params.sort) !== null && _m !== void 0 ? _m : {}).map(function (_a) {
queryParams.sort = Object.entries((_p = params.sort) !== null && _p !== void 0 ? _p : {}).map(function (_a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
if (value === 'asc' || value === 'desc') {
return "".concat(key, ":").concat(value);
Expand Down
37 changes: 23 additions & 14 deletions lib/core/endpoints/objects/membership/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,45 @@ var endpoint = {
},
isAuthSupported: function () { return true; },
prepareParams: function (_modules, params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
var queryParams = {};
queryParams.include = ['channel.status', 'channel.type', 'status'];
queryParams.include = [];
if (params === null || params === void 0 ? void 0 : params.include) {
if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) {
queryParams.include.push('custom');
if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.statusField) {
queryParams.include.push('status');
}
if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customChannelFields) {
queryParams.include.push('channel.custom');
if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customFields) {
queryParams.include.push('custom');
}
if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.channelFields) {
queryParams.include.push('channel');
}
if ((_d = params.include) === null || _d === void 0 ? void 0 : _d.customChannelFields) {
queryParams.include.push('channel.custom');
}
if ((_e = params.include) === null || _e === void 0 ? void 0 : _e.channelStatusField) {
queryParams.include.push('channel.status');
}
if ((_f = params.include) === null || _f === void 0 ? void 0 : _f.channelTypeField) {
queryParams.include.push('channel.type');
}
}
queryParams.include = queryParams.include.join(',');
if ((_d = params === null || params === void 0 ? void 0 : params.include) === null || _d === void 0 ? void 0 : _d.totalCount) {
queryParams.count = (_e = params.include) === null || _e === void 0 ? void 0 : _e.totalCount;
if ((_g = params === null || params === void 0 ? void 0 : params.include) === null || _g === void 0 ? void 0 : _g.totalCount) {
queryParams.count = (_h = params.include) === null || _h === void 0 ? void 0 : _h.totalCount;
}
if ((_f = params === null || params === void 0 ? void 0 : params.page) === null || _f === void 0 ? void 0 : _f.next) {
queryParams.start = (_g = params.page) === null || _g === void 0 ? void 0 : _g.next;
if ((_j = params === null || params === void 0 ? void 0 : params.page) === null || _j === void 0 ? void 0 : _j.next) {
queryParams.start = (_k = params.page) === null || _k === void 0 ? void 0 : _k.next;
}
if ((_h = params === null || params === void 0 ? void 0 : params.page) === null || _h === void 0 ? void 0 : _h.prev) {
queryParams.end = (_j = params.page) === null || _j === void 0 ? void 0 : _j.prev;
if ((_l = params === null || params === void 0 ? void 0 : params.page) === null || _l === void 0 ? void 0 : _l.prev) {
queryParams.end = (_m = params.page) === null || _m === void 0 ? void 0 : _m.prev;
}
if (params === null || params === void 0 ? void 0 : params.filter) {
queryParams.filter = params.filter;
}
queryParams.limit = (_k = params === null || params === void 0 ? void 0 : params.limit) !== null && _k !== void 0 ? _k : 100;
queryParams.limit = (_o = params === null || params === void 0 ? void 0 : params.limit) !== null && _o !== void 0 ? _o : 100;
if (params === null || params === void 0 ? void 0 : params.sort) {
queryParams.sort = Object.entries((_l = params.sort) !== null && _l !== void 0 ? _l : {}).map(function (_a) {
queryParams.sort = Object.entries((_p = params.sort) !== null && _p !== void 0 ? _p : {}).map(function (_a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
if (value === 'asc' || value === 'desc') {
return "".concat(key, ":").concat(value);
Expand Down
6 changes: 6 additions & 0 deletions lib/core/pubnub-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ var default_1 = /** @class */ (function () {
customFields: params.include.customFields,
UUIDFields: params.include.userFields,
customUUIDFields: params.include.customUserFields,
statusField: params.include.statusField,
UUIDStatusField: params.include.userStatusField,
UUIDTypeField: params.include.userTypeField,
totalCount: params.include.totalCount,
},
sort: params.sort != null
Expand Down Expand Up @@ -460,6 +463,9 @@ var default_1 = /** @class */ (function () {
customFields: params.include.customFields,
channelFields: params.include.spaceFields,
customChannelFields: params.include.customSpaceFields,
statusField: params.include.statusField,
channelStatusField: params.include.spaceStatusField,
channelTypeField: params.include.spaceTypeField,
totalCount: params.include.totalCount,
},
sort: params.sort != null
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubnub",
"version": "7.4.4",
"version": "7.4.5",
"author": "PubNub <[email protected]>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export default class {
}

getVersion() {
return '7.4.4';
return '7.4.5';
}

_addPnsdkSuffix(name, suffix) {
Expand Down
9 changes: 2 additions & 7 deletions src/core/components/subscription_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,7 @@ export default class {
decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData;
} catch (e) {
decryptedPayload = null;
if (console && console.log) {
console.log('decryption error', e.message);
}
announce.error = `Error while decrypting message content: ${e.message}`;
}
if (decryptedPayload !== null) {
msgPayload = decryptedPayload;
Expand Down Expand Up @@ -752,10 +750,7 @@ export default class {
decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData;
} catch (e) {
decryptedPayload = null;
// eslint-disable-next-line
if (console && console.log) {
console.log('decryption error', e.message); //eslint-disable-line
}
announce.error = `Error while decrypting message content: ${e.message}`;
}
if (decryptedPayload != null) {
announce.message = decryptedPayload;
Expand Down
Loading

0 comments on commit 76bc504

Please sign in to comment.