From 6469d002b7b18e49c77ee650a4255974ab43e790 Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Wed, 27 Aug 2025 16:37:13 -0400 Subject: [PATCH] fix: cleanup obsoleted legacy api keys on api startup (cli / connect) (#1630) - these keys have been replaced with a session based authorization system --- api/src/unraid-api/auth/api-key.service.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/api/src/unraid-api/auth/api-key.service.ts b/api/src/unraid-api/auth/api-key.service.ts index 4a7ad6edb..63eb90d17 100644 --- a/api/src/unraid-api/auth/api-key.service.ts +++ b/api/src/unraid-api/auth/api-key.service.ts @@ -35,11 +35,29 @@ export class ApiKeyService implements OnModuleInit { async onModuleInit() { this.memoryApiKeys = await this.loadAllFromDisk(); + await this.cleanupLegacyInternalKeys(); if (environment.IS_MAIN_PROCESS) { this.setupWatch(); } } + private async cleanupLegacyInternalKeys() { + const legacyNames = ['CliInternal', 'ConnectInternal']; + const keysToDelete = this.memoryApiKeys.filter((key) => legacyNames.includes(key.name)); + + if (keysToDelete.length > 0) { + try { + await this.deleteApiKeys(keysToDelete.map((key) => key.id)); + this.logger.log(`Cleaned up ${keysToDelete.length} legacy internal keys`); + } catch (error) { + this.logger.debug( + error, + `Failed to delete legacy internal keys: ${keysToDelete.map((key) => key.name).join(', ')}` + ); + } + } + } + public async findAll(): Promise { return this.memoryApiKeys; }