From e7c822e76661fd3c5880f82f54dcf73f6f278356 Mon Sep 17 00:00:00 2001 From: Lalima Sharda Date: Fri, 17 Oct 2025 12:34:17 -0700 Subject: [PATCH 1/4] getNativeAccountId fix --- lib/msal-browser/src/cache/AccountManager.ts | 5 ----- .../test/cache/BrowserCacheManager.spec.ts | 19 +++++++++++++++++++ lib/msal-common/src/cache/CacheManager.ts | 9 +++++++++ .../test/cache/CacheManager.spec.ts | 12 ++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/msal-browser/src/cache/AccountManager.ts b/lib/msal-browser/src/cache/AccountManager.ts index 8c009b84d7..6537f316b9 100644 --- a/lib/msal-browser/src/cache/AccountManager.ts +++ b/lib/msal-browser/src/cache/AccountManager.ts @@ -36,11 +36,6 @@ export function getAccount( correlationId: string ): AccountInfo | null { logger.trace("getAccount called"); - if (Object.keys(accountFilter).length === 0) { - logger.warning("getAccount: No accountFilter provided"); - return null; - } - const account: AccountInfo | null = browserStorage.getAccountInfoFilteredBy( accountFilter, correlationId diff --git a/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts b/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts index e83e56cdbf..b8ccf207f9 100644 --- a/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts +++ b/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts @@ -35,6 +35,7 @@ import { AccountEntityUtils, Constants, CredentialEntity, + AccountFilter, } from "@azure/msal-common"; import { BrowserCacheLocation, @@ -50,6 +51,7 @@ import { BrowserPerformanceClient } from "../../src/telemetry/BrowserPerformance import { EventHandler } from "../../src/event/EventHandler.js"; import { version } from "../../src/packageMetadata.js"; import * as CacheKeys from "../../src/cache/CacheKeys.js"; +import { getAccount } from "../../src/cache/AccountManager.js"; describe("BrowserCacheManager tests", () => { let cacheConfig: Required; @@ -2299,6 +2301,23 @@ describe("BrowserCacheManager tests", () => { ) ).toEqual(testAccount); }); + + + it("getAccount returns null if accountfilter is passed but values are undefined", () => { + const testAccountFilter: AccountFilter = { + loginHint: undefined, + sid: undefined, + }; + + expect( + getAccount( + testAccountFilter, + logger, + browserSessionStorage, + TEST_CONFIG.CORRELATION_ID + ) + ).toEqual(null); + }); }); describe("IdTokenCredential", () => { diff --git a/lib/msal-common/src/cache/CacheManager.ts b/lib/msal-common/src/cache/CacheManager.ts index 736a3ed050..a85e3bf024 100644 --- a/lib/msal-common/src/cache/CacheManager.ts +++ b/lib/msal-common/src/cache/CacheManager.ts @@ -280,6 +280,15 @@ export abstract class CacheManager implements ICacheManager { accountFilter: AccountFilter, correlationId: string ): AccountInfo | null { + if ( + Object.keys(accountFilter).length === 0 || + Object.values(accountFilter).every((value) => !value) + ) { + this.commonLogger.warning( + "getAccountInfoFilteredBy: Account filter is empty or invalid, returning null" + ); + return null; + } const allAccounts = this.getAllAccounts(accountFilter, correlationId); if (allAccounts.length > 1) { // If one or more accounts are found, prioritize accounts that have an ID token diff --git a/lib/msal-common/test/cache/CacheManager.spec.ts b/lib/msal-common/test/cache/CacheManager.spec.ts index 07aa74f7d1..9824f8b2e0 100644 --- a/lib/msal-common/test/cache/CacheManager.spec.ts +++ b/lib/msal-common/test/cache/CacheManager.spec.ts @@ -686,6 +686,18 @@ describe("CacheManager.ts test cases", () => { ).toBeNull(); }); + it("returns null if filter passed in is empty", () => { + expect( + mockCache.cacheManager.getAccountInfoFilteredBy( + { + homeAccountId: "", + loginHint: "", + }, + RANDOM_TEST_GUID + ) + ).toBeNull(); + }); + it("returns an account matching filter", () => { const resultAccount = mockCache.cacheManager.getAccountInfoFilteredBy( From bff242e3d9fe93de7012c727481b75f58bd2b93a Mon Sep 17 00:00:00 2001 From: Lalima Sharda Date: Fri, 17 Oct 2025 12:45:59 -0700 Subject: [PATCH 2/4] Update lib/msal-browser/test/cache/BrowserCacheManager.spec.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/msal-browser/test/cache/BrowserCacheManager.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts b/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts index 5bc23b1e19..40b2f6c9df 100644 --- a/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts +++ b/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts @@ -2315,7 +2315,7 @@ describe("BrowserCacheManager tests", () => { }); - it("getAccount returns null if accountfilter is passed but values are undefined", () => { + it("getAccount returns null if accountFilter is passed but values are undefined", () => { const testAccountFilter: AccountFilter = { loginHint: undefined, sid: undefined, From 73f9a4108207ebf8cf9c5a2fbcddabc3444ac30d Mon Sep 17 00:00:00 2001 From: Lalima Sharda Date: Fri, 17 Oct 2025 12:58:28 -0700 Subject: [PATCH 3/4] Change files --- ...-msal-browser-f0c007ae-e311-4ceb-9576-4ddb9e737326.json | 7 +++++++ ...e-msal-common-034baa00-0efc-4248-b3c9-df6d476a271d.json | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 change/@azure-msal-browser-f0c007ae-e311-4ceb-9576-4ddb9e737326.json create mode 100644 change/@azure-msal-common-034baa00-0efc-4248-b3c9-df6d476a271d.json diff --git a/change/@azure-msal-browser-f0c007ae-e311-4ceb-9576-4ddb9e737326.json b/change/@azure-msal-browser-f0c007ae-e311-4ceb-9576-4ddb9e737326.json new file mode 100644 index 0000000000..bfb204ec62 --- /dev/null +++ b/change/@azure-msal-browser-f0c007ae-e311-4ceb-9576-4ddb9e737326.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "getNativeAccountId() bugfix for v5 #8105", + "packageName": "@azure/msal-browser", + "email": "lalimasharda@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@azure-msal-common-034baa00-0efc-4248-b3c9-df6d476a271d.json b/change/@azure-msal-common-034baa00-0efc-4248-b3c9-df6d476a271d.json new file mode 100644 index 0000000000..ba909ae465 --- /dev/null +++ b/change/@azure-msal-common-034baa00-0efc-4248-b3c9-df6d476a271d.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "bugfix - added filter validity check in getAccountInfoFilteredBy() #8105", + "packageName": "@azure/msal-common", + "email": "lalimasharda@microsoft.com", + "dependentChangeType": "patch" +} From 87b9951404236818a04e857fbf9e71cf734299de Mon Sep 17 00:00:00 2001 From: Lalima Sharda Date: Fri, 17 Oct 2025 13:58:19 -0700 Subject: [PATCH 4/4] fixing build errors --- lib/msal-browser/src/cache/AccountManager.ts | 2 +- .../test/cache/BrowserCacheManager.spec.ts | 1 - lib/msal-common/apiReview/msal-common.api.md | 68 +++++++++---------- lib/msal-common/src/cache/CacheManager.ts | 5 +- .../test/cache/CacheManager.spec.ts | 2 +- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/msal-browser/src/cache/AccountManager.ts b/lib/msal-browser/src/cache/AccountManager.ts index b4cdb3495b..4aaeff5e1d 100644 --- a/lib/msal-browser/src/cache/AccountManager.ts +++ b/lib/msal-browser/src/cache/AccountManager.ts @@ -35,7 +35,7 @@ export function getAccount( browserStorage: BrowserCacheManager, correlationId: string ): AccountInfo | null { - logger.trace("getAccount called"); + logger.trace("getAccount called", correlationId); const account: AccountInfo | null = browserStorage.getAccountInfoFilteredBy( accountFilter, correlationId diff --git a/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts b/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts index 40b2f6c9df..cdff30e1c5 100644 --- a/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts +++ b/lib/msal-browser/test/cache/BrowserCacheManager.spec.ts @@ -2314,7 +2314,6 @@ describe("BrowserCacheManager tests", () => { ).toEqual(testAccount); }); - it("getAccount returns null if accountFilter is passed but values are undefined", () => { const testAccountFilter: AccountFilter = { loginHint: undefined, diff --git a/lib/msal-common/apiReview/msal-common.api.md b/lib/msal-common/apiReview/msal-common.api.md index 64e8bcf836..2d90990d9a 100644 --- a/lib/msal-common/apiReview/msal-common.api.md +++ b/lib/msal-common/apiReview/msal-common.api.md @@ -4608,42 +4608,42 @@ const X_MS_LIB_CAPABILITY_VALUE: string; // src/authority/Authority.ts:802:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // src/authority/Authority.ts:1000:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // src/authority/AuthorityOptions.ts:25:5 - (ae-forgotten-export) The symbol "CloudInstanceDiscoveryResponse" needs to be exported by the entry point index.d.ts -// src/cache/CacheManager.ts:336:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:337:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:605:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1568:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1569:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1583:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1584:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1604:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1605:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:345:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:346:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:614:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1577:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1578:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1592:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1593:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1613:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // src/cache/CacheManager.ts:1614:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1615:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1631:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1632:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1646:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1647:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1685:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1686:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1700:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1701:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1712:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1713:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1724:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1725:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1736:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1737:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1754:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1755:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1779:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1780:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1799:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1800:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1819:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1820:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1831:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/cache/CacheManager.ts:1832:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1623:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1624:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1640:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1641:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1655:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1656:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1694:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1695:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1709:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1710:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1721:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1722:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1733:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1734:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1745:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1746:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1763:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1764:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1788:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1789:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1808:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1809:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1828:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1829:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // src/cache/CacheManager.ts:1840:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1841:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/cache/CacheManager.ts:1849:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // src/cache/entities/AccountEntity.ts:49:5 - (ae-forgotten-export) The symbol "DataBoundary" needs to be exported by the entry point index.d.ts // src/cache/utils/CacheTypes.ts:93:53 - (tsdoc-escape-greater-than) The ">" character should be escaped using a backslash to avoid confusion with an HTML tag // src/cache/utils/CacheTypes.ts:93:43 - (tsdoc-malformed-html-name) Invalid HTML element: An HTML name must be an ASCII letter followed by zero or more letters, digits, or hyphens diff --git a/lib/msal-common/src/cache/CacheManager.ts b/lib/msal-common/src/cache/CacheManager.ts index 0e319243c2..1234503e81 100644 --- a/lib/msal-common/src/cache/CacheManager.ts +++ b/lib/msal-common/src/cache/CacheManager.ts @@ -295,12 +295,13 @@ export abstract class CacheManager implements ICacheManager { accountFilter: AccountFilter, correlationId: string ): AccountInfo | null { - if ( + if ( Object.keys(accountFilter).length === 0 || Object.values(accountFilter).every((value) => !value) ) { this.commonLogger.warning( - "getAccountInfoFilteredBy: Account filter is empty or invalid, returning null" + "getAccountInfoFilteredBy: Account filter is empty or invalid, returning null", + correlationId ); return null; } diff --git a/lib/msal-common/test/cache/CacheManager.spec.ts b/lib/msal-common/test/cache/CacheManager.spec.ts index 13af84409f..01ebed11bb 100644 --- a/lib/msal-common/test/cache/CacheManager.spec.ts +++ b/lib/msal-common/test/cache/CacheManager.spec.ts @@ -686,7 +686,7 @@ describe("CacheManager.ts test cases", () => { ).toBeNull(); }); - it("returns null if filter passed in is empty", () => { + it("returns null if filter passed in is empty", () => { expect( mockCache.cacheManager.getAccountInfoFilteredBy( {