From: Dessalines <dessalines@users.noreply.github.com>
Date: Thu, 24 Mar 2022 20:34:04 +0000 (+0000)
Subject: Remove auth token from error message. Fixes #600 (#601)
X-Git-Url: http://these/git/%22https:/join-lemmy.org/static/sneer-club-logo.svg?a=commitdiff_plain;h=6bd4ed479197429f14eebc2cb2b006b0a11fbbd0;p=lemmy-ui.git

Remove auth token from error message. Fixes #600 (#601)
---

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");
+}