Skip to content

Commit

Permalink
Use high precision TS for NAA message time (#7243)
Browse files Browse the repository at this point in the history
- Use high precision TS for NAA message time to avoid clock skew.
  • Loading branch information
konstantin-msft committed Aug 12, 2024
1 parent 630605c commit 022805b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Use high precision TS for NAA message time #7243",
"packageName": "@azure/msal-browser",
"email": "kshabelko@microsoft.com",
"dependentChangeType": "patch"
}
9 changes: 7 additions & 2 deletions lib/msal-browser/src/naa/BridgeProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IBridgeProxy } from "./IBridgeProxy";
import { InitContext } from "./InitContext";
import { TokenRequest } from "./TokenRequest";
import * as BrowserCrypto from "../crypto/BrowserCrypto";
import { supportsBrowserPerformanceNow } from "../telemetry/BrowserPerformanceClient";

declare global {
interface Window {
Expand Down Expand Up @@ -81,7 +82,9 @@ export class BridgeProxy implements IBridgeProxy {
messageType: "NestedAppAuthRequest",
method: "GetInitContext",
requestId: BrowserCrypto.createNewGuid(),
sendTime: Date.now(),
sendTime: supportsBrowserPerformanceNow()
? window.performance.now()
: Date.now(),
};
const request: BridgeRequest = {
requestId: message.requestId,
Expand Down Expand Up @@ -157,7 +160,9 @@ export class BridgeProxy implements IBridgeProxy {
messageType: "NestedAppAuthRequest",
method: method,
requestId: BrowserCrypto.createNewGuid(),
sendTime: Date.now(),
sendTime: supportsBrowserPerformanceNow()
? window.performance.now()
: Date.now(),
...requestParams,
};

Expand Down
2 changes: 1 addition & 1 deletion lib/msal-browser/src/telemetry/BrowserPerformanceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getPerfMeasurementModule() {
/**
* Returns boolean, indicating whether browser supports window.performance.now() function.
*/
function supportsBrowserPerformanceNow(): boolean {
export function supportsBrowserPerformanceNow(): boolean {
return (
typeof window !== "undefined" &&
typeof window.performance !== "undefined" &&
Expand Down

0 comments on commit 022805b

Please sign in to comment.