@smithy/core 3.36.0 → 3.36.2
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/CHANGELOG.md +13 -0
- package/dist-cjs/submodules/client/index.js +15 -2
- package/dist-cjs/submodules/event-streams/index.browser.js +10 -0
- package/dist-cjs/submodules/event-streams/index.js +10 -0
- package/dist-cjs/submodules/protocols/index.js +5 -5
- package/dist-es/submodules/client/smithy-client/command.js +16 -2
- package/dist-es/submodules/event-streams/eventstream-codec/HeaderMarshaller.js +10 -0
- package/dist-es/submodules/protocols/json/codec-v2/JsonShapeSerializer2.js +5 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.36.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 76726da: Add event stream header size validations
|
|
8
|
+
- 50f64b9: cache schema-based detection of event streams
|
|
9
|
+
|
|
10
|
+
## 3.36.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- dbdacac: Keep the JSON string serializer's buffer reservation intact after 6-byte escape sequences so that the characters and closing quote that follow are always written within the buffer.
|
|
15
|
+
|
|
3
16
|
## 3.36.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -578,6 +578,7 @@ function schemaLogFilter(schema, data) {
|
|
|
578
578
|
return data;
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
+
const operationEventStreamMarker = Symbol.for("@smithy/op-event-stream");
|
|
581
582
|
class Command {
|
|
582
583
|
middlewareStack = constructStack();
|
|
583
584
|
schema;
|
|
@@ -611,9 +612,21 @@ class Command {
|
|
|
611
612
|
requestOptions = { ...requestOptions };
|
|
612
613
|
delete requestOptions.metricsRecorder;
|
|
613
614
|
}
|
|
614
|
-
|
|
615
|
+
let isEventStream;
|
|
616
|
+
const schema = this.schema;
|
|
617
|
+
const marker = schema?.[operationEventStreamMarker];
|
|
618
|
+
if (marker !== undefined) {
|
|
619
|
+
isEventStream = marker;
|
|
620
|
+
}
|
|
621
|
+
else if (schema) {
|
|
622
|
+
if (Array.isArray(schema) && schema[0] === 9) {
|
|
623
|
+
const [, , , , input$, output$] = schema;
|
|
624
|
+
isEventStream = schema[operationEventStreamMarker] = Boolean(NormalizedSchema.of(input$).getEventStreamMember() || NormalizedSchema.of(output$).getEventStreamMember());
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (isEventStream) {
|
|
615
628
|
requestOptions = {
|
|
616
|
-
isEventStream
|
|
629
|
+
isEventStream,
|
|
617
630
|
...requestOptions,
|
|
618
631
|
};
|
|
619
632
|
}
|
|
@@ -60,6 +60,9 @@ class HeaderMarshaller {
|
|
|
60
60
|
if (!hasOwn(headers, headerName))
|
|
61
61
|
continue;
|
|
62
62
|
const bytes = this.fromUtf8(headerName);
|
|
63
|
+
if (bytes.byteLength > 255) {
|
|
64
|
+
throw new Error(`@smithy/core/event-streams - header name exceeds 255 bytes: ${bytes.byteLength}`);
|
|
65
|
+
}
|
|
63
66
|
chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
|
|
64
67
|
}
|
|
65
68
|
const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
|
|
@@ -92,6 +95,9 @@ class HeaderMarshaller {
|
|
|
92
95
|
longBytes.set(header.value.bytes, 1);
|
|
93
96
|
return longBytes;
|
|
94
97
|
case "binary":
|
|
98
|
+
if (header.value.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
99
|
+
throw new Error(`@smithy/core/event-streams - header value (binary) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${header.value.byteLength}`);
|
|
100
|
+
}
|
|
95
101
|
const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
|
|
96
102
|
binView.setUint8(0, 6);
|
|
97
103
|
binView.setUint16(1, header.value.byteLength, false);
|
|
@@ -100,6 +106,9 @@ class HeaderMarshaller {
|
|
|
100
106
|
return binBytes;
|
|
101
107
|
case "string":
|
|
102
108
|
const utf8Bytes = this.fromUtf8(header.value);
|
|
109
|
+
if (utf8Bytes.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
110
|
+
throw new Error(`@smithy/core/event-streams - header value (string) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${utf8Bytes.byteLength}`);
|
|
111
|
+
}
|
|
103
112
|
const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
|
|
104
113
|
strView.setUint8(0, 7);
|
|
105
114
|
strView.setUint16(1, utf8Bytes.byteLength, false);
|
|
@@ -231,6 +240,7 @@ const STRING_TAG = "string";
|
|
|
231
240
|
const TIMESTAMP_TAG = "timestamp";
|
|
232
241
|
const UUID_TAG = "uuid";
|
|
233
242
|
const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
243
|
+
const MAX_HEADER_VALUE_BYTES = 32767;
|
|
234
244
|
|
|
235
245
|
const PRELUDE_MEMBER_LENGTH = 4;
|
|
236
246
|
const PRELUDE_LENGTH = PRELUDE_MEMBER_LENGTH * 2;
|
|
@@ -61,6 +61,9 @@ class HeaderMarshaller {
|
|
|
61
61
|
if (!hasOwn(headers, headerName))
|
|
62
62
|
continue;
|
|
63
63
|
const bytes = this.fromUtf8(headerName);
|
|
64
|
+
if (bytes.byteLength > 255) {
|
|
65
|
+
throw new Error(`@smithy/core/event-streams - header name exceeds 255 bytes: ${bytes.byteLength}`);
|
|
66
|
+
}
|
|
64
67
|
chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
|
|
65
68
|
}
|
|
66
69
|
const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
|
|
@@ -93,6 +96,9 @@ class HeaderMarshaller {
|
|
|
93
96
|
longBytes.set(header.value.bytes, 1);
|
|
94
97
|
return longBytes;
|
|
95
98
|
case "binary":
|
|
99
|
+
if (header.value.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
100
|
+
throw new Error(`@smithy/core/event-streams - header value (binary) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${header.value.byteLength}`);
|
|
101
|
+
}
|
|
96
102
|
const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
|
|
97
103
|
binView.setUint8(0, 6);
|
|
98
104
|
binView.setUint16(1, header.value.byteLength, false);
|
|
@@ -101,6 +107,9 @@ class HeaderMarshaller {
|
|
|
101
107
|
return binBytes;
|
|
102
108
|
case "string":
|
|
103
109
|
const utf8Bytes = this.fromUtf8(header.value);
|
|
110
|
+
if (utf8Bytes.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
111
|
+
throw new Error(`@smithy/core/event-streams - header value (string) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${utf8Bytes.byteLength}`);
|
|
112
|
+
}
|
|
104
113
|
const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
|
|
105
114
|
strView.setUint8(0, 7);
|
|
106
115
|
strView.setUint16(1, utf8Bytes.byteLength, false);
|
|
@@ -232,6 +241,7 @@ const STRING_TAG = "string";
|
|
|
232
241
|
const TIMESTAMP_TAG = "timestamp";
|
|
233
242
|
const UUID_TAG = "uuid";
|
|
234
243
|
const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
244
|
+
const MAX_HEADER_VALUE_BYTES = 32767;
|
|
235
245
|
|
|
236
246
|
const PRELUDE_MEMBER_LENGTH = 4;
|
|
237
247
|
const PRELUDE_LENGTH = PRELUDE_MEMBER_LENGTH * 2;
|
|
@@ -1812,9 +1812,9 @@ class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
1812
1812
|
this.i = i;
|
|
1813
1813
|
}
|
|
1814
1814
|
writeJsonString(s) {
|
|
1815
|
-
this.ensure(s.length * 3 + 2);
|
|
1816
|
-
this.json[this.i++] = QUOTE;
|
|
1817
1815
|
const z = s.length;
|
|
1816
|
+
this.ensure(z * 3 + 2);
|
|
1817
|
+
this.json[this.i++] = QUOTE;
|
|
1818
1818
|
for (let j = 0; j < z; ++j) {
|
|
1819
1819
|
const c = s.charCodeAt(j);
|
|
1820
1820
|
if (c > 0x22 && c < 0x5c) {
|
|
@@ -1823,7 +1823,7 @@ class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
1823
1823
|
else if (c < 0x80) {
|
|
1824
1824
|
const esc = ESCAPE_TABLE[c];
|
|
1825
1825
|
if (esc !== null) {
|
|
1826
|
-
this.ensure(esc.length + 1);
|
|
1826
|
+
this.ensure(esc.length + 1 + (z - j - 1) * 3 + 1);
|
|
1827
1827
|
this.json[this.i++] = BACKSLASH;
|
|
1828
1828
|
for (let k = 0; k < esc.length; k++) {
|
|
1829
1829
|
this.json[this.i++] = esc.charCodeAt(k);
|
|
@@ -1842,12 +1842,12 @@ class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
1842
1842
|
++j;
|
|
1843
1843
|
}
|
|
1844
1844
|
else {
|
|
1845
|
-
this.ensure(6);
|
|
1845
|
+
this.ensure(6 + (z - j - 1) * 3 + 1);
|
|
1846
1846
|
this.writeUnicodeEscape(c);
|
|
1847
1847
|
}
|
|
1848
1848
|
}
|
|
1849
1849
|
else if (c >= 0xdc00 && c <= 0xdfff) {
|
|
1850
|
-
this.ensure(6);
|
|
1850
|
+
this.ensure(6 + (z - j - 1) * 3 + 1);
|
|
1851
1851
|
this.writeUnicodeEscape(c);
|
|
1852
1852
|
}
|
|
1853
1853
|
else {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SMITHY_CONTEXT_KEY, } from "@smithy/types";
|
|
2
2
|
import { constructStack } from "../middleware-stack/MiddlewareStack";
|
|
3
3
|
import { schemaLogFilter } from "./schemaLogFilter";
|
|
4
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
5
|
+
const operationEventStreamMarker = Symbol.for("@smithy/op-event-stream");
|
|
4
6
|
export class Command {
|
|
5
7
|
middlewareStack = constructStack();
|
|
6
8
|
schema;
|
|
@@ -34,9 +36,21 @@ export class Command {
|
|
|
34
36
|
requestOptions = { ...requestOptions };
|
|
35
37
|
delete requestOptions.metricsRecorder;
|
|
36
38
|
}
|
|
37
|
-
|
|
39
|
+
let isEventStream;
|
|
40
|
+
const schema = this.schema;
|
|
41
|
+
const marker = schema?.[operationEventStreamMarker];
|
|
42
|
+
if (marker !== undefined) {
|
|
43
|
+
isEventStream = marker;
|
|
44
|
+
}
|
|
45
|
+
else if (schema) {
|
|
46
|
+
if (Array.isArray(schema) && schema[0] === 9) {
|
|
47
|
+
const [, , , , input$, output$] = schema;
|
|
48
|
+
isEventStream = schema[operationEventStreamMarker] = Boolean(NormalizedSchema.of(input$).getEventStreamMember() || NormalizedSchema.of(output$).getEventStreamMember());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (isEventStream) {
|
|
38
52
|
requestOptions = {
|
|
39
|
-
isEventStream
|
|
53
|
+
isEventStream,
|
|
40
54
|
...requestOptions,
|
|
41
55
|
};
|
|
42
56
|
}
|
|
@@ -14,6 +14,9 @@ export class HeaderMarshaller {
|
|
|
14
14
|
if (!hasOwn(headers, headerName))
|
|
15
15
|
continue;
|
|
16
16
|
const bytes = this.fromUtf8(headerName);
|
|
17
|
+
if (bytes.byteLength > 255) {
|
|
18
|
+
throw new Error(`@smithy/core/event-streams - header name exceeds 255 bytes: ${bytes.byteLength}`);
|
|
19
|
+
}
|
|
17
20
|
chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
|
|
18
21
|
}
|
|
19
22
|
const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
|
|
@@ -46,6 +49,9 @@ export class HeaderMarshaller {
|
|
|
46
49
|
longBytes.set(header.value.bytes, 1);
|
|
47
50
|
return longBytes;
|
|
48
51
|
case "binary":
|
|
52
|
+
if (header.value.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
53
|
+
throw new Error(`@smithy/core/event-streams - header value (binary) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${header.value.byteLength}`);
|
|
54
|
+
}
|
|
49
55
|
const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
|
|
50
56
|
binView.setUint8(0, 6);
|
|
51
57
|
binView.setUint16(1, header.value.byteLength, false);
|
|
@@ -54,6 +60,9 @@ export class HeaderMarshaller {
|
|
|
54
60
|
return binBytes;
|
|
55
61
|
case "string":
|
|
56
62
|
const utf8Bytes = this.fromUtf8(header.value);
|
|
63
|
+
if (utf8Bytes.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
64
|
+
throw new Error(`@smithy/core/event-streams - header value (string) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${utf8Bytes.byteLength}`);
|
|
65
|
+
}
|
|
57
66
|
const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
|
|
58
67
|
strView.setUint8(0, 7);
|
|
59
68
|
strView.setUint16(1, utf8Bytes.byteLength, false);
|
|
@@ -185,3 +194,4 @@ const STRING_TAG = "string";
|
|
|
185
194
|
const TIMESTAMP_TAG = "timestamp";
|
|
186
195
|
const UUID_TAG = "uuid";
|
|
187
196
|
const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
197
|
+
const MAX_HEADER_VALUE_BYTES = 32767;
|
|
@@ -118,9 +118,9 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
118
118
|
this.i = i;
|
|
119
119
|
}
|
|
120
120
|
writeJsonString(s) {
|
|
121
|
-
this.ensure(s.length * 3 + 2);
|
|
122
|
-
this.json[this.i++] = QUOTE;
|
|
123
121
|
const z = s.length;
|
|
122
|
+
this.ensure(z * 3 + 2);
|
|
123
|
+
this.json[this.i++] = QUOTE;
|
|
124
124
|
for (let j = 0; j < z; ++j) {
|
|
125
125
|
const c = s.charCodeAt(j);
|
|
126
126
|
if (c > 0x22 && c < 0x5c) {
|
|
@@ -129,7 +129,7 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
129
129
|
else if (c < 0x80) {
|
|
130
130
|
const esc = ESCAPE_TABLE[c];
|
|
131
131
|
if (esc !== null) {
|
|
132
|
-
this.ensure(esc.length + 1);
|
|
132
|
+
this.ensure(esc.length + 1 + (z - j - 1) * 3 + 1);
|
|
133
133
|
this.json[this.i++] = BACKSLASH;
|
|
134
134
|
for (let k = 0; k < esc.length; k++) {
|
|
135
135
|
this.json[this.i++] = esc.charCodeAt(k);
|
|
@@ -148,12 +148,12 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
148
148
|
++j;
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
151
|
-
this.ensure(6);
|
|
151
|
+
this.ensure(6 + (z - j - 1) * 3 + 1);
|
|
152
152
|
this.writeUnicodeEscape(c);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
else if (c >= 0xdc00 && c <= 0xdfff) {
|
|
156
|
-
this.ensure(6);
|
|
156
|
+
this.ensure(6 + (z - j - 1) * 3 + 1);
|
|
157
157
|
this.writeUnicodeEscape(c);
|
|
158
158
|
}
|
|
159
159
|
else {
|