Skip to content

Commit aea33cb

Browse files
committed
fix(core): add error metadata indicating clock skew correction
1 parent e1ba507 commit aea33cb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/core/src/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ interface AwsSdkSigV4AuthSigningProperties {
4545
*/
4646
interface AwsSdkSigV4Exception extends ServiceException {
4747
ServerTime?: string;
48+
$metadata: ServiceException["$metadata"] & {
49+
clockSkewCorrected?: boolean;
50+
};
4851
}
4952

5053
/**
@@ -104,11 +107,13 @@ export class AwsSdkSigV4Signer implements HttpSigner {
104107
const serverTime: string | undefined =
105108
(error as AwsSdkSigV4Exception).ServerTime ?? getDateHeader((error as AwsSdkSigV4Exception).$response);
106109
if (serverTime) {
107-
const config = throwSigningPropertyError(
108-
"config",
109-
signingProperties.config as AwsSdkSigV4Config | undefined
110-
);
110+
const config = throwSigningPropertyError("config", signingProperties.config as AwsSdkSigV4Config | undefined);
111+
const initialSystemClockOffset = config.systemClockOffset;
111112
config.systemClockOffset = getUpdatedSystemClockOffset(serverTime, config.systemClockOffset);
113+
const clockSkewCorrected = config.systemClockOffset !== initialSystemClockOffset;
114+
if (clockSkewCorrected) {
115+
(error as AwsSdkSigV4Exception).$metadata.clockSkewCorrected = true;
116+
}
112117
}
113118
throw error;
114119
};
@@ -117,10 +122,7 @@ export class AwsSdkSigV4Signer implements HttpSigner {
117122
successHandler(httpResponse: HttpResponse | unknown, signingProperties: Record<string, unknown>): void {
118123
const dateHeader = getDateHeader(httpResponse);
119124
if (dateHeader) {
120-
const config = throwSigningPropertyError(
121-
"config",
122-
signingProperties.config as AwsSdkSigV4Config | undefined
123-
);
125+
const config = throwSigningPropertyError("config", signingProperties.config as AwsSdkSigV4Config | undefined);
124126
config.systemClockOffset = getUpdatedSystemClockOffset(dateHeader, config.systemClockOffset);
125127
}
126128
}

0 commit comments

Comments
 (0)