From bad939f3ae735a09ec140188e2e01fe2c2ca4577 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Wed, 8 Mar 2023 18:20:00 -0500 Subject: [PATCH 1/2] Added model for email forwarder options --- libs/common/src/models/domain/email-forwarder-options.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 libs/common/src/models/domain/email-forwarder-options.ts diff --git a/libs/common/src/models/domain/email-forwarder-options.ts b/libs/common/src/models/domain/email-forwarder-options.ts new file mode 100644 index 00000000000..61449a8c70c --- /dev/null +++ b/libs/common/src/models/domain/email-forwarder-options.ts @@ -0,0 +1,5 @@ +export class EmailForwarderOptions { + name: string; + value: string; + validForSelfHosted: boolean; +} From f58517fc22c632addf75583d54ea2bf982468793 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Wed, 8 Mar 2023 18:20:49 -0500 Subject: [PATCH 2/2] Refactored code base to use model and filter based on the new model --- apps/web/src/app/tools/generator.component.ts | 12 ++---------- .../angular/src/components/generator.component.ts | 15 ++++++++------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/apps/web/src/app/tools/generator.component.ts b/apps/web/src/app/tools/generator.component.ts index 6a5f00c19b0..3260f47ef5c 100644 --- a/apps/web/src/app/tools/generator.component.ts +++ b/apps/web/src/app/tools/generator.component.ts @@ -41,16 +41,8 @@ export class GeneratorComponent extends BaseGeneratorComponent { window ); if (platformUtilsService.isSelfHost()) { - // Cannot use Firefox Relay on self hosted web vaults due to CORS issues with Firefox Relay API - this.forwardOptions.splice( - this.forwardOptions.findIndex((o) => o.value === "firefoxrelay"), - 1 - ); - // Also cannot use Duck Duck Go on self hosted web vaults due to CORS issues - this.forwardOptions.splice( - this.forwardOptions.findIndex((o) => o.value === "duckduckgo"), - 1 - ); + // Allow only valid email forwarders for self host + this.forwardOptions = this.forwardOptions.filter((forwarder) => forwarder.validForSelfHosted); } } diff --git a/libs/angular/src/components/generator.component.ts b/libs/angular/src/components/generator.component.ts index 6a104b45dad..fbb27cdecf6 100644 --- a/libs/angular/src/components/generator.component.ts +++ b/libs/angular/src/components/generator.component.ts @@ -8,6 +8,7 @@ import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwo import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; import { UsernameGenerationService } from "@bitwarden/common/abstractions/usernameGeneration.service"; +import { EmailForwarderOptions } from "@bitwarden/common/models/domain/email-forwarder-options"; import { PasswordGeneratorPolicyOptions } from "@bitwarden/common/models/domain/password-generator-policy-options"; @Directive() @@ -22,7 +23,7 @@ export class GeneratorComponent implements OnInit { usernameTypeOptions: any[]; subaddressOptions: any[]; catchallOptions: any[]; - forwardOptions: any[]; + forwardOptions: EmailForwarderOptions[]; usernameOptions: any = {}; passwordOptions: any = {}; username = "-"; @@ -236,11 +237,11 @@ export class GeneratorComponent implements OnInit { private async initForwardOptions() { this.forwardOptions = [ - { name: "AnonAddy", value: "anonaddy" }, - { name: "DuckDuckGo", value: "duckduckgo" }, - { name: "Fastmail", value: "fastmail" }, - { name: "Firefox Relay", value: "firefoxrelay" }, - { name: "SimpleLogin", value: "simplelogin" }, + { name: "AnonAddy", value: "anonaddy", validForSelfHosted: true }, + { name: "DuckDuckGo", value: "duckduckgo", validForSelfHosted: false }, + { name: "Fastmail", value: "fastmail", validForSelfHosted: true }, + { name: "Firefox Relay", value: "firefoxrelay", validForSelfHosted: false }, + { name: "SimpleLogin", value: "simplelogin", validForSelfHosted: true }, ]; this.usernameOptions = await this.usernameGenerationService.getOptions(); @@ -248,7 +249,7 @@ export class GeneratorComponent implements OnInit { this.usernameOptions.forwardedService == null || this.usernameOptions.forwardedService === "" ) { - this.forwardOptions.push({ name: "", value: null }); + this.forwardOptions.push({ name: "", value: null, validForSelfHosted: false }); } this.forwardOptions = this.forwardOptions.sort((a, b) => a.name.localeCompare(b.name));