Skip to content

Fix Metro Server crash on empty or undefined symbolication payload #1670

Description

@vijaykumawat2001

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch metro@0.81.5 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/metro/src/Server.js b/node_modules/metro/src/Server.js
index ec933c0..2d10cd8 100644
--- a/node_modules/metro/src/Server.js
+++ b/node_modules/metro/src/Server.js
@@ -975,7 +975,17 @@ class Server {
       );
       debug("Start symbolication");
       const body = await req.rawBody;
-      const parsedBody = JSON.parse(body);
+      let parsedBody;
+      try {
+        if (typeof body !== 'string' || body.trim() === '' || body.trim() === 'undefined') {
+          throw new SyntaxError('Invalid symbolication payload');
+        }
+        parsedBody = JSON.parse(body);
+      } catch (e) {
+        res.statusCode = 400;
+        res.end(JSON.stringify({error: 'Invalid symbolication payload'}));
+        return;
+      }
       const rewriteAndNormalizeStackFrame = (frame, lineNumber) => {
         invariant(
           frame != null && typeof frame === "object",

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions