From 2d02b6ca5ce1e7d41d2e2acc89e44cc6aa75207d Mon Sep 17 00:00:00 2001
From: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
Date: Tue, 10 Sep 2024 11:29:48 -0400
Subject: [PATCH] Auth/PM-11252 - Registration with Email Verification - Add
new redirect connector (#10682)
* PM-11252 - Registration with email verification - Add new signup redirect connector
* PM-11252 - Make the redirect connector generic and extensible while updating it to reference the new fragment based approach which prevents open redirects and prevents the query string from being sent to servers or proxies.
* PM-11252 - PR feedback - refactor redirect to simply forward any fragment onward with no query param parsing required leading to an even more generic solution.
* PM-11252 - Docs
* PM-11252 - PR Feedback - Include styles in chunks to remove need to manually import scss
* PM-11252 - Update redirect html to tailwind.
---
apps/web/src/connectors/redirect.html | 29 +++++++++++++++++++++++++++
apps/web/src/connectors/redirect.ts | 17 ++++++++++++++++
apps/web/webpack.config.js | 6 ++++++
3 files changed, 52 insertions(+)
create mode 100644 apps/web/src/connectors/redirect.html
create mode 100644 apps/web/src/connectors/redirect.ts
diff --git a/apps/web/src/connectors/redirect.html b/apps/web/src/connectors/redirect.html
new file mode 100644
index 00000000000..13b05fb17e2
--- /dev/null
+++ b/apps/web/src/connectors/redirect.html
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+ Bitwarden Web vault
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/apps/web/src/connectors/redirect.ts b/apps/web/src/connectors/redirect.ts
new file mode 100644
index 00000000000..82bd273fad3
--- /dev/null
+++ b/apps/web/src/connectors/redirect.ts
@@ -0,0 +1,17 @@
+// This redirect connector is used to redirect users to the correct URL after they have been sent here from an email link.
+// The fragment contains the information needed to redirect the user to the correct page.
+// This is required because android app links couldn't properly handle the angular hash based route we originally had in the email link.
+window.addEventListener("load", () => {
+ // ex: https://vault.bitwarden.com/redirect-connector.html#finish-signup?token=fakeToken&email=example%40example.com&fromEmail=true
+ const currentUrl = new URL(window.location.href);
+
+ // Get the fragment (everything after the #)
+ const fragment = currentUrl.hash.substring(1); // Remove the leading #
+
+ if (!fragment) {
+ throw new Error("No fragment found in URL. Cannot determine redirect.");
+ }
+
+ const newUrl = `${window.location.origin}/#/${fragment}`;
+ window.location.href = newUrl;
+});
diff --git a/apps/web/webpack.config.js b/apps/web/webpack.config.js
index ce3979f7918..cec4bf044be 100644
--- a/apps/web/webpack.config.js
+++ b/apps/web/webpack.config.js
@@ -111,6 +111,11 @@ const plugins = [
filename: "sso-connector.html",
chunks: ["connectors/sso"],
}),
+ new HtmlWebpackPlugin({
+ template: "./src/connectors/redirect.html",
+ filename: "redirect-connector.html",
+ chunks: ["connectors/redirect", "styles"],
+ }),
new HtmlWebpackPlugin({
template: "./src/connectors/captcha.html",
filename: "captcha-connector.html",
@@ -325,6 +330,7 @@ const webpackConfig = {
"connectors/sso": "./src/connectors/sso.ts",
"connectors/captcha": "./src/connectors/captcha.ts",
"connectors/duo-redirect": "./src/connectors/duo-redirect.ts",
+ "connectors/redirect": "./src/connectors/redirect.ts",
styles: ["./src/scss/styles.scss", "./src/scss/tailwind.css"],
theme_head: "./src/theme.ts",
},