@aws-sdk/core 3.976.0 → 3.977.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/submodules/httpAuthSchemes/index.js +66 -28
- package/dist-cjs/submodules/protocols/index.js +111 -12
- package/dist-es/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4ASigner.js +7 -2
- package/dist-es/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.js +28 -14
- package/dist-es/submodules/httpAuthSchemes/aws_sdk/clock-skew-defaults.browser.js +1 -0
- package/dist-es/submodules/httpAuthSchemes/aws_sdk/clock-skew-defaults.js +3 -0
- package/dist-es/submodules/httpAuthSchemes/aws_sdk/clock-skew-node-config.js +8 -0
- package/dist-es/submodules/httpAuthSchemes/aws_sdk/index.js +1 -1
- package/dist-es/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.js +3 -3
- package/dist-es/submodules/httpAuthSchemes/index.browser.js +9 -0
- package/dist-es/submodules/httpAuthSchemes/index.js +5 -1
- package/dist-es/submodules/httpAuthSchemes/utils/getDateHeader.js +1 -0
- package/dist-es/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.js +12 -6
- package/dist-es/submodules/httpAuthSchemes/utils/index.js +2 -1
- package/dist-es/submodules/httpAuthSchemes/utils/isClockSkewed.js +1 -1
- package/dist-es/submodules/protocols/json/JsonShapeDeserializer.js +10 -1
- package/dist-es/submodules/protocols/json/JsonShapeSerializer.js +10 -0
- package/dist-es/submodules/protocols/json/detectBufferParsing.js +18 -0
- package/dist-es/submodules/protocols/json/experimental/BufferJsonShapeDeserializer.js +13 -15
- package/dist-es/submodules/protocols/json/experimental/ByteJsonShapeSerializer.js +27 -17
- package/dist-es/submodules/protocols/json/needsReviver.js +41 -0
- package/dist-es/submodules/protocols/json/parseJsonBody.js +33 -13
- package/dist-es/submodules/protocols/writeKey.js +3 -0
- package/dist-es/submodules/protocols/xml/XmlShapeDeserializer.js +4 -0
- package/dist-types/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.d.ts +2 -1
- package/dist-types/submodules/httpAuthSchemes/aws_sdk/clock-skew-defaults.browser.d.ts +6 -0
- package/dist-types/submodules/httpAuthSchemes/aws_sdk/clock-skew-defaults.d.ts +7 -0
- package/dist-types/submodules/httpAuthSchemes/aws_sdk/clock-skew-node-config.d.ts +13 -0
- package/dist-types/submodules/httpAuthSchemes/aws_sdk/index.d.ts +1 -1
- package/dist-types/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.d.ts +22 -6
- package/dist-types/submodules/httpAuthSchemes/index.browser.d.ts +11 -0
- package/dist-types/submodules/httpAuthSchemes/index.d.ts +7 -1
- package/dist-types/submodules/httpAuthSchemes/utils/getDateHeader.d.ts +4 -0
- package/dist-types/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.d.ts +22 -6
- package/dist-types/submodules/httpAuthSchemes/utils/index.d.ts +2 -1
- package/dist-types/submodules/protocols/json/detectBufferParsing.d.ts +1 -0
- package/dist-types/submodules/protocols/json/experimental/ByteJsonShapeSerializer.d.ts +0 -2
- package/dist-types/submodules/protocols/json/needsReviver.d.ts +11 -0
- package/dist-types/submodules/protocols/json/parseJsonBody.d.ts +7 -2
- package/dist-types/submodules/protocols/writeKey.d.ts +4 -0
- package/dist-types/ts3.4/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.d.ts +2 -0
- package/dist-types/ts3.4/submodules/httpAuthSchemes/aws_sdk/clock-skew-defaults.browser.d.ts +1 -0
- package/dist-types/ts3.4/submodules/httpAuthSchemes/aws_sdk/clock-skew-defaults.d.ts +1 -0
- package/dist-types/ts3.4/submodules/httpAuthSchemes/aws_sdk/clock-skew-node-config.d.ts +4 -0
- package/dist-types/ts3.4/submodules/httpAuthSchemes/aws_sdk/index.d.ts +1 -1
- package/dist-types/ts3.4/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.d.ts +7 -6
- package/dist-types/ts3.4/submodules/httpAuthSchemes/index.browser.d.ts +32 -0
- package/dist-types/ts3.4/submodules/httpAuthSchemes/index.d.ts +10 -2
- package/dist-types/ts3.4/submodules/httpAuthSchemes/utils/getDateHeader.d.ts +1 -0
- package/dist-types/ts3.4/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.d.ts +2 -0
- package/dist-types/ts3.4/submodules/httpAuthSchemes/utils/index.d.ts +2 -1
- package/dist-types/ts3.4/submodules/protocols/json/detectBufferParsing.d.ts +1 -0
- package/dist-types/ts3.4/submodules/protocols/json/experimental/ByteJsonShapeSerializer.d.ts +0 -2
- package/dist-types/ts3.4/submodules/protocols/json/needsReviver.d.ts +2 -0
- package/dist-types/ts3.4/submodules/protocols/json/parseJsonBody.d.ts +7 -2
- package/dist-types/ts3.4/submodules/protocols/writeKey.d.ts +1 -0
- package/package.json +10 -6
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const { normalizeProvider, memoizeIdentityProvider, isIdentityExpired, doesIdentityRequireRefresh } = require("@smithy/core");
|
|
3
|
-
const { ProviderError } = require("@smithy/core/config");
|
|
1
|
+
const { ProviderError, booleanSelector, SelectorType, loadConfig } = require("@smithy/core/config");
|
|
4
2
|
const { setCredentialFeature } = require("@aws-sdk/core/client");
|
|
3
|
+
const { normalizeProvider, memoizeIdentityProvider, isIdentityExpired, doesIdentityRequireRefresh } = require("@smithy/core");
|
|
5
4
|
const { SignatureV4 } = require("@smithy/signature-v4");
|
|
5
|
+
const { HttpResponse, HttpRequest } = require("@smithy/core/protocols");
|
|
6
6
|
|
|
7
7
|
const getDateHeader = (response) => HttpResponse.isInstance(response) ? (response.headers?.date ?? response.headers?.Date) : undefined;
|
|
8
|
+
const getAgeHeader = (response) => HttpResponse.isInstance(response) ? (response.headers?.age ?? response.headers?.Age) : undefined;
|
|
8
9
|
|
|
9
10
|
const getSkewCorrectedDate = (systemClockOffset) => new Date(Date.now() + systemClockOffset);
|
|
10
11
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const getUpdatedSystemClockOffset = (clockTime, currentSystemClockOffset, timeRequestSent, ageHeader) => {
|
|
13
|
+
if (ageHeader !== undefined) {
|
|
14
|
+
return currentSystemClockOffset;
|
|
15
|
+
}
|
|
16
|
+
const serverTime = Date.parse(clockTime);
|
|
17
|
+
const timeResponseReceived = Date.now();
|
|
18
|
+
if (timeRequestSent !== undefined && timeResponseReceived - timeRequestSent > 900_000) {
|
|
19
|
+
return currentSystemClockOffset;
|
|
17
20
|
}
|
|
18
|
-
|
|
21
|
+
const candidateSkew = timeRequestSent !== undefined
|
|
22
|
+
? serverTime - (timeRequestSent + timeResponseReceived) / 2
|
|
23
|
+
: serverTime - timeResponseReceived;
|
|
24
|
+
return candidateSkew;
|
|
19
25
|
};
|
|
20
26
|
|
|
21
27
|
const throwSigningPropertyError = (name, property) => {
|
|
@@ -57,9 +63,14 @@ class AwsSdkSigV4Signer {
|
|
|
57
63
|
signingName = second?.signingName ?? signingName;
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
|
-
|
|
66
|
+
const noSkewCorrection = (await config.disableClockSkewCorrection?.()) === true;
|
|
67
|
+
signingProperties._disableClockSkewCorrection = noSkewCorrection;
|
|
68
|
+
if (!noSkewCorrection) {
|
|
69
|
+
signingProperties._preRequestSystemClockOffset = config.systemClockOffset;
|
|
70
|
+
signingProperties._requestSentAt = Date.now();
|
|
71
|
+
}
|
|
61
72
|
const signedRequest = await signer.sign(httpRequest, {
|
|
62
|
-
signingDate: getSkewCorrectedDate(config.systemClockOffset),
|
|
73
|
+
signingDate: noSkewCorrection ? new Date() : getSkewCorrectedDate(config.systemClockOffset),
|
|
63
74
|
signingRegion: signingRegion,
|
|
64
75
|
signingService: signingName,
|
|
65
76
|
});
|
|
@@ -68,27 +79,36 @@ class AwsSdkSigV4Signer {
|
|
|
68
79
|
errorHandler(signingProperties) {
|
|
69
80
|
return (error) => {
|
|
70
81
|
const errorException = error;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (clockSkewCorrected && errorException.$metadata) {
|
|
82
|
+
if (!signingProperties._disableClockSkewCorrection) {
|
|
83
|
+
const serverTime = errorException.ServerTime ?? getDateHeader(errorException.$response);
|
|
84
|
+
if (serverTime) {
|
|
85
|
+
const config = throwSigningPropertyError("config", signingProperties.config);
|
|
86
|
+
const preRequestOffset = signingProperties._preRequestSystemClockOffset;
|
|
87
|
+
const timeRequestSent = signingProperties._requestSentAt;
|
|
88
|
+
const ageHeader = getAgeHeader(errorException.$response);
|
|
89
|
+
const newOffset = getUpdatedSystemClockOffset(serverTime, config.systemClockOffset, timeRequestSent, ageHeader);
|
|
80
90
|
config.systemClockOffset = newOffset;
|
|
81
|
-
|
|
91
|
+
const skewExceedsThreshold = Math.abs(newOffset) >= 240_000;
|
|
92
|
+
const isLocalCorrection = newOffset !== preRequestOffset;
|
|
93
|
+
const isConcurrentCorrection = preRequestOffset !== undefined && preRequestOffset !== newOffset;
|
|
94
|
+
if (skewExceedsThreshold && (isLocalCorrection || isConcurrentCorrection) && errorException.$metadata) {
|
|
95
|
+
errorException.$metadata.clockSkewCorrected = true;
|
|
96
|
+
}
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
99
|
throw error;
|
|
85
100
|
};
|
|
86
101
|
}
|
|
87
102
|
successHandler(httpResponse, signingProperties) {
|
|
103
|
+
if (signingProperties._disableClockSkewCorrection) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
88
106
|
const dateHeader = getDateHeader(httpResponse);
|
|
89
107
|
if (dateHeader) {
|
|
90
108
|
const config = throwSigningPropertyError("config", signingProperties.config);
|
|
91
|
-
|
|
109
|
+
const timeRequestSent = signingProperties._requestSentAt;
|
|
110
|
+
const ageHeader = getAgeHeader(httpResponse);
|
|
111
|
+
config.systemClockOffset = getUpdatedSystemClockOffset(dateHeader, config.systemClockOffset, timeRequestSent, ageHeader);
|
|
92
112
|
}
|
|
93
113
|
}
|
|
94
114
|
}
|
|
@@ -103,9 +123,14 @@ class AwsSdkSigV4ASigner extends AwsSdkSigV4Signer {
|
|
|
103
123
|
const configResolvedSigningRegionSet = await config.sigv4aSigningRegionSet?.();
|
|
104
124
|
const multiRegionOverride = (configResolvedSigningRegionSet ??
|
|
105
125
|
signingRegionSet ?? [signingRegion]).join(",");
|
|
106
|
-
|
|
126
|
+
const noSkewCorrection = (await config.disableClockSkewCorrection?.()) === true;
|
|
127
|
+
signingProperties._disableClockSkewCorrection = noSkewCorrection;
|
|
128
|
+
if (!noSkewCorrection) {
|
|
129
|
+
signingProperties._preRequestSystemClockOffset = config.systemClockOffset;
|
|
130
|
+
signingProperties._requestSentAt = Date.now();
|
|
131
|
+
}
|
|
107
132
|
const signedRequest = await signer.sign(httpRequest, {
|
|
108
|
-
signingDate: getSkewCorrectedDate(config.systemClockOffset),
|
|
133
|
+
signingDate: noSkewCorrection ? new Date() : getSkewCorrectedDate(config.systemClockOffset),
|
|
109
134
|
signingRegion: multiRegionOverride,
|
|
110
135
|
signingService: signingName,
|
|
111
136
|
});
|
|
@@ -162,7 +187,7 @@ const NODE_SIGV4A_CONFIG_OPTIONS = {
|
|
|
162
187
|
default: undefined,
|
|
163
188
|
};
|
|
164
189
|
|
|
165
|
-
const
|
|
190
|
+
const bindResolveAwsSdkSigV4Config = (defaultDisableClockSkewCorrection) => (config) => {
|
|
166
191
|
let inputCredentials = config.credentials;
|
|
167
192
|
let isUserSupplied = !!config.credentials;
|
|
168
193
|
let resolvedCredentials = undefined;
|
|
@@ -260,11 +285,11 @@ const resolveAwsSdkSigV4Config = (config) => {
|
|
|
260
285
|
systemClockOffset,
|
|
261
286
|
signingEscapePath,
|
|
262
287
|
signer,
|
|
288
|
+
disableClockSkewCorrection: normalizeProvider(config.disableClockSkewCorrection ?? defaultDisableClockSkewCorrection),
|
|
263
289
|
});
|
|
264
290
|
return resolvedConfig;
|
|
265
291
|
};
|
|
266
|
-
|
|
267
|
-
function normalizeCredentialProvider(config, { credentials, credentialDefaultProvider, }) {
|
|
292
|
+
function normalizeCredentialProvider(config, { credentials, credentialDefaultProvider }) {
|
|
268
293
|
let credentialsProvider;
|
|
269
294
|
if (credentials) {
|
|
270
295
|
if (!credentials?.memoized) {
|
|
@@ -299,6 +324,19 @@ function bindCallerConfig(config, credentialsProvider) {
|
|
|
299
324
|
return fn;
|
|
300
325
|
}
|
|
301
326
|
|
|
327
|
+
const ENV_DISABLE_CLOCK_SKEW_CORRECTION = "AWS_DISABLE_CLOCK_SKEW_CORRECTION";
|
|
328
|
+
const CONFIG_DISABLE_CLOCK_SKEW_CORRECTION = "disable_clock_skew_correction";
|
|
329
|
+
const NODE_DISABLE_CLOCK_SKEW_CORRECTION_CONFIG_OPTIONS = {
|
|
330
|
+
environmentVariableSelector: (env) => booleanSelector(env, ENV_DISABLE_CLOCK_SKEW_CORRECTION, SelectorType.ENV),
|
|
331
|
+
configFileSelector: (profile) => booleanSelector(profile, CONFIG_DISABLE_CLOCK_SKEW_CORRECTION, SelectorType.CONFIG),
|
|
332
|
+
default: false,
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const DEFAULT_DISABLE_CLOCK_SKEW_CORRECTION = loadConfig(NODE_DISABLE_CLOCK_SKEW_CORRECTION_CONFIG_OPTIONS);
|
|
336
|
+
|
|
337
|
+
const resolveAwsSdkSigV4Config = bindResolveAwsSdkSigV4Config(DEFAULT_DISABLE_CLOCK_SKEW_CORRECTION);
|
|
338
|
+
const resolveAWSSDKSigV4Config = resolveAwsSdkSigV4Config;
|
|
339
|
+
|
|
302
340
|
exports.AWSSDKSigV4Signer = AWSSDKSigV4Signer;
|
|
303
341
|
exports.AwsSdkSigV4ASigner = AwsSdkSigV4ASigner;
|
|
304
342
|
exports.AwsSdkSigV4Signer = AwsSdkSigV4Signer;
|
|
@@ -295,24 +295,100 @@ function jsonReviver(key, value, context) {
|
|
|
295
295
|
return value;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
const REVIVER_SYMBOL = Symbol.for("@aws-sdk/reviver");
|
|
299
|
+
function needsReviver(schema) {
|
|
300
|
+
const ns = NormalizedSchema.of(schema);
|
|
301
|
+
const raw = ns.getSchema();
|
|
302
|
+
if (Array.isArray(raw) && ns.isStructSchema()) {
|
|
303
|
+
if (REVIVER_SYMBOL in raw) {
|
|
304
|
+
return raw[REVIVER_SYMBOL];
|
|
305
|
+
}
|
|
306
|
+
const result = _check(ns, new Set());
|
|
307
|
+
raw[REVIVER_SYMBOL] = result;
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
return _check(ns, new Set());
|
|
311
|
+
}
|
|
312
|
+
function _check(ns, seen) {
|
|
313
|
+
const raw = ns.getSchema();
|
|
314
|
+
if (seen.has(raw)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
seen.add(raw);
|
|
318
|
+
if (ns.isBigIntegerSchema() || ns.isBigDecimalSchema()) {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
if (ns.isStructSchema()) {
|
|
322
|
+
for (const [, memberSchema] of ns.structIterator()) {
|
|
323
|
+
if (_check(memberSchema, seen)) {
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
else if (ns.isListSchema() || ns.isMapSchema()) {
|
|
329
|
+
if (_check(ns.getValueSchema(), seen)) {
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else if (ns.isDocumentSchema()) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
|
|
298
339
|
const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => (context?.utf8Encoder ?? toUtf8)(body));
|
|
299
340
|
|
|
300
|
-
|
|
301
|
-
|
|
341
|
+
let canParseBuffer;
|
|
342
|
+
function detectBufferParsing() {
|
|
343
|
+
if (canParseBuffer === undefined) {
|
|
302
344
|
try {
|
|
303
|
-
|
|
345
|
+
if (typeof Buffer !== "function") {
|
|
346
|
+
canParseBuffer = false;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
const result = JSON.parse(Buffer.from([0x7b, 0x7d]));
|
|
350
|
+
canParseBuffer = result !== null && typeof result === "object";
|
|
351
|
+
}
|
|
304
352
|
}
|
|
305
|
-
catch
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
353
|
+
catch {
|
|
354
|
+
canParseBuffer = false;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return canParseBuffer;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
async function parseJsonBody(streamBody, context, schema) {
|
|
361
|
+
let parsingInput;
|
|
362
|
+
if (detectBufferParsing() && typeof streamBody?.[Symbol.asyncIterator] === "function") {
|
|
363
|
+
const buffer = await collectBody(streamBody, context);
|
|
364
|
+
if (typeof Buffer === "function") {
|
|
365
|
+
if (Buffer.isBuffer(buffer)) {
|
|
366
|
+
parsingInput = buffer;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
parsingInput = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
310
370
|
}
|
|
311
|
-
throw e;
|
|
312
371
|
}
|
|
313
372
|
}
|
|
314
|
-
|
|
315
|
-
|
|
373
|
+
if (!parsingInput) {
|
|
374
|
+
parsingInput = await collectBodyString(streamBody, context);
|
|
375
|
+
}
|
|
376
|
+
if (parsingInput.length === 0) {
|
|
377
|
+
return {};
|
|
378
|
+
}
|
|
379
|
+
const reviver = schema && needsReviver(schema) ? jsonReviver : undefined;
|
|
380
|
+
try {
|
|
381
|
+
return JSON.parse(parsingInput, reviver);
|
|
382
|
+
}
|
|
383
|
+
catch (e) {
|
|
384
|
+
if (e?.name === "SyntaxError") {
|
|
385
|
+
Object.defineProperty(e, "$responseBodyText", {
|
|
386
|
+
value: typeof parsingInput === "string" ? parsingInput : parsingInput.toString("utf8"),
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
throw e;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
316
392
|
const parseJsonErrorBody = async (errorBody, context) => {
|
|
317
393
|
const value = await parseJsonBody(errorBody, context);
|
|
318
394
|
value.message = value.message ?? value.Message;
|
|
@@ -366,6 +442,10 @@ const loadErrorCode = ({ headers }, data, order) => {
|
|
|
366
442
|
}
|
|
367
443
|
};
|
|
368
444
|
|
|
445
|
+
function writeKey(obj) {
|
|
446
|
+
Object.defineProperty(obj, "__proto__", { value: undefined, writable: true, enumerable: true, configurable: true });
|
|
447
|
+
}
|
|
448
|
+
|
|
369
449
|
class JsonShapeDeserializer extends SerdeContextConfig {
|
|
370
450
|
settings;
|
|
371
451
|
constructor(settings) {
|
|
@@ -373,7 +453,8 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
373
453
|
this.settings = settings;
|
|
374
454
|
}
|
|
375
455
|
async read(schema, data) {
|
|
376
|
-
|
|
456
|
+
const reviver = needsReviver(schema) ? jsonReviver : undefined;
|
|
457
|
+
return this._read(schema, typeof data === "string" ? JSON.parse(data, reviver) : await parseJsonBody(data, this.serdeContext, schema));
|
|
377
458
|
}
|
|
378
459
|
readObject(schema, data) {
|
|
379
460
|
return this._read(schema, data);
|
|
@@ -434,6 +515,9 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
434
515
|
const mapMember = ns.getValueSchema();
|
|
435
516
|
const out = {};
|
|
436
517
|
for (const _k in value) {
|
|
518
|
+
if (_k === "__proto__") {
|
|
519
|
+
writeKey(out);
|
|
520
|
+
}
|
|
437
521
|
out[_k] = this._read(mapMember, value[_k]);
|
|
438
522
|
}
|
|
439
523
|
return out;
|
|
@@ -492,6 +576,9 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
492
576
|
if (isObject) {
|
|
493
577
|
const out = Array.isArray(value) ? [] : {};
|
|
494
578
|
for (const k in value) {
|
|
579
|
+
if (k === "__proto__") {
|
|
580
|
+
writeKey(out);
|
|
581
|
+
}
|
|
495
582
|
const v = value[k];
|
|
496
583
|
if (v instanceof NumericValue) {
|
|
497
584
|
out[k] = v;
|
|
@@ -617,6 +704,9 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
617
704
|
const { $unknown } = record;
|
|
618
705
|
if (Array.isArray($unknown)) {
|
|
619
706
|
const [k, v] = $unknown;
|
|
707
|
+
if (k === "__proto__") {
|
|
708
|
+
writeKey(out);
|
|
709
|
+
}
|
|
620
710
|
out[k] = this._write(15, v);
|
|
621
711
|
}
|
|
622
712
|
}
|
|
@@ -649,6 +739,9 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
649
739
|
for (const _k in value) {
|
|
650
740
|
const _v = value[_k];
|
|
651
741
|
if (sparse || _v != null) {
|
|
742
|
+
if (_k === "__proto__") {
|
|
743
|
+
writeKey(out);
|
|
744
|
+
}
|
|
652
745
|
out[_k] = this._write(mapMember, _v);
|
|
653
746
|
}
|
|
654
747
|
}
|
|
@@ -714,6 +807,9 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
714
807
|
const out = Array.isArray(value) ? [] : {};
|
|
715
808
|
for (const k in value) {
|
|
716
809
|
const v = value[k];
|
|
810
|
+
if (k === "__proto__") {
|
|
811
|
+
writeKey(out);
|
|
812
|
+
}
|
|
717
813
|
if (v instanceof NumericValue) {
|
|
718
814
|
this.useReplacer = true;
|
|
719
815
|
out[k] = v;
|
|
@@ -1037,6 +1133,9 @@ class XmlShapeDeserializer extends SerdeContextConfig {
|
|
|
1037
1133
|
for (const entry of entries) {
|
|
1038
1134
|
const key = entry[keyProperty];
|
|
1039
1135
|
const value = entry[valueProperty];
|
|
1136
|
+
if (key === "__proto__") {
|
|
1137
|
+
writeKey(buffer);
|
|
1138
|
+
}
|
|
1040
1139
|
buffer[key] = this.readSchema(memberNs, value);
|
|
1041
1140
|
}
|
|
1042
1141
|
return buffer;
|
|
@@ -10,9 +10,14 @@ export class AwsSdkSigV4ASigner extends AwsSdkSigV4Signer {
|
|
|
10
10
|
const configResolvedSigningRegionSet = await config.sigv4aSigningRegionSet?.();
|
|
11
11
|
const multiRegionOverride = (configResolvedSigningRegionSet ??
|
|
12
12
|
signingRegionSet ?? [signingRegion]).join(",");
|
|
13
|
-
|
|
13
|
+
const noSkewCorrection = (await config.disableClockSkewCorrection?.()) === true;
|
|
14
|
+
signingProperties._disableClockSkewCorrection = noSkewCorrection;
|
|
15
|
+
if (!noSkewCorrection) {
|
|
16
|
+
signingProperties._preRequestSystemClockOffset = config.systemClockOffset;
|
|
17
|
+
signingProperties._requestSentAt = Date.now();
|
|
18
|
+
}
|
|
14
19
|
const signedRequest = await signer.sign(httpRequest, {
|
|
15
|
-
signingDate: getSkewCorrectedDate(config.systemClockOffset),
|
|
20
|
+
signingDate: noSkewCorrection ? new Date() : getSkewCorrectedDate(config.systemClockOffset),
|
|
16
21
|
signingRegion: multiRegionOverride,
|
|
17
22
|
signingService: signingName,
|
|
18
23
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpRequest } from "@smithy/core/protocols";
|
|
2
|
-
import { getDateHeader, getSkewCorrectedDate, getUpdatedSystemClockOffset } from "../utils";
|
|
2
|
+
import { getAgeHeader, getDateHeader, getSkewCorrectedDate, getUpdatedSystemClockOffset } from "../utils";
|
|
3
3
|
const throwSigningPropertyError = (name, property) => {
|
|
4
4
|
if (!property) {
|
|
5
5
|
throw new Error(`Property \`${name}\` is not resolved for AWS SDK SigV4Auth`);
|
|
@@ -39,9 +39,14 @@ export class AwsSdkSigV4Signer {
|
|
|
39
39
|
signingName = second?.signingName ?? signingName;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
const noSkewCorrection = (await config.disableClockSkewCorrection?.()) === true;
|
|
43
|
+
signingProperties._disableClockSkewCorrection = noSkewCorrection;
|
|
44
|
+
if (!noSkewCorrection) {
|
|
45
|
+
signingProperties._preRequestSystemClockOffset = config.systemClockOffset;
|
|
46
|
+
signingProperties._requestSentAt = Date.now();
|
|
47
|
+
}
|
|
43
48
|
const signedRequest = await signer.sign(httpRequest, {
|
|
44
|
-
signingDate: getSkewCorrectedDate(config.systemClockOffset),
|
|
49
|
+
signingDate: noSkewCorrection ? new Date() : getSkewCorrectedDate(config.systemClockOffset),
|
|
45
50
|
signingRegion: signingRegion,
|
|
46
51
|
signingService: signingName,
|
|
47
52
|
});
|
|
@@ -50,27 +55,36 @@ export class AwsSdkSigV4Signer {
|
|
|
50
55
|
errorHandler(signingProperties) {
|
|
51
56
|
return (error) => {
|
|
52
57
|
const errorException = error;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (clockSkewCorrected && errorException.$metadata) {
|
|
58
|
+
if (!signingProperties._disableClockSkewCorrection) {
|
|
59
|
+
const serverTime = errorException.ServerTime ?? getDateHeader(errorException.$response);
|
|
60
|
+
if (serverTime) {
|
|
61
|
+
const config = throwSigningPropertyError("config", signingProperties.config);
|
|
62
|
+
const preRequestOffset = signingProperties._preRequestSystemClockOffset;
|
|
63
|
+
const timeRequestSent = signingProperties._requestSentAt;
|
|
64
|
+
const ageHeader = getAgeHeader(errorException.$response);
|
|
65
|
+
const newOffset = getUpdatedSystemClockOffset(serverTime, config.systemClockOffset, timeRequestSent, ageHeader);
|
|
62
66
|
config.systemClockOffset = newOffset;
|
|
63
|
-
|
|
67
|
+
const skewExceedsThreshold = Math.abs(newOffset) >= 240_000;
|
|
68
|
+
const isLocalCorrection = newOffset !== preRequestOffset;
|
|
69
|
+
const isConcurrentCorrection = preRequestOffset !== undefined && preRequestOffset !== newOffset;
|
|
70
|
+
if (skewExceedsThreshold && (isLocalCorrection || isConcurrentCorrection) && errorException.$metadata) {
|
|
71
|
+
errorException.$metadata.clockSkewCorrected = true;
|
|
72
|
+
}
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
75
|
throw error;
|
|
67
76
|
};
|
|
68
77
|
}
|
|
69
78
|
successHandler(httpResponse, signingProperties) {
|
|
79
|
+
if (signingProperties._disableClockSkewCorrection) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
70
82
|
const dateHeader = getDateHeader(httpResponse);
|
|
71
83
|
if (dateHeader) {
|
|
72
84
|
const config = throwSigningPropertyError("config", signingProperties.config);
|
|
73
|
-
|
|
85
|
+
const timeRequestSent = signingProperties._requestSentAt;
|
|
86
|
+
const ageHeader = getAgeHeader(httpResponse);
|
|
87
|
+
config.systemClockOffset = getUpdatedSystemClockOffset(dateHeader, config.systemClockOffset, timeRequestSent, ageHeader);
|
|
74
88
|
}
|
|
75
89
|
}
|
|
76
90
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_DISABLE_CLOCK_SKEW_CORRECTION = false;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { booleanSelector, SelectorType } from "@smithy/core/config";
|
|
2
|
+
export const ENV_DISABLE_CLOCK_SKEW_CORRECTION = "AWS_DISABLE_CLOCK_SKEW_CORRECTION";
|
|
3
|
+
export const CONFIG_DISABLE_CLOCK_SKEW_CORRECTION = "disable_clock_skew_correction";
|
|
4
|
+
export const NODE_DISABLE_CLOCK_SKEW_CORRECTION_CONFIG_OPTIONS = {
|
|
5
|
+
environmentVariableSelector: (env) => booleanSelector(env, ENV_DISABLE_CLOCK_SKEW_CORRECTION, SelectorType.ENV),
|
|
6
|
+
configFileSelector: (profile) => booleanSelector(profile, CONFIG_DISABLE_CLOCK_SKEW_CORRECTION, SelectorType.CONFIG),
|
|
7
|
+
default: false,
|
|
8
|
+
};
|
|
@@ -2,4 +2,4 @@ export { AwsSdkSigV4Signer, AWSSDKSigV4Signer, validateSigningProperties } from
|
|
|
2
2
|
export { AwsSdkSigV4ASigner } from "./AwsSdkSigV4ASigner";
|
|
3
3
|
export { NODE_AUTH_SCHEME_PREFERENCE_OPTIONS } from "./NODE_AUTH_SCHEME_PREFERENCE_OPTIONS";
|
|
4
4
|
export { resolveAwsSdkSigV4AConfig, NODE_SIGV4A_CONFIG_OPTIONS } from "./resolveAwsSdkSigV4AConfig";
|
|
5
|
-
export {
|
|
5
|
+
export { bindResolveAwsSdkSigV4Config } from "./resolveAwsSdkSigV4Config";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setCredentialFeature } from "@aws-sdk/core/client";
|
|
2
2
|
import { doesIdentityRequireRefresh, isIdentityExpired, memoizeIdentityProvider, normalizeProvider, } from "@smithy/core";
|
|
3
3
|
import { SignatureV4 } from "@smithy/signature-v4";
|
|
4
|
-
export const
|
|
4
|
+
export const bindResolveAwsSdkSigV4Config = (defaultDisableClockSkewCorrection) => (config) => {
|
|
5
5
|
let inputCredentials = config.credentials;
|
|
6
6
|
let isUserSupplied = !!config.credentials;
|
|
7
7
|
let resolvedCredentials = undefined;
|
|
@@ -99,11 +99,11 @@ export const resolveAwsSdkSigV4Config = (config) => {
|
|
|
99
99
|
systemClockOffset,
|
|
100
100
|
signingEscapePath,
|
|
101
101
|
signer,
|
|
102
|
+
disableClockSkewCorrection: normalizeProvider(config.disableClockSkewCorrection ?? defaultDisableClockSkewCorrection),
|
|
102
103
|
});
|
|
103
104
|
return resolvedConfig;
|
|
104
105
|
};
|
|
105
|
-
|
|
106
|
-
function normalizeCredentialProvider(config, { credentials, credentialDefaultProvider, }) {
|
|
106
|
+
function normalizeCredentialProvider(config, { credentials, credentialDefaultProvider }) {
|
|
107
107
|
let credentialsProvider;
|
|
108
108
|
if (credentials) {
|
|
109
109
|
if (!credentials?.memoized) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const no = Symbol.for("node-only");
|
|
2
|
+
export { AwsSdkSigV4Signer, AWSSDKSigV4Signer, validateSigningProperties, AwsSdkSigV4ASigner, resolveAwsSdkSigV4AConfig, } from "./aws_sdk";
|
|
3
|
+
export { getBearerTokenEnvKey } from "./utils/getBearerTokenEnvKey";
|
|
4
|
+
export const NODE_AUTH_SCHEME_PREFERENCE_OPTIONS = no;
|
|
5
|
+
export const NODE_SIGV4A_CONFIG_OPTIONS = no;
|
|
6
|
+
import { bindResolveAwsSdkSigV4Config } from "./aws_sdk";
|
|
7
|
+
import { DEFAULT_DISABLE_CLOCK_SKEW_CORRECTION } from "./aws_sdk/clock-skew-defaults.browser";
|
|
8
|
+
export const resolveAwsSdkSigV4Config = bindResolveAwsSdkSigV4Config(DEFAULT_DISABLE_CLOCK_SKEW_CORRECTION);
|
|
9
|
+
export const resolveAWSSDKSigV4Config = resolveAwsSdkSigV4Config;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export { AwsSdkSigV4Signer, AWSSDKSigV4Signer, validateSigningProperties, AwsSdkSigV4ASigner, NODE_AUTH_SCHEME_PREFERENCE_OPTIONS, resolveAwsSdkSigV4AConfig, NODE_SIGV4A_CONFIG_OPTIONS,
|
|
1
|
+
export { AwsSdkSigV4Signer, AWSSDKSigV4Signer, validateSigningProperties, AwsSdkSigV4ASigner, NODE_AUTH_SCHEME_PREFERENCE_OPTIONS, resolveAwsSdkSigV4AConfig, NODE_SIGV4A_CONFIG_OPTIONS, } from "./aws_sdk";
|
|
2
2
|
export { getBearerTokenEnvKey } from "./utils/getBearerTokenEnvKey";
|
|
3
|
+
import { bindResolveAwsSdkSigV4Config } from "./aws_sdk";
|
|
4
|
+
import { DEFAULT_DISABLE_CLOCK_SKEW_CORRECTION } from "./aws_sdk/clock-skew-defaults";
|
|
5
|
+
export const resolveAwsSdkSigV4Config = bindResolveAwsSdkSigV4Config(DEFAULT_DISABLE_CLOCK_SKEW_CORRECTION);
|
|
6
|
+
export const resolveAWSSDKSigV4Config = resolveAwsSdkSigV4Config;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { HttpResponse } from "@smithy/core/protocols";
|
|
2
2
|
export const getDateHeader = (response) => HttpResponse.isInstance(response) ? (response.headers?.date ?? response.headers?.Date) : undefined;
|
|
3
|
+
export const getAgeHeader = (response) => HttpResponse.isInstance(response) ? (response.headers?.age ?? response.headers?.Age) : undefined;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (isClockSkewed(clockTimeInMs, currentSystemClockOffset)) {
|
|
5
|
-
return clockTimeInMs - Date.now();
|
|
1
|
+
export const getUpdatedSystemClockOffset = (clockTime, currentSystemClockOffset, timeRequestSent, ageHeader) => {
|
|
2
|
+
if (ageHeader !== undefined) {
|
|
3
|
+
return currentSystemClockOffset;
|
|
6
4
|
}
|
|
7
|
-
|
|
5
|
+
const serverTime = Date.parse(clockTime);
|
|
6
|
+
const timeResponseReceived = Date.now();
|
|
7
|
+
if (timeRequestSent !== undefined && timeResponseReceived - timeRequestSent > 900_000) {
|
|
8
|
+
return currentSystemClockOffset;
|
|
9
|
+
}
|
|
10
|
+
const candidateSkew = timeRequestSent !== undefined
|
|
11
|
+
? serverTime - (timeRequestSent + timeResponseReceived) / 2
|
|
12
|
+
: serverTime - timeResponseReceived;
|
|
13
|
+
return candidateSkew;
|
|
8
14
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { getDateHeader } from "./getDateHeader";
|
|
1
|
+
export { getAgeHeader, getDateHeader } from "./getDateHeader";
|
|
2
2
|
export { getSkewCorrectedDate } from "./getSkewCorrectedDate";
|
|
3
3
|
export { getUpdatedSystemClockOffset } from "./getUpdatedSystemClockOffset";
|
|
4
|
+
export { isClockSkewed } from "./isClockSkewed";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { getSkewCorrectedDate } from "./getSkewCorrectedDate";
|
|
2
|
-
export const isClockSkewed = (clockTime, systemClockOffset) => Math.abs(getSkewCorrectedDate(systemClockOffset).getTime() - clockTime) >=
|
|
2
|
+
export const isClockSkewed = (clockTime, systemClockOffset) => Math.abs(getSkewCorrectedDate(systemClockOffset).getTime() - clockTime) >= 240000;
|
|
@@ -5,7 +5,9 @@ import { fromBase64 } from "@smithy/core/serde";
|
|
|
5
5
|
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
|
6
6
|
import { UnionSerde } from "../UnionSerde";
|
|
7
7
|
import { jsonReviver } from "./jsonReviver";
|
|
8
|
+
import { needsReviver } from "./needsReviver";
|
|
8
9
|
import { parseJsonBody } from "./parseJsonBody";
|
|
10
|
+
import { writeKey } from "../writeKey";
|
|
9
11
|
export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
10
12
|
settings;
|
|
11
13
|
constructor(settings) {
|
|
@@ -13,7 +15,8 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
13
15
|
this.settings = settings;
|
|
14
16
|
}
|
|
15
17
|
async read(schema, data) {
|
|
16
|
-
|
|
18
|
+
const reviver = needsReviver(schema) ? jsonReviver : undefined;
|
|
19
|
+
return this._read(schema, typeof data === "string" ? JSON.parse(data, reviver) : await parseJsonBody(data, this.serdeContext, schema));
|
|
17
20
|
}
|
|
18
21
|
readObject(schema, data) {
|
|
19
22
|
return this._read(schema, data);
|
|
@@ -74,6 +77,9 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
74
77
|
const mapMember = ns.getValueSchema();
|
|
75
78
|
const out = {};
|
|
76
79
|
for (const _k in value) {
|
|
80
|
+
if (_k === "__proto__") {
|
|
81
|
+
writeKey(out);
|
|
82
|
+
}
|
|
77
83
|
out[_k] = this._read(mapMember, value[_k]);
|
|
78
84
|
}
|
|
79
85
|
return out;
|
|
@@ -132,6 +138,9 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
132
138
|
if (isObject) {
|
|
133
139
|
const out = Array.isArray(value) ? [] : {};
|
|
134
140
|
for (const k in value) {
|
|
141
|
+
if (k === "__proto__") {
|
|
142
|
+
writeKey(out);
|
|
143
|
+
}
|
|
135
144
|
const v = value[k];
|
|
136
145
|
if (v instanceof NumericValue) {
|
|
137
146
|
out[k] = v;
|
|
@@ -3,6 +3,7 @@ import { NormalizedSchema } from "@smithy/core/schema";
|
|
|
3
3
|
import { dateToUtcString, generateIdempotencyToken, LazyJsonString, NumericValue, toBase64 } from "@smithy/core/serde";
|
|
4
4
|
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
|
5
5
|
import { JsonReplacer } from "./jsonReplacer";
|
|
6
|
+
import { writeKey } from "../writeKey";
|
|
6
7
|
export class JsonShapeSerializer extends SerdeContextConfig {
|
|
7
8
|
settings;
|
|
8
9
|
buffer;
|
|
@@ -64,6 +65,9 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
64
65
|
const { $unknown } = record;
|
|
65
66
|
if (Array.isArray($unknown)) {
|
|
66
67
|
const [k, v] = $unknown;
|
|
68
|
+
if (k === "__proto__") {
|
|
69
|
+
writeKey(out);
|
|
70
|
+
}
|
|
67
71
|
out[k] = this._write(15, v);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
@@ -96,6 +100,9 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
96
100
|
for (const _k in value) {
|
|
97
101
|
const _v = value[_k];
|
|
98
102
|
if (sparse || _v != null) {
|
|
103
|
+
if (_k === "__proto__") {
|
|
104
|
+
writeKey(out);
|
|
105
|
+
}
|
|
99
106
|
out[_k] = this._write(mapMember, _v);
|
|
100
107
|
}
|
|
101
108
|
}
|
|
@@ -161,6 +168,9 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
161
168
|
const out = Array.isArray(value) ? [] : {};
|
|
162
169
|
for (const k in value) {
|
|
163
170
|
const v = value[k];
|
|
171
|
+
if (k === "__proto__") {
|
|
172
|
+
writeKey(out);
|
|
173
|
+
}
|
|
164
174
|
if (v instanceof NumericValue) {
|
|
165
175
|
this.useReplacer = true;
|
|
166
176
|
out[k] = v;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
let canParseBuffer;
|
|
2
|
+
export function detectBufferParsing() {
|
|
3
|
+
if (canParseBuffer === undefined) {
|
|
4
|
+
try {
|
|
5
|
+
if (typeof Buffer !== "function") {
|
|
6
|
+
canParseBuffer = false;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const result = JSON.parse(Buffer.from([0x7b, 0x7d]));
|
|
10
|
+
canParseBuffer = result !== null && typeof result === "object";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
canParseBuffer = false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return canParseBuffer;
|
|
18
|
+
}
|