From 6bd4ed479197429f14eebc2cb2b006b0a11fbbd0 Mon Sep 17 00:00:00 2001
From: Dessalines <dessalines@users.noreply.github.com>
Date: Thu, 24 Mar 2022 20:34:04 +0000
Subject: [PATCH] Remove auth token from error message. Fixes #600 (#601)

---
 src/server/index.tsx | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/server/index.tsx b/src/server/index.tsx
index 4c496d3..7b83760 100644
--- a/src/server/index.tsx
+++ b/src/server/index.tsx
@@ -145,7 +145,7 @@ server.get("/*", async (req, res) => {
       if (errCode == "instance_is_private") {
         return res.redirect(`/signup`);
       } else {
-        return res.send(`404: ${errCode}`);
+        return res.send(`404: ${removeAuthParam(errCode)}`);
       }
     }
 
@@ -231,7 +231,7 @@ server.get("/*", async (req, res) => {
 `);
   } catch (err) {
     console.error(err);
-    return res.send(`404: ${err}`);
+    return res.send(`404: ${removeAuthParam(err)}`);
   }
 });
 
@@ -259,3 +259,13 @@ process.on("SIGINT", () => {
   console.info("Interrupted");
   process.exit(0);
 });
+
+function removeAuthParam(err: any): string {
+  return removeParam(err.toString(), "auth");
+}
+
+function removeParam(url: string, parameter: string): string {
+  return url
+    .replace(new RegExp("[?&]" + parameter + "=[^&#]*(#.*)?$"), "$1")
+    .replace(new RegExp("([?&])" + parameter + "=[^&]*&"), "$1");
+}
-- 
2.44.1