Repository navigation
Skip malformed lines in the pusher-js HTTP stream instead of throwing - #102752
Conversation
Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
I created this PR from an upstream branch since I don't have push access to your fork. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. |
|
@MelvinBot complete the checklist and test steps, and mark screenshots as done since they’ll be added in the reviewer checklist. for tests add:
(function () {
// Make Pusher's WebSocket fail so pusher-js falls back to xhr_streaming, like the affected users.
var NativeWebSocket = window.WebSocket;
function TestWebSocket(url, protocols) {
var target = String(url).indexOf('pusher.com') !== -1 ? 'wss://127.0.0.1:9' : url;
return protocols === undefined ? new NativeWebSocket(target) : new NativeWebSocket(target, protocols);
}
TestWebSocket.prototype = NativeWebSocket.prototype;
['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'].forEach(function (key) {
TestWebSocket[key] = NativeWebSocket[key];
});
window.WebSocket = TestWebSocket;
// Simulate Forcepoint DLP adding its script to the start of Pusher's fallback stream.
var descriptor = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'responseText');
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url) {
this.shouldInjectForcepoint = String(url).indexOf('/xhr_streaming') !== -1;
return open.apply(this, arguments);
};
Object.defineProperty(XMLHttpRequest.prototype, 'responseText', {
configurable: true,
get: function () {
var text = descriptor.get.call(this);
return this.shouldInjectForcepoint && text ? 'class FPClassifier {\n' + text : text;
},
});
console.log('[APP-27B test] Forcepoint simulation active');
})();You should see |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariBefore Screen.Recording.2026-10-01.at.18.54.46.movAfter Screen.Recording.2026-10-01.at.19.07.41.mov |
|
@MelvinBot @codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
I updated the PR description:
|
|
@MelvinBot mark the pr as ready |
|
I couldn't mark this PR as ready for review. My environment blocked the You can mark it ready yourself with the Ready for review button at the bottom of the PR page. |
|
@mountiny i cannot mark it as ready for some reason melvin refuses to ... can you please make it ready for review |
|
@abzokhattab Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e307ba6c0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| Only dist/web/pusher-with-encryption.js is patched, because App imports `pusher-js/with-encryption`. | ||
| ``` | ||
|
|
||
| - Upstream PR/issue: 🛑, upstream pusher-js `master` has the same unguarded parse: https://github.com/pusher/pusher-js/blob/f53faf9f33dbab922a45a919607f4c87ad1b7f72/src/core/http/http_socket.ts#L91-L113 |
There was a problem hiding this comment.
Can you please create the issue first
There was a problem hiding this comment.
Done in b1603c9. Upstream PR/issue now links HTTP streaming fallback throws SyntaxError when a proxy injects non-JSON lines into the response, with the fix in Ignore non-JSON lines in the HTTP streaming fallback.
|
|
||
| - Upstream PR/issue: 🛑, upstream pusher-js `master` has the same unguarded parse: https://github.com/pusher/pusher-js/blob/f53faf9f33dbab922a45a919607f4c87ad1b7f72/src/core/http/http_socket.ts#L91-L113 | ||
| - E/App issue: https://github.com/Expensify/App/issues/102745 | ||
| - PR introducing patch: 🛑 |
There was a problem hiding this comment.
I think we should link this pr
There was a problem hiding this comment.
Done in b1603c9. PR introducing patch now links this PR.
|
@MelvinBot please address the review comments:
|
…stream issue Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
@abzokhattab Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
I addressed all three review comments in b1603c9:
All 3 tests in |
Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
Fixed the failing
|
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.2-0 🚀
|
|
🚀 Deployed to production by https://github.com/Julesssss in version: 9.5.2-4 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
When WebSockets fail, pusher-js falls back to its
xhr_streaming/xhr_pollingtransports. These transports split the response into lines and pass any line that starts witho,a,m, orctoJSON.parsewithout atry/catch. Forcepoint DLP adds its own script (class FPClassifier {) to Pusher'sapplication/javascriptstream. pusher-js reads that line as a close frame,JSON.parsethrows out of the XHRonprogresshandler, and Sentry reports it (APP-27B).This PR adds a patch for
pusher-js@8.3.0(dist/web/pusher-with-encryption.js, the file App loads throughpusher-js/with-encryption):errorevent would reachLog.alertthroughPusherConnectionManager. Valid frames in the same response are still handled.cframe whose payload is not an array is also skipped, because a real close frame always carries[code, reason].JSON.parsecall is guarded.onOpen,onEvent, andonCloseare not wrapped, so errors in App's channel callbacks still surface.Upstream pusher-js
masterhas the same unguarded parse, so upgrading would not fix this.patches/pusher-js/details.mddocuments this.tests/unit/PusherHttpSocketTest.tsdrives the real pusher-js HTTP streaming socket with a fake XHR. It feeds aclass FPClassifier {line before theoandaframes and checks thatonopenandonmessagefire in the same progress event and thatonclosefires when the response ends. A second test checks that a non-arraycpayload does not close the socket. Both tests fail without the patch (SyntaxError) and pass with it.Fixed Issues
$ #102745
PROPOSAL: #102745 (comment)
Tests
Open
https://dev.new.expensify.com:8082/and sign in.Open DevTools → Console and paste the script below. Verify the Console shows
[APP-27B test] Forcepoint simulation active.Sign out, then sign back in in the same tab, without reloading.
Verify the Console does not show
Uncaught SyntaxError: Unexpected token 'l', "lass FPClassifier {" is not valid JSONfrompusher-with-encryption.js.Offline tests
N/A. This change only affects how pusher-js parses its HTTP fallback stream. Offline behavior is unchanged.
QA Steps
Same as tests, using
https://staging.new.expensify.com/instead of the dev URL.PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Screenshots and videos will be added in the reviewer checklist.
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari