Skip to content

Commit

Permalink
Add min vault version check (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanedirt committed Feb 9, 2025
1 parent c46e836 commit d298748
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
14 changes: 14 additions & 0 deletions browser-extensions/chrome/src/app/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SrpUtility from '../utils/SrpUtility';
import { useLoading } from '../context/LoadingContext';
import { VaultResponse } from '../../shared/types/webapi/VaultResponse';
import { LoginResponse } from '../../shared/types/webapi/Login';
import { AppInfo } from '../../shared/AppInfo';

/**
* Login page
Expand Down Expand Up @@ -109,6 +110,13 @@ const Login: React.FC = () => {
return;
}

// Check if vault version is supported.
if (!AppInfo.isVaultVersionSupported(vaultResponseJson.vault.version)) {
setError('Your vault is outdated. Please login via the web client to update your vault.');
hideLoading();
return;
}

// All is good. Store auth info which makes the user logged in.
await authContext.login(credentials.username, validationResponse.token.token, validationResponse.token.refreshToken);

Expand Down Expand Up @@ -164,6 +172,12 @@ const Login: React.FC = () => {
return;
}

// Check if vault version is supported.
if (!AppInfo.isVaultVersionSupported(vaultResponseJson.vault.version)) {
setError('Your vault is outdated. Please login via the web client to update your vault.');
hideLoading();
return;
}
// All is good. Store auth info which makes the user logged in.
await authContext.login(credentials.username, validationResponse.token.token, validationResponse.token.refreshToken);

Expand Down
45 changes: 45 additions & 0 deletions browser-extensions/chrome/src/shared/AppInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* AppInfo class which contains information about the application version.
*/
export class AppInfo {
// Current extension version - should be updated with each release
public static readonly VERSION = '0.10.0';

// Minimum supported AliasVault client vault version
public static readonly MIN_VAULT_VERSION = '1.4.1';

/**
* Prevent instantiation of this utility class
*/
private constructor() {}

/**
* Checks if a given vault version is supported
* @param vaultVersion The version to check
* @returns boolean indicating if the version is supported
*/
public static isVaultVersionSupported(vaultVersion: string): boolean {
return this.compareVersions(vaultVersion, this.MIN_VAULT_VERSION) >= 0;
}

/**
* Compares two version strings
* @param version1 First version string (e.g., "1.2.3")
* @param version2 Second version string (e.g., "1.2.0")
* @returns -1 if version1 < version2, 0 if equal, 1 if version1 > version2
*/
private static compareVersions(version1: string, version2: string): number {
const parts1 = version1.split('.').map(Number);
const parts2 = version2.split('.').map(Number);

for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
const part1 = parts1[i] || 0;
const part2 = parts2[i] || 0;

if (part1 < part2) return -1;
if (part1 > part2) return 1;
}

return 0;
}
}
5 changes: 4 additions & 1 deletion docs/misc/release/create-new-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ nav_order: 1

Follow the steps in the checklist below to prepare a new release.

## Versioning
## Versioning client and server
- [ ] Update ./src/Shared/AliasVault.Shared.Core/AppInfo.cs and update major/minor/patch to the new version. This version will be shown in the client and admin app footer.
- [ ] Update ./install.sh `@version` in header if the install script has changed. This allows the install script to self-update when running the `./install.sh update` command on default installations.
- [ ] Update README.md install.sh download link to point to the new release version

# Versioning browser extension
- [ ] Update ./chrome/src/shared/AppInfo.ts with the new version for the extension and minimum supported client vault version.

## Docker Images
If docker containers have been added or removed:
- [ ] Verify that `.github/workflows/publish-docker-images.yml` contains references to all docker images that need to be published.
Expand Down

0 comments on commit d298748

Please sign in to comment.