Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add yup validation schema to auth settings (#858)
Leendert de Borstdbb6cf5b9415
diff --git a/apps/browser-extension/package-lock.json b/apps/browser-extension/package-lock.jsonindex 176451e55..51be25455 100644--- a/apps/browser-extension/package-lock.json+++ b/apps/browser-extension/package-lock.json@@ -19,7 +19,8 @@"secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0","sql.js": "^1.12.0","vitest": "^3.0.8",- "webext-bridge": "^6.0.1"+ "webext-bridge": "^6.0.1",+ "yup": "^1.6.1"},"devDependencies": {"@types/chrome": "^0.0.280",@@ -28,6 +29,7 @@"@types/react": "^19.0.7","@types/react-dom": "^19.0.3","@types/sql.js": "^1.4.9",+ "@types/yup": "^0.29.14","@typescript-eslint/eslint-plugin": "^8.21.0","@typescript-eslint/parser": "^8.21.0","@vitest/coverage-v8": "^3.0.8",@@ -2085,6 +2087,13 @@"@types/node": "*"}},+ "node_modules/@types/yup": {+ "version": "0.29.14",+ "resolved": "https://registry.npmjs.org/@types/yup/-/yup-0.29.14.tgz",+ "integrity": "sha512-Ynb/CjHhE/Xp/4bhHmQC4U1Ox+I2OpfRYF3dnNgQqn1cHa6LK3H1wJMNPT02tSVZA6FYuXE2ITORfbnb6zBCSA==",+ "dev": true,+ "license": "MIT"+ },"node_modules/@typescript-eslint/eslint-plugin": {"version": "8.32.1","resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.32.1.tgz",@@ -9702,6 +9711,12 @@"react-is": "^16.13.1"}},+ "node_modules/property-expr": {+ "version": "2.0.6",+ "resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.6.tgz",+ "integrity": "sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==",+ "license": "MIT"+ },"node_modules/proto-list": {"version": "1.2.4","resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz",@@ -11833,6 +11848,12 @@"dev": true,"license": "MIT"},+ "node_modules/tiny-case": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/tiny-case/-/tiny-case-1.0.3.tgz",+ "integrity": "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==",+ "license": "MIT"+ },"node_modules/tiny-uid": {"version": "1.1.2","resolved": "https://registry.npmjs.org/tiny-uid/-/tiny-uid-1.1.2.tgz",@@ -11986,6 +12007,12 @@"node": ">=0.6"}},+ "node_modules/toposort": {+ "version": "2.0.2",+ "resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz",+ "integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==",+ "license": "MIT"+ },"node_modules/tough-cookie": {"version": "5.1.2","resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz",@@ -13472,6 +13499,18 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "node_modules/yup": {+ "version": "1.6.1",+ "resolved": "https://registry.npmjs.org/yup/-/yup-1.6.1.tgz",+ "integrity": "sha512-JED8pB50qbA4FOkDol0bYF/p60qSEDQqBD0/qeIrUCG1KbPBIQ776fCUNb9ldbPcSTxA69g/47XTo4TqWiuXOA==",+ "license": "MIT",+ "dependencies": {+ "property-expr": "^2.0.5",+ "tiny-case": "^1.0.3",+ "toposort": "^2.0.2",+ "type-fest": "^2.19.0"+ }+ },"node_modules/zip-dir": {"version": "2.0.0","resolved": "https://registry.npmjs.org/zip-dir/-/zip-dir-2.0.0.tgz",diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.jsonindex b50e80863..2c3fc7be8 100644--- a/apps/browser-extension/package.json+++ b/apps/browser-extension/package.json@@ -35,7 +35,8 @@"secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0","sql.js": "^1.12.0","vitest": "^3.0.8",- "webext-bridge": "^6.0.1"+ "webext-bridge": "^6.0.1",+ "yup": "^1.6.1"},"devDependencies": {"@types/chrome": "^0.0.280",@@ -44,6 +45,7 @@"@types/react": "^19.0.7","@types/react-dom": "^19.0.3","@types/sql.js": "^1.4.9",+ "@types/yup": "^0.29.14","@typescript-eslint/eslint-plugin": "^8.21.0","@typescript-eslint/parser": "^8.21.0","@vitest/coverage-v8": "^3.0.8",diff --git a/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsxindex 65c349170..396c1285c 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';import { AppInfo } from '@/utils/AppInfo';import { storage } from '#imports';import { GLOBAL_AUTOFILL_POPUP_ENABLED_KEY, DISABLED_SITES_KEY, VAULT_LOCKED_DISMISS_UNTIL_KEY } from '@/utils/Constants';+import * as Yup from 'yup';type ApiOption = {label: string;@@ -13,6 +14,38 @@ const DEFAULT_OPTIONS: ApiOption[] = [{ label: 'Self-hosted', value: 'custom' }];+// Validation schema for URLs+const urlSchema = Yup.object().shape({+ apiUrl: Yup.string()+ .url('Please enter a valid URL')+ .required('API URL is required')+ .test('is-valid-api-url', 'Please enter a valid API URL', (value: string | undefined) => {+ if (!value) {+ return true; // Allow empty for non-custom option+ }+ try {+ const url = new URL(value);+ return url.protocol === 'http:' || url.protocol === 'https:';+ } catch {+ return false;+ }+ }),+ clientUrl: Yup.string()+ .url('Please enter a valid URL')+ .required('Client URL is required')+ .test('is-valid-client-url', 'Please enter a valid client URL', (value: string | undefined) => {+ if (!value) {+ return true; // Allow empty for non-custom option+ }+ try {+ const url = new URL(value);+ return url.protocol === 'http:' || url.protocol === 'https:';+ } catch {+ return false;+ }+ })+});+/*** Auth settings page only shown when user is not logged in.*/@@ -21,6 +54,7 @@ const AuthSettings: React.FC = () => {const [customUrl, setCustomUrl] = useState<string>('');const [customClientUrl, setCustomClientUrl] = useState<string>('');const [isGloballyEnabled, setIsGloballyEnabled] = useState<boolean>(true);+ const [errors, setErrors] = useState<{ apiUrl?: string; clientUrl?: string }>({});useEffect(() => {/**@@ -63,6 +97,9 @@ const AuthSettings: React.FC = () => {if (value !== 'custom') {await storage.setItem('local:apiUrl', '');await storage.setItem('local:clientUrl', '');+ setCustomUrl('');+ setCustomClientUrl('');+ setErrors({});}};@@ -72,17 +109,36 @@ const AuthSettings: React.FC = () => {const handleCustomUrlChange = async (e: React.ChangeEvent<HTMLInputElement>) : Promise<void> => {const value = e.target.value;setCustomUrl(value);- await storage.setItem('local:apiUrl', value);++ try {+ await urlSchema.validateAt('apiUrl', { apiUrl: value });+ setErrors(prev => ({ ...prev, apiUrl: undefined }));+ await storage.setItem('local:apiUrl', value);+ } catch (error: unknown) {+ if (error instanceof Yup.ValidationError) {+ setErrors(prev => ({ ...prev, apiUrl: error.message }));+ // On error we revert back to the aliasvault.net official hosted instance.+ await storage.setItem('local:apiUrl', AppInfo.DEFAULT_API_URL);+ }+ }};/*** Handle custom client URL change- * @param e*/const handleCustomClientUrlChange = async (e: React.ChangeEvent<HTMLInputElement>) : Promise<void> => {const value = e.target.value;setCustomClientUrl(value);- await storage.setItem('local:clientUrl', value);++ try {+ await urlSchema.validateAt('clientUrl', { clientUrl: value });+ setErrors(prev => ({ ...prev, clientUrl: undefined }));+ await storage.setItem('local:clientUrl', value);+ } catch (error: unknown) {+ if (error instanceof Yup.ValidationError) {+ setErrors(prev => ({ ...prev, clientUrl: error.message }));+ }+ }};/**@@ -133,8 +189,11 @@ const AuthSettings: React.FC = () => {value={customClientUrl}onChange={handleCustomClientUrlChange}placeholder="https://my-aliasvault-instance.com"- className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"+ className={`w-full bg-gray-50 border ${errors.clientUrl ? 'border-red-500' : 'border-gray-300'} text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white`}/>+ {errors.clientUrl && (+ <p className="mt-1 text-sm text-red-500">{errors.clientUrl}</p>+ )}</div><div className="mb-6"><label htmlFor="custom-api-url" className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">@@ -146,8 +205,11 @@ const AuthSettings: React.FC = () => {value={customUrl}onChange={handleCustomUrlChange}placeholder="https://my-aliasvault-instance.com/api"- className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"+ className={`w-full bg-gray-50 border ${errors.apiUrl ? 'border-red-500' : 'border-gray-300'} text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white`}/>+ {errors.apiUrl && (+ <p className="mt-1 text-sm text-red-500">{errors.apiUrl}</p>+ )}</div></>)}