From 84ba6dee1ccfe0084b0ef55098d259e796af5ddb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:08:34 +0000 Subject: [PATCH 1/2] Initial plan From 9e3c4ac7b19337e2e6725a73349890c448aab2b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:19:16 +0000 Subject: [PATCH 2/2] Improve code quality and type safety in Azure Login action - Fix unsafe error handling by checking error type before accessing properties - Replace loose equality (==) with strict equality (===) for type safety - Remove all 'any' types and use proper TypeScript ExecOptions interface - Improve error messages to show only error message, not full object toString - Add proper type checking before accessing error.stack to prevent runtime errors These changes enhance the reliability and maintainability of the codebase while maintaining backward compatibility. Co-authored-by: Jury1981 <210622247+Jury1981@users.noreply.github.com> --- lib/cleanup/index.js | 7 +++++-- lib/main/index.js | 9 ++++++--- src/Cli/AzureCliLogin.ts | 4 ++-- src/PowerShell/AzPSUtils.ts | 3 ++- src/cleanup.ts | 7 +++++-- src/main.ts | 9 ++++++--- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/cleanup/index.js b/lib/cleanup/index.js index 714f013c0..71ed34750 100644 --- a/lib/cleanup/index.js +++ b/lib/cleanup/index.js @@ -4241,8 +4241,11 @@ function cleanup() { } } catch (error) { - core.warning(`Login cleanup failed with ${error}. Cleanup will be skipped.`); - core.debug(error.stack); + const errorMessage = error instanceof Error ? error.message : String(error); + core.warning(`Login cleanup failed with ${errorMessage}. Cleanup will be skipped.`); + if (error instanceof Error && error.stack) { + core.debug(error.stack); + } } }); } diff --git a/lib/main/index.js b/lib/main/index.js index 53710c157..d4b2ae6c6 100644 --- a/lib/main/index.js +++ b/lib/main/index.js @@ -4770,7 +4770,7 @@ function main() { try { (0, Utils_1.setUserAgent)(); const preCleanup = process.env.AZURE_LOGIN_PRE_CLEANUP; - if ('true' == preCleanup) { + if ('true' === preCleanup) { yield (0, Utils_1.cleanupAzCLIAccounts)(); if (core.getInput('enable-AzPSSession').toLowerCase() === "true") { yield (0, Utils_1.cleanupAzPSAccounts)(); @@ -4790,8 +4790,11 @@ function main() { } } catch (error) { - core.setFailed(`Login failed with ${error}. Double check if the 'auth-type' is correct. Refer to https://github.com/Azure/login#readme for more information.`); - core.debug(error.stack); + const errorMessage = error instanceof Error ? error.message : String(error); + core.setFailed(`Login failed with ${errorMessage}. Double check if the 'auth-type' is correct. Refer to https://github.com/Azure/login#readme for more information.`); + if (error instanceof Error && error.stack) { + core.debug(error.stack); + } } }); } diff --git a/src/Cli/AzureCliLogin.ts b/src/Cli/AzureCliLogin.ts index e762213f8..60290a90d 100644 --- a/src/Cli/AzureCliLogin.ts +++ b/src/Cli/AzureCliLogin.ts @@ -21,7 +21,7 @@ export class AzureCliLogin { core.debug(`Azure CLI path: ${this.azPath}`); let output: string = ""; - const execOptions: any = { + const execOptions: ExecOptions = { listeners: { stdout: (data: Buffer) => { output += data.toString(); @@ -161,7 +161,7 @@ export class AzureCliLogin { async executeAzCliCommand( args: string[], silent?: boolean, - execOptions: any = {}) { + execOptions: ExecOptions = {}) { execOptions.silent = !!silent; await exec.exec(`"${this.azPath}"`, args, execOptions); } diff --git a/src/PowerShell/AzPSUtils.ts b/src/PowerShell/AzPSUtils.ts index 4b287cfd7..5ef4644cc 100644 --- a/src/PowerShell/AzPSUtils.ts +++ b/src/PowerShell/AzPSUtils.ts @@ -2,6 +2,7 @@ import * as core from '@actions/core'; import * as os from 'os'; import * as path from 'path'; import * as exec from '@actions/exec'; +import { ExecOptions } from '@actions/exec/lib/interfaces'; import * as io from '@actions/io'; import AzPSScriptBuilder from './AzPSScriptBuilder'; @@ -54,7 +55,7 @@ export class AzPSUtils { static async runPSScript(psScript: string): Promise { let outputString: string = ""; let commandStdErr = false; - const options: any = { + const options: ExecOptions = { silent: true, listeners: { stdout: (data: Buffer) => { diff --git a/src/cleanup.ts b/src/cleanup.ts index d307920d2..0272751fe 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -10,8 +10,11 @@ async function cleanup() { } } catch (error) { - core.warning(`Login cleanup failed with ${error}. Cleanup will be skipped.`); - core.debug(error.stack); + const errorMessage = error instanceof Error ? error.message : String(error); + core.warning(`Login cleanup failed with ${errorMessage}. Cleanup will be skipped.`); + if (error instanceof Error && error.stack) { + core.debug(error.stack); + } } } diff --git a/src/main.ts b/src/main.ts index add837a9e..cd88eca1c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ async function main() { try { setUserAgent(); const preCleanup: string = process.env.AZURE_LOGIN_PRE_CLEANUP; - if ('true' == preCleanup) { + if ('true' === preCleanup) { await cleanupAzCLIAccounts(); if (core.getInput('enable-AzPSSession').toLowerCase() === "true") { await cleanupAzPSAccounts(); @@ -31,8 +31,11 @@ async function main() { } } catch (error) { - core.setFailed(`Login failed with ${error}. Double check if the 'auth-type' is correct. Refer to https://github.com/Azure/login#readme for more information.`); - core.debug(error.stack); + const errorMessage = error instanceof Error ? error.message : String(error); + core.setFailed(`Login failed with ${errorMessage}. Double check if the 'auth-type' is correct. Refer to https://github.com/Azure/login#readme for more information.`); + if (error instanceof Error && error.stack) { + core.debug(error.stack); + } } }