Skip to content

Commit 12ba7d8

Browse files
eps1lonunstubbable
andauthored
[Flight Reply] Early bailout if backing entry for Blob deserialization is not a Blob (facebook#36055)
Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
1 parent c80a075 commit 12ba7d8

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReply-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,4 +744,17 @@ describe('ReactFlightDOMReply', () => {
744744
// has closed but that's a bug in both ReactFlightReplyServer and ReactFlightClient.
745745
// It just halts in this case.
746746
});
747+
748+
it('cannot deserialize a Blob reference backed by a string', async () => {
749+
const formData = new FormData();
750+
formData.set('1', '-'.repeat(50000));
751+
formData.set('0', JSON.stringify(['$B1']));
752+
let error;
753+
try {
754+
await ReactServerDOMServer.decodeReply(formData, webpackServerMap);
755+
} catch (x) {
756+
error = x;
757+
}
758+
expect(error.message).toContain('Referenced Blob is not a Blob.');
759+
});
747760
});

packages/react-server/src/ReactFlightReplyServer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,10 @@ function parseModelString(
18061806
const blobKey = prefix + id;
18071807
// We should have this backingEntry in the store already because we emitted
18081808
// it before referencing it. It should be a Blob.
1809-
const backingEntry: Blob = (response._formData.get(blobKey): any);
1809+
const backingEntry = response._formData.get(blobKey);
1810+
if (!(backingEntry instanceof Blob)) {
1811+
throw new Error('Referenced Blob is not a Blob.');
1812+
}
18101813
return backingEntry;
18111814
}
18121815
case 'R': {

scripts/error-codes/codes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,5 +566,6 @@
566566
"578": "Already initialized Iterator.",
567567
"579": "Invalid data for bytes stream.",
568568
"580": "Server Function has too many bound arguments. Received %s but the limit is %s.",
569-
"581": "BigInt is too large. Received %s digits but the limit is %s."
569+
"581": "BigInt is too large. Received %s digits but the limit is %s.",
570+
"582": "Referenced Blob is not a Blob."
570571
}

0 commit comments

Comments
 (0)