@fluidframework/debugger 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.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.
Files changed (39) hide show
  1. package/.eslintrc.js +9 -12
  2. package/README.md +33 -33
  3. package/api-extractor.json +2 -2
  4. package/dist/fluidDebugger.d.ts.map +1 -1
  5. package/dist/fluidDebugger.js.map +1 -1
  6. package/dist/fluidDebuggerController.d.ts.map +1 -1
  7. package/dist/fluidDebuggerController.js +5 -2
  8. package/dist/fluidDebuggerController.js.map +1 -1
  9. package/dist/fluidDebuggerUi.d.ts.map +1 -1
  10. package/dist/fluidDebuggerUi.js +11 -5
  11. package/dist/fluidDebuggerUi.js.map +1 -1
  12. package/dist/messageSchema.js.map +1 -1
  13. package/dist/sanitize.js.map +1 -1
  14. package/dist/sanitizer.d.ts.map +1 -1
  15. package/dist/sanitizer.js +9 -5
  16. package/dist/sanitizer.js.map +1 -1
  17. package/lib/fluidDebugger.d.ts.map +1 -1
  18. package/lib/fluidDebugger.js.map +1 -1
  19. package/lib/fluidDebuggerController.d.ts.map +1 -1
  20. package/lib/fluidDebuggerController.js +5 -2
  21. package/lib/fluidDebuggerController.js.map +1 -1
  22. package/lib/fluidDebuggerUi.d.ts.map +1 -1
  23. package/lib/fluidDebuggerUi.js +11 -5
  24. package/lib/fluidDebuggerUi.js.map +1 -1
  25. package/lib/messageSchema.js.map +1 -1
  26. package/lib/sanitize.js.map +1 -1
  27. package/lib/sanitizer.d.ts.map +1 -1
  28. package/lib/sanitizer.js +9 -5
  29. package/lib/sanitizer.js.map +1 -1
  30. package/package.json +33 -32
  31. package/prettier.config.cjs +1 -1
  32. package/src/fluidDebugger.ts +30 -30
  33. package/src/fluidDebuggerController.ts +348 -322
  34. package/src/fluidDebuggerUi.ts +306 -281
  35. package/src/messageSchema.ts +367 -367
  36. package/src/sanitize.ts +29 -29
  37. package/src/sanitizer.ts +699 -638
  38. package/tsconfig.esnext.json +6 -6
  39. package/tsconfig.json +10 -15
package/src/sanitizer.ts CHANGED
@@ -20,35 +20,35 @@
20
20
 
21
21
  import * as Validator from "jsonschema";
22
22
  import { assert } from "@fluidframework/common-utils";
23
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
23
24
  import {
24
- ISequencedDocumentMessage,
25
- } from "@fluidframework/protocol-definitions";
26
- import {
27
- attachContentsSchema,
28
- chunkedOpContentsSchema,
29
- joinContentsSchema,
30
- joinDataSchema,
31
- opContentsMapSchema,
32
- opContentsSchema,
33
- opContentsMergeTreeDeltaOpSchema,
34
- opContentsMergeTreeGroupOpSchema,
35
- opContentsRegisterCollectionSchema,
36
- proposeContentsSchema,
25
+ attachContentsSchema,
26
+ chunkedOpContentsSchema,
27
+ joinContentsSchema,
28
+ joinDataSchema,
29
+ opContentsMapSchema,
30
+ opContentsSchema,
31
+ opContentsMergeTreeDeltaOpSchema,
32
+ opContentsMergeTreeGroupOpSchema,
33
+ opContentsRegisterCollectionSchema,
34
+ proposeContentsSchema,
37
35
  } from "./messageSchema";
38
36
 
39
37
  enum TextType {
40
- Generic,
41
- Email,
42
- Name,
43
- FluidObject,
44
- MapKey,
38
+ Generic,
39
+ Email,
40
+ Name,
41
+ FluidObject,
42
+ MapKey,
45
43
  }
46
44
 
47
45
  // Workaround to jsonschema package not supporting "false" as a schema
48
46
  // that matches nothing
49
47
  const falseResult = {
50
- valid: false,
51
- toString: () => { return "Unmatched format"; },
48
+ valid: false,
49
+ toString: () => {
50
+ return "Unmatched format";
51
+ },
52
52
  };
53
53
 
54
54
  /**
@@ -58,625 +58,686 @@ const falseResult = {
58
58
  * size to the original message.
59
59
  */
60
60
  class ChunkedOpProcessor {
61
- /**
62
- * Message references so we can replace their contents in-place. These can
63
- * be top-level chunkedOp messages, or top-level op messages with a chunkedOp
64
- * within the contents
65
- */
66
- private messages = new Array<any>();
67
- /**
68
- * The messages' parsed contents for processing. Should parallel the
69
- * messages member
70
- */
71
- private parsedMessageContents = new Array<any>();
72
- private writtenBack = false;
73
- /**
74
- * keep track of the total starting length to make sure we don't somehow end
75
- * up with more content than we started with (meaning we may not be able to
76
- * write it back)
77
- */
78
- private concatenatedLength = 0;
79
-
80
- constructor(
81
- readonly validateSchemaFn: (object: any, schema: any) => boolean,
82
- readonly debug: boolean,
83
- ) { }
84
-
85
- debugMsg(msg: any) {
86
- if (this.debug) {
87
- console.error(msg);
88
- }
89
- }
90
-
91
- addMessage(message: any): void {
92
- this.messages.push(message);
93
-
94
- let parsed;
95
- try {
96
- parsed = JSON.parse(message.contents);
97
- if (message.type === "op") {
98
- // nested within a regular op
99
- // need to go deeper to get the desired contents
100
- parsed = parsed.contents;
101
- }
102
- } catch (e) {
103
- this.debugMsg(e);
104
- this.debugMsg(message.contents);
105
- }
106
- this.validateSchemaFn(parsed, chunkedOpContentsSchema);
107
- this.parsedMessageContents.push(parsed);
108
- }
109
-
110
- hasAllMessages(): boolean {
111
- const lastMsgContents = this.parsedMessageContents[this.parsedMessageContents.length - 1];
112
- return lastMsgContents.chunkId !== undefined && lastMsgContents.chunkId === lastMsgContents.totalChunks;
113
- }
114
-
115
- /**
116
- * @returns The concatenated contents of all the messages parsed as json
117
- */
118
- getConcatenatedContents(): any {
119
- const contentsString = this.parsedMessageContents.reduce((previousValue: string, currentValue: any) => {
120
- return previousValue + (currentValue.contents as string);
121
- }, "");
122
-
123
- this.concatenatedLength = contentsString.length;
124
- try {
125
- return JSON.parse(contentsString);
126
- } catch (e) {
127
- this.debugMsg(contentsString);
128
- this.debugMsg(e);
129
- return undefined;
130
- }
131
- }
132
-
133
- /**
134
- * Write back sanitized contents into the messages. The contents are
135
- * stringified, split up, and written in place to the messages that
136
- * were added earlier. The number of messages is preserved.
137
- * @param contents - Sanitized contents to write back
138
- */
139
- writeSanitizedContents(contents: any): void {
140
- // Write back a chunk size equal to the original
141
- const chunkSize = this.parsedMessageContents[0].contents.length;
142
-
143
- let stringified: string;
144
- try {
145
- stringified = JSON.stringify(contents);
146
- assert(stringified.length <= this.concatenatedLength,
147
- 0x089 /* "Stringified length of chunk contents > total starting length" */);
148
- } catch (e) {
149
- this.debugMsg(e);
150
- throw e;
151
- }
152
-
153
- for (let i = 0; i < this.messages.length; i++) {
154
- const substring = stringified.substring(i * chunkSize, (i + 1) * chunkSize);
155
-
156
- const parsedContents = this.parsedMessageContents[i];
157
- parsedContents.contents = substring;
158
- const message = this.messages[i];
159
-
160
- let stringifiedParsedContents;
161
- try {
162
- // for nested chunkedOps, we need to recreate the extra nesting layer
163
- // we removed earlier when adding the message
164
- if (message.type === "op") {
165
- const nestingLayer = {
166
- type: "chunkedOp",
167
- contents: parsedContents,
168
- };
169
- stringifiedParsedContents = JSON.stringify(nestingLayer);
170
- } else {
171
- stringifiedParsedContents = JSON.stringify(parsedContents);
172
- }
173
- } catch (e) {
174
- this.debugMsg(e);
175
- }
176
-
177
- message.contents = stringifiedParsedContents;
178
- }
179
-
180
- this.writtenBack = true;
181
- }
182
-
183
- reset(): void {
184
- assert(this.writtenBack, 0x08a /* "resetting ChunkedOpProcessor that never wrote back its contents" */);
185
- this.messages = new Array<any>();
186
- this.parsedMessageContents = new Array<any>();
187
- this.writtenBack = false;
188
- this.concatenatedLength = 0;
189
- }
190
-
191
- isPendingProcessing(): boolean {
192
- return this.messages.length !== 0;
193
- }
61
+ /**
62
+ * Message references so we can replace their contents in-place. These can
63
+ * be top-level chunkedOp messages, or top-level op messages with a chunkedOp
64
+ * within the contents
65
+ */
66
+ private messages = new Array<any>();
67
+ /**
68
+ * The messages' parsed contents for processing. Should parallel the
69
+ * messages member
70
+ */
71
+ private parsedMessageContents = new Array<any>();
72
+ private writtenBack = false;
73
+ /**
74
+ * keep track of the total starting length to make sure we don't somehow end
75
+ * up with more content than we started with (meaning we may not be able to
76
+ * write it back)
77
+ */
78
+ private concatenatedLength = 0;
79
+
80
+ constructor(
81
+ readonly validateSchemaFn: (object: any, schema: any) => boolean,
82
+ readonly debug: boolean,
83
+ ) {}
84
+
85
+ debugMsg(msg: any) {
86
+ if (this.debug) {
87
+ console.error(msg);
88
+ }
89
+ }
90
+
91
+ addMessage(message: any): void {
92
+ this.messages.push(message);
93
+
94
+ let parsed;
95
+ try {
96
+ parsed = JSON.parse(message.contents);
97
+ if (message.type === "op") {
98
+ // nested within a regular op
99
+ // need to go deeper to get the desired contents
100
+ parsed = parsed.contents;
101
+ }
102
+ } catch (e) {
103
+ this.debugMsg(e);
104
+ this.debugMsg(message.contents);
105
+ }
106
+ this.validateSchemaFn(parsed, chunkedOpContentsSchema);
107
+ this.parsedMessageContents.push(parsed);
108
+ }
109
+
110
+ hasAllMessages(): boolean {
111
+ const lastMsgContents = this.parsedMessageContents[this.parsedMessageContents.length - 1];
112
+ return (
113
+ lastMsgContents.chunkId !== undefined &&
114
+ lastMsgContents.chunkId === lastMsgContents.totalChunks
115
+ );
116
+ }
117
+
118
+ /**
119
+ * @returns The concatenated contents of all the messages parsed as json
120
+ */
121
+ getConcatenatedContents(): any {
122
+ const contentsString = this.parsedMessageContents.reduce(
123
+ (previousValue: string, currentValue: any) => {
124
+ return previousValue + (currentValue.contents as string);
125
+ },
126
+ "",
127
+ );
128
+
129
+ this.concatenatedLength = contentsString.length;
130
+ try {
131
+ return JSON.parse(contentsString);
132
+ } catch (e) {
133
+ this.debugMsg(contentsString);
134
+ this.debugMsg(e);
135
+ return undefined;
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Write back sanitized contents into the messages. The contents are
141
+ * stringified, split up, and written in place to the messages that
142
+ * were added earlier. The number of messages is preserved.
143
+ * @param contents - Sanitized contents to write back
144
+ */
145
+ writeSanitizedContents(contents: any): void {
146
+ // Write back a chunk size equal to the original
147
+ const chunkSize = this.parsedMessageContents[0].contents.length;
148
+
149
+ let stringified: string;
150
+ try {
151
+ stringified = JSON.stringify(contents);
152
+ assert(
153
+ stringified.length <= this.concatenatedLength,
154
+ 0x089 /* "Stringified length of chunk contents > total starting length" */,
155
+ );
156
+ } catch (e) {
157
+ this.debugMsg(e);
158
+ throw e;
159
+ }
160
+
161
+ for (let i = 0; i < this.messages.length; i++) {
162
+ const substring = stringified.substring(i * chunkSize, (i + 1) * chunkSize);
163
+
164
+ const parsedContents = this.parsedMessageContents[i];
165
+ parsedContents.contents = substring;
166
+ const message = this.messages[i];
167
+
168
+ let stringifiedParsedContents;
169
+ try {
170
+ // for nested chunkedOps, we need to recreate the extra nesting layer
171
+ // we removed earlier when adding the message
172
+ if (message.type === "op") {
173
+ const nestingLayer = {
174
+ type: "chunkedOp",
175
+ contents: parsedContents,
176
+ };
177
+ stringifiedParsedContents = JSON.stringify(nestingLayer);
178
+ } else {
179
+ stringifiedParsedContents = JSON.stringify(parsedContents);
180
+ }
181
+ } catch (e) {
182
+ this.debugMsg(e);
183
+ }
184
+
185
+ message.contents = stringifiedParsedContents;
186
+ }
187
+
188
+ this.writtenBack = true;
189
+ }
190
+
191
+ reset(): void {
192
+ assert(
193
+ this.writtenBack,
194
+ 0x08a /* "resetting ChunkedOpProcessor that never wrote back its contents" */,
195
+ );
196
+ this.messages = new Array<any>();
197
+ this.parsedMessageContents = new Array<any>();
198
+ this.writtenBack = false;
199
+ this.concatenatedLength = 0;
200
+ }
201
+
202
+ isPendingProcessing(): boolean {
203
+ return this.messages.length !== 0;
204
+ }
194
205
  }
195
206
 
196
207
  export class Sanitizer {
197
- readonly validator = new Validator.Validator();
198
- // Represents the keys used to store Fluid object identifiers, snapshot info,
199
- // and other string fields that should not be replaced in contents blobs to
200
- // ensure the messages are still usable
201
- readonly defaultExcludedKeys = new Set<string>();
202
- // Represents the keys used by merge-tree ops their "seg" property, where other
203
- // keys represent user information
204
- readonly mergeTreeExcludedKeys = new Set<string>();
205
- // Map of user information to what it was replaced with. Used to ensure the same
206
- // data have the same replacements
207
- readonly replacementMap = new Map<string, string>();
208
-
209
- /**
210
- * Validate that the provided message matches the provided schema.
211
- * For a full scrub, warn and continue (scrubber should fully sanitize unexpected
212
- * fields for ops), otherwise throw an error because we cannot be sure user
213
- * information is being sufficiently sanitized.
214
- */
215
- objectMatchesSchema = (object: any, schema: any): boolean => {
216
- const result = schema === false ? falseResult : this.validator.validate(object, schema);
217
- if (!result.valid) {
218
- const errorMsg = `Bad msg fmt:\n${result.toString()}\n${JSON.stringify(object, undefined, 2)}`;
219
-
220
- if (this.fullScrub || this.noBail) {
221
- this.debugMsg(errorMsg);
222
- } else {
223
- throw new Error(errorMsg);
224
- }
225
- }
226
- return result.valid;
227
- };
228
-
229
- readonly chunkProcessor = new ChunkedOpProcessor(this.objectMatchesSchema, this.debug);
230
-
231
- constructor(
232
- readonly messages: ISequencedDocumentMessage[],
233
- readonly fullScrub: boolean,
234
- readonly noBail: boolean,
235
- readonly debug: boolean = false,
236
- ) {
237
- this.defaultExcludedKeys.add("type");
238
- this.defaultExcludedKeys.add("id");
239
- this.defaultExcludedKeys.add("pkg");
240
- this.defaultExcludedKeys.add("snapshotFormatVersion");
241
- this.defaultExcludedKeys.add("packageVersion");
242
- this.mergeTreeExcludedKeys.add("nodeType");
243
- }
244
-
245
- debugMsg(msg: any) {
246
- if (this.debug) {
247
- console.error(msg);
248
- }
249
- }
250
-
251
- isFluidObjectKey(key: string): boolean {
252
- return key === "type" || key === "id";
253
- }
254
-
255
- getRandomText(len: number): string {
256
- let str = "";
257
- while (str.length < len) {
258
- str = str + Math.random().toString(36).substring(2);
259
- }
260
- return str.substr(0, len);
261
- }
262
-
263
- readonly wordTokenRegex = /\S+/g;
264
-
265
- readonly replaceRandomTextFn = (match: string): string => {
266
- if (this.replacementMap.has(match)) {
267
- return this.replacementMap.get(match)!;
268
- }
269
-
270
- const replacement = this.getRandomText(match.length);
271
- this.replacementMap.set(match, replacement);
272
- return replacement;
273
- };
274
-
275
- /**
276
- * Replace text with garbage. FluidObject types are not replaced when not under
277
- * full scrub mode. All other text is replaced consistently.
278
- */
279
- replaceText(input?: string, type: TextType = TextType.Generic): string | undefined {
280
- if (input === undefined) {
281
- return undefined;
282
- }
283
-
284
- if (type === TextType.FluidObject) {
285
- if (this.replacementMap.has(input)) {
286
- return this.replacementMap.get(input)!;
287
- }
288
-
289
- const replacement = this.fullScrub ? this.getRandomText(input.length) : input;
290
-
291
- this.replacementMap.set(input, replacement);
292
- return replacement;
293
- }
294
-
295
- return input.replace(this.wordTokenRegex, this.replaceRandomTextFn);
296
- }
297
-
298
- replaceArray(input: any[]): any[] {
299
- for (let i = 0; i < input.length; i++) {
300
- const value = input[i];
301
- if (typeof value === "string") {
302
- input[i] = this.replaceText(value);
303
- } else if (Array.isArray(value)) {
304
- input[i] = this.replaceArray(value);
305
- } else if (typeof value === "object") {
306
- input[i] = this.replaceObject(value);
307
- }
308
- }
309
- return input;
310
- }
311
-
312
- /**
313
- * (sort of) recurses down the values of a JSON object to sanitize all its strings
314
- * (only checks strings, arrays, and objects)
315
- * @param input - The object to sanitize
316
- * @param excludedKeys - object keys for which to skip replacement when not in fullScrub
317
- */
318
- replaceObject(input: object | null, excludedKeys: Set<string> = this.defaultExcludedKeys): object | null {
319
- // File might contain actual nulls
320
- if (input === null || input === undefined) {
321
- return input;
322
- }
323
-
324
- const keys = Object.keys(input);
325
- keys.forEach((key) => {
326
- if (this.fullScrub || !excludedKeys.has(key)) {
327
- const value = input[key];
328
- if (typeof value === "string") {
329
- input[key] = this.replaceText(
330
- value,
331
- this.isFluidObjectKey(key) ? TextType.FluidObject : TextType.Generic,
332
- );
333
- } else if (Array.isArray(value)) {
334
- input[key] = this.replaceArray(value);
335
- } else if (typeof value === "object") {
336
- input[key] = this.replaceObject(value, excludedKeys);
337
- }
338
- }
339
- });
340
- return input;
341
- }
342
-
343
- /**
344
- * Replacement on an unknown type or a parsed root level object
345
- * without a key
346
- * @param input - The object to sanitize
347
- * @param excludedKeys - object keys for which to skip replacement when not in fullScrub
348
- */
349
- replaceAny(input: any, excludedKeys: Set<string> = this.defaultExcludedKeys): any {
350
- if (input === null || input === undefined) {
351
- return input;
352
- }
353
-
354
- if (typeof input === "string") {
355
- return this.replaceText(input);
356
- } else if (Array.isArray(input)) {
357
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
358
- return this.replaceArray(input);
359
- } else if (typeof input === "object") {
360
- return this.replaceObject(input, excludedKeys);
361
- }
362
-
363
- // Don't run replacement on any other types
364
- return input;
365
- }
366
-
367
- fixJoin(message: any) {
368
- if (!this.objectMatchesSchema(message.contents, joinContentsSchema)) {
369
- message.contents = this.replaceAny(message.contents);
370
- }
371
-
372
- try {
373
- let data = JSON.parse(message.data);
374
- if (!this.objectMatchesSchema(data, joinDataSchema)) {
375
- data = this.replaceAny(data);
376
- } else {
377
- const user = data.detail.user;
378
- user.id = this.replaceText(user.id, TextType.Email);
379
- user.email = this.replaceText(user.email, TextType.Email);
380
- user.name = this.replaceText(user.name, TextType.Name);
381
- }
382
-
383
- message.data = JSON.stringify(data);
384
- } catch (e) {
385
- this.debugMsg(e);
386
- }
387
- }
388
-
389
- fixPropose(message: any) {
390
- if (!this.objectMatchesSchema(message.contents, proposeContentsSchema)) {
391
- message.contents = this.replaceAny(message.contents);
392
- } else {
393
- if (typeof message.contents === "string") {
394
- try {
395
- const data = JSON.parse(message.contents);
396
- if (this.fullScrub) {
397
- const pkg = data.value?.package;
398
- if (pkg?.name) {
399
- pkg.name = this.replaceText(pkg.name, TextType.FluidObject);
400
- }
401
- if (Array.isArray(pkg?.fluid?.browser?.umd?.files)) {
402
- pkg.fluid.browser.umd.files = this.replaceArray(pkg.fluid.browser.umd.files);
403
- }
404
- }
405
- } catch (e) {
406
- this.debugMsg(e);
407
- }
408
- } else {
409
- if (this.fullScrub) {
410
- message.contents.value = this.replaceText(message.contents.value, TextType.FluidObject);
411
- }
412
- }
413
- }
414
- }
415
-
416
- fixAttachEntries(entries: any[]) {
417
- entries.forEach((element) => {
418
- // Tree type
419
- if (element.value.entries) {
420
- this.fixAttachEntries(element.value.entries);
421
- } else {
422
- // Blob (leaf) type
423
- try {
424
- if (typeof element.value.contents === "string") {
425
- let data = JSON.parse(element.value.contents);
426
- data = this.replaceObject(data);
427
- element.value.contents = JSON.stringify(data);
428
- }
429
- } catch (e) {
430
- this.debugMsg(e);
431
- }
432
- }
433
- });
434
- }
435
-
436
- /**
437
- * Fix the content of an attach in place
438
- * @param contents - contents object to fix
439
- */
440
- fixAttachContents(contents: any): any {
441
- assert(typeof contents === "object", 0x08b /* "Unexpected type on contents for fix of an attach!" */);
442
- if (!this.objectMatchesSchema(contents, attachContentsSchema)) {
443
- this.replaceObject(contents);
444
- } else {
445
- if (this.fullScrub) {
446
- contents.id = this.replaceText(contents.id, TextType.FluidObject);
447
- contents.type = this.replaceText(contents.type, TextType.FluidObject);
448
- }
449
-
450
- this.fixAttachEntries(contents.snapshot.entries);
451
- }
452
- }
453
-
454
- /**
455
- * Fix an attach message at the root level or a ContainerMessageType attach. Attach
456
- * messages found within an op message should instead have their contents parsed out
457
- * and sent to fixAttachContents.
458
- * @param message - The attach message to fix
459
- * @param withinOp - If the message is from within an op message (as opposed to being
460
- * an attach message at the root level). Root level attach messages have "snapshot"
461
- * under a "contents" key, whereas attach messages from within an op message have it
462
- * under a "content" key
463
- */
464
- fixAttach(message: any) {
465
- // Handle case where contents is stringified json
466
- if (typeof message.contents === "string") {
467
- try {
468
- const data = JSON.parse(message.contents);
469
- this.fixAttachContents(data);
470
- message.contents = JSON.stringify(data);
471
- } catch (e) {
472
- this.debugMsg(e);
473
- return;
474
- }
475
- } else {
476
- this.fixAttachContents(message.contents);
477
- }
478
- }
479
-
480
- fixDeltaOp(deltaOp: any) {
481
- deltaOp.seg = typeof deltaOp.seg === "string"
482
- ? this.replaceText(deltaOp.seg)
483
- : this.replaceObject(deltaOp.seg, this.mergeTreeExcludedKeys);
484
- }
485
-
486
- /**
487
- * Fix the contents object for an op message. Does not do extra type handling. Does
488
- * not handle special container message types like "attach", "component", and
489
- * "chunkedOp" (these should be handled by the caller)
490
- * @param contents - The contents object for an op message. If it was a string in the
491
- * message, it must have been converted to an object first
492
- */
493
- fixOpContentsObject(contents: any) {
494
- // do replacement
495
- if (!this.objectMatchesSchema(contents, opContentsSchema)) {
496
- this.replaceAny(contents);
497
- } else {
498
- if (this.fullScrub) {
499
- contents.address = this.replaceText(contents.address, TextType.FluidObject);
500
- }
501
-
502
- const innerContent = contents.contents.content;
503
- assert(innerContent !== undefined, 0x08c /* "innerContent for fixing op contents is undefined!" */);
504
- if (contents.contents.type === "attach") {
505
- // attach op
506
- // handle case where inner content is stringified json
507
- if (typeof contents.contents.content === "string") {
508
- try {
509
- const data = JSON.parse(contents.contents.content);
510
- this.fixAttachContents(data);
511
- contents.contents.content = JSON.stringify(data);
512
- } catch (e) {
513
- this.debugMsg(e);
514
- }
515
- } else {
516
- this.fixAttachContents(contents.contents.content);
517
- }
518
- } else if (this.validator.validate(innerContent, opContentsMapSchema).valid) {
519
- // map op
520
- if (this.fullScrub) {
521
- innerContent.address = this.replaceText(innerContent.address, TextType.FluidObject);
522
- innerContent.contents.key = this.replaceText(innerContent.contents.key, TextType.MapKey);
523
- }
524
- if (innerContent.contents.value !== undefined) {
525
- innerContent.contents.value.value = this.replaceAny(innerContent.contents.value.value);
526
- }
527
- } else if (this.validator.validate(innerContent, opContentsMergeTreeGroupOpSchema).valid) {
528
- // merge tree group op
529
- if (this.fullScrub) {
530
- innerContent.address = this.replaceText(innerContent.address, TextType.FluidObject);
531
- }
532
- innerContent.contents.ops.forEach((deltaOp) => {
533
- this.fixDeltaOp(deltaOp);
534
- });
535
- } else if (this.validator.validate(innerContent, opContentsMergeTreeDeltaOpSchema).valid) {
536
- // merge tree delta op
537
- if (this.fullScrub) {
538
- innerContent.address = this.replaceText(innerContent.address, TextType.FluidObject);
539
- }
540
- this.fixDeltaOp(innerContent.contents);
541
- } else if (this.validator.validate(innerContent, opContentsRegisterCollectionSchema).valid) {
542
- // register collection op
543
- if (this.fullScrub) {
544
- innerContent.address = this.replaceText(innerContent.address, TextType.FluidObject);
545
- innerContent.contents.key = this.replaceText(innerContent.contents.key, TextType.MapKey);
546
- }
547
- if (innerContent.contents.value !== undefined) {
548
- innerContent.contents.value.value = this.replaceAny(innerContent.contents.value.value);
549
- }
550
- } else {
551
- // message contents don't match any known op format
552
- this.objectMatchesSchema(contents, false);
553
- }
554
- }
555
- }
556
-
557
- fixOp(message: any) {
558
- // handle case where contents is stringified json
559
- let msgContents;
560
- if (typeof message.contents === "string") {
561
- try {
562
- msgContents = JSON.parse(message.contents);
563
- } catch (e) {
564
- this.debugMsg(e);
565
- return;
566
- }
567
- } else {
568
- msgContents = message.contents;
569
- }
570
-
571
- // handle container message types
572
- switch (msgContents.type) {
573
- case "attach": {
574
- // this one is like a regular attach op, except its contents aren't nested as deep
575
- // run fixAttach directly and return
576
- this.fixAttach(msgContents);
577
- break;
578
- }
579
- case "component": {
580
- // this one functionally nests its contents one layer deeper
581
- // bring up the contents object and continue as usual
582
- this.fixOpContentsObject(msgContents.contents);
583
- break;
584
- }
585
- case "chunkedOp": {
586
- // this is a (regular?) op split into multiple parts due to size, e.g. because it
587
- // has an attached image, and where the chunkedOp is within the top-level op's contents
588
- // (as opposed to being at the top-level). The contents of the chunks need to be
589
- // concatenated to form the complete stringified json object
590
- // Early return here to skip re-stringify because no changes are made until the last
591
- // chunk, and the ChunkedOpProcessor will handle everything at that point
592
- return this.fixChunkedOp(message);
593
- }
594
- case "blobAttach": {
595
- // TODO: handle this properly once blob api is used
596
- this.debugMsg("TODO: blobAttach ops are skipped/unhandled");
597
- return;
598
- }
599
- default: {
600
- // A regular op
601
- this.fixOpContentsObject(msgContents);
602
- }
603
- }
604
-
605
- // re-stringify the json if needed
606
- if (typeof message.contents === "string") {
607
- try {
608
- message.contents = JSON.stringify(msgContents);
609
- } catch (e) {
610
- this.debugMsg(e);
611
- return;
612
- }
613
- }
614
- }
615
-
616
- /**
617
- * @param message - The top-level chunkedOp message or a top-level op message
618
- * with a chunkedOp inside its contents
619
- */
620
- fixChunkedOp(message: any) {
621
- this.chunkProcessor.addMessage(message);
622
- if (!this.chunkProcessor.hasAllMessages()) {
623
- return;
624
- }
625
-
626
- const contents = this.chunkProcessor.getConcatenatedContents();
627
- this.fixOpContentsObject(contents);
628
-
629
- this.chunkProcessor.writeSanitizedContents(contents);
630
- this.chunkProcessor.reset();
631
- }
632
-
633
- sanitize(): ISequencedDocumentMessage[] {
634
- let seq = 0;
635
-
636
- try {
637
- this.messages.map((message) => {
638
- seq = message.sequenceNumber;
639
- // message types from protocol-definitions' protocol.ts
640
- switch (message.type) {
641
- case "join": {
642
- this.fixJoin(message);
643
- break;
644
- }
645
- case "propose": {
646
- this.fixPropose(message);
647
- break;
648
- }
649
- case "attach": {
650
- this.fixAttach(message);
651
- break;
652
- }
653
- case "op": {
654
- this.fixOp(message);
655
- break;
656
- }
657
- case "chunkedOp": {
658
- this.fixChunkedOp(message);
659
- break;
660
- }
661
- case "noop":
662
- case "leave":
663
- case "noClient":
664
- case "summarize":
665
- case "summaryAck":
666
- case "summaryNack":
667
- break;
668
- default:
669
- this.debugMsg(`Unexpected op type ${message.type}`);
670
- }
671
- });
672
-
673
- // make sure we don't miss an incomplete chunked op at the end
674
- assert(!this.chunkProcessor.isPendingProcessing(), 0x08d /* "After sanitize, pending incomplete ops!" */);
675
- } catch (error) {
676
- this.debugMsg(`Error while processing sequenceNumber ${seq}`);
677
- throw error;
678
- }
679
-
680
- return this.messages;
681
- }
208
+ readonly validator = new Validator.Validator();
209
+ // Represents the keys used to store Fluid object identifiers, snapshot info,
210
+ // and other string fields that should not be replaced in contents blobs to
211
+ // ensure the messages are still usable
212
+ readonly defaultExcludedKeys = new Set<string>();
213
+ // Represents the keys used by merge-tree ops their "seg" property, where other
214
+ // keys represent user information
215
+ readonly mergeTreeExcludedKeys = new Set<string>();
216
+ // Map of user information to what it was replaced with. Used to ensure the same
217
+ // data have the same replacements
218
+ readonly replacementMap = new Map<string, string>();
219
+
220
+ /**
221
+ * Validate that the provided message matches the provided schema.
222
+ * For a full scrub, warn and continue (scrubber should fully sanitize unexpected
223
+ * fields for ops), otherwise throw an error because we cannot be sure user
224
+ * information is being sufficiently sanitized.
225
+ */
226
+ objectMatchesSchema = (object: any, schema: any): boolean => {
227
+ const result = schema === false ? falseResult : this.validator.validate(object, schema);
228
+ if (!result.valid) {
229
+ const errorMsg = `Bad msg fmt:\n${result.toString()}\n${JSON.stringify(
230
+ object,
231
+ undefined,
232
+ 2,
233
+ )}`;
234
+
235
+ if (this.fullScrub || this.noBail) {
236
+ this.debugMsg(errorMsg);
237
+ } else {
238
+ throw new Error(errorMsg);
239
+ }
240
+ }
241
+ return result.valid;
242
+ };
243
+
244
+ readonly chunkProcessor = new ChunkedOpProcessor(this.objectMatchesSchema, this.debug);
245
+
246
+ constructor(
247
+ readonly messages: ISequencedDocumentMessage[],
248
+ readonly fullScrub: boolean,
249
+ readonly noBail: boolean,
250
+ readonly debug: boolean = false,
251
+ ) {
252
+ this.defaultExcludedKeys.add("type");
253
+ this.defaultExcludedKeys.add("id");
254
+ this.defaultExcludedKeys.add("pkg");
255
+ this.defaultExcludedKeys.add("snapshotFormatVersion");
256
+ this.defaultExcludedKeys.add("packageVersion");
257
+ this.mergeTreeExcludedKeys.add("nodeType");
258
+ }
259
+
260
+ debugMsg(msg: any) {
261
+ if (this.debug) {
262
+ console.error(msg);
263
+ }
264
+ }
265
+
266
+ isFluidObjectKey(key: string): boolean {
267
+ return key === "type" || key === "id";
268
+ }
269
+
270
+ getRandomText(len: number): string {
271
+ let str = "";
272
+ while (str.length < len) {
273
+ str = str + Math.random().toString(36).substring(2);
274
+ }
275
+ return str.substr(0, len);
276
+ }
277
+
278
+ readonly wordTokenRegex = /\S+/g;
279
+
280
+ readonly replaceRandomTextFn = (match: string): string => {
281
+ if (this.replacementMap.has(match)) {
282
+ return this.replacementMap.get(match)!;
283
+ }
284
+
285
+ const replacement = this.getRandomText(match.length);
286
+ this.replacementMap.set(match, replacement);
287
+ return replacement;
288
+ };
289
+
290
+ /**
291
+ * Replace text with garbage. FluidObject types are not replaced when not under
292
+ * full scrub mode. All other text is replaced consistently.
293
+ */
294
+ replaceText(input?: string, type: TextType = TextType.Generic): string | undefined {
295
+ if (input === undefined) {
296
+ return undefined;
297
+ }
298
+
299
+ if (type === TextType.FluidObject) {
300
+ if (this.replacementMap.has(input)) {
301
+ return this.replacementMap.get(input)!;
302
+ }
303
+
304
+ const replacement = this.fullScrub ? this.getRandomText(input.length) : input;
305
+
306
+ this.replacementMap.set(input, replacement);
307
+ return replacement;
308
+ }
309
+
310
+ return input.replace(this.wordTokenRegex, this.replaceRandomTextFn);
311
+ }
312
+
313
+ replaceArray(input: any[]): any[] {
314
+ for (let i = 0; i < input.length; i++) {
315
+ const value = input[i];
316
+ if (typeof value === "string") {
317
+ input[i] = this.replaceText(value);
318
+ } else if (Array.isArray(value)) {
319
+ input[i] = this.replaceArray(value);
320
+ } else if (typeof value === "object") {
321
+ input[i] = this.replaceObject(value);
322
+ }
323
+ }
324
+ return input;
325
+ }
326
+
327
+ /**
328
+ * (sort of) recurses down the values of a JSON object to sanitize all its strings
329
+ * (only checks strings, arrays, and objects)
330
+ * @param input - The object to sanitize
331
+ * @param excludedKeys - object keys for which to skip replacement when not in fullScrub
332
+ */
333
+ replaceObject(
334
+ input: object | null,
335
+ excludedKeys: Set<string> = this.defaultExcludedKeys,
336
+ ): object | null {
337
+ // File might contain actual nulls
338
+ if (input === null || input === undefined) {
339
+ return input;
340
+ }
341
+
342
+ const keys = Object.keys(input);
343
+ keys.forEach((key) => {
344
+ if (this.fullScrub || !excludedKeys.has(key)) {
345
+ const value = input[key];
346
+ if (typeof value === "string") {
347
+ input[key] = this.replaceText(
348
+ value,
349
+ this.isFluidObjectKey(key) ? TextType.FluidObject : TextType.Generic,
350
+ );
351
+ } else if (Array.isArray(value)) {
352
+ input[key] = this.replaceArray(value);
353
+ } else if (typeof value === "object") {
354
+ input[key] = this.replaceObject(value, excludedKeys);
355
+ }
356
+ }
357
+ });
358
+ return input;
359
+ }
360
+
361
+ /**
362
+ * Replacement on an unknown type or a parsed root level object
363
+ * without a key
364
+ * @param input - The object to sanitize
365
+ * @param excludedKeys - object keys for which to skip replacement when not in fullScrub
366
+ */
367
+ replaceAny(input: any, excludedKeys: Set<string> = this.defaultExcludedKeys): any {
368
+ if (input === null || input === undefined) {
369
+ return input;
370
+ }
371
+
372
+ if (typeof input === "string") {
373
+ return this.replaceText(input);
374
+ } else if (Array.isArray(input)) {
375
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
376
+ return this.replaceArray(input);
377
+ } else if (typeof input === "object") {
378
+ return this.replaceObject(input, excludedKeys);
379
+ }
380
+
381
+ // Don't run replacement on any other types
382
+ return input;
383
+ }
384
+
385
+ fixJoin(message: any) {
386
+ if (!this.objectMatchesSchema(message.contents, joinContentsSchema)) {
387
+ message.contents = this.replaceAny(message.contents);
388
+ }
389
+
390
+ try {
391
+ let data = JSON.parse(message.data);
392
+ if (!this.objectMatchesSchema(data, joinDataSchema)) {
393
+ data = this.replaceAny(data);
394
+ } else {
395
+ const user = data.detail.user;
396
+ user.id = this.replaceText(user.id, TextType.Email);
397
+ user.email = this.replaceText(user.email, TextType.Email);
398
+ user.name = this.replaceText(user.name, TextType.Name);
399
+ }
400
+
401
+ message.data = JSON.stringify(data);
402
+ } catch (e) {
403
+ this.debugMsg(e);
404
+ }
405
+ }
406
+
407
+ fixPropose(message: any) {
408
+ if (!this.objectMatchesSchema(message.contents, proposeContentsSchema)) {
409
+ message.contents = this.replaceAny(message.contents);
410
+ } else {
411
+ if (typeof message.contents === "string") {
412
+ try {
413
+ const data = JSON.parse(message.contents);
414
+ if (this.fullScrub) {
415
+ const pkg = data.value?.package;
416
+ if (pkg?.name) {
417
+ pkg.name = this.replaceText(pkg.name, TextType.FluidObject);
418
+ }
419
+ if (Array.isArray(pkg?.fluid?.browser?.umd?.files)) {
420
+ pkg.fluid.browser.umd.files = this.replaceArray(
421
+ pkg.fluid.browser.umd.files,
422
+ );
423
+ }
424
+ }
425
+ } catch (e) {
426
+ this.debugMsg(e);
427
+ }
428
+ } else {
429
+ if (this.fullScrub) {
430
+ message.contents.value = this.replaceText(
431
+ message.contents.value,
432
+ TextType.FluidObject,
433
+ );
434
+ }
435
+ }
436
+ }
437
+ }
438
+
439
+ fixAttachEntries(entries: any[]) {
440
+ entries.forEach((element) => {
441
+ // Tree type
442
+ if (element.value.entries) {
443
+ this.fixAttachEntries(element.value.entries);
444
+ } else {
445
+ // Blob (leaf) type
446
+ try {
447
+ if (typeof element.value.contents === "string") {
448
+ let data = JSON.parse(element.value.contents);
449
+ data = this.replaceObject(data);
450
+ element.value.contents = JSON.stringify(data);
451
+ }
452
+ } catch (e) {
453
+ this.debugMsg(e);
454
+ }
455
+ }
456
+ });
457
+ }
458
+
459
+ /**
460
+ * Fix the content of an attach in place
461
+ * @param contents - contents object to fix
462
+ */
463
+ fixAttachContents(contents: any): any {
464
+ assert(
465
+ typeof contents === "object",
466
+ 0x08b /* "Unexpected type on contents for fix of an attach!" */,
467
+ );
468
+ if (!this.objectMatchesSchema(contents, attachContentsSchema)) {
469
+ this.replaceObject(contents);
470
+ } else {
471
+ if (this.fullScrub) {
472
+ contents.id = this.replaceText(contents.id, TextType.FluidObject);
473
+ contents.type = this.replaceText(contents.type, TextType.FluidObject);
474
+ }
475
+
476
+ this.fixAttachEntries(contents.snapshot.entries);
477
+ }
478
+ }
479
+
480
+ /**
481
+ * Fix an attach message at the root level or a ContainerMessageType attach. Attach
482
+ * messages found within an op message should instead have their contents parsed out
483
+ * and sent to fixAttachContents.
484
+ * @param message - The attach message to fix
485
+ * @param withinOp - If the message is from within an op message (as opposed to being
486
+ * an attach message at the root level). Root level attach messages have "snapshot"
487
+ * under a "contents" key, whereas attach messages from within an op message have it
488
+ * under a "content" key
489
+ */
490
+ fixAttach(message: any) {
491
+ // Handle case where contents is stringified json
492
+ if (typeof message.contents === "string") {
493
+ try {
494
+ const data = JSON.parse(message.contents);
495
+ this.fixAttachContents(data);
496
+ message.contents = JSON.stringify(data);
497
+ } catch (e) {
498
+ this.debugMsg(e);
499
+ return;
500
+ }
501
+ } else {
502
+ this.fixAttachContents(message.contents);
503
+ }
504
+ }
505
+
506
+ fixDeltaOp(deltaOp: any) {
507
+ deltaOp.seg =
508
+ typeof deltaOp.seg === "string"
509
+ ? this.replaceText(deltaOp.seg)
510
+ : this.replaceObject(deltaOp.seg, this.mergeTreeExcludedKeys);
511
+ }
512
+
513
+ /**
514
+ * Fix the contents object for an op message. Does not do extra type handling. Does
515
+ * not handle special container message types like "attach", "component", and
516
+ * "chunkedOp" (these should be handled by the caller)
517
+ * @param contents - The contents object for an op message. If it was a string in the
518
+ * message, it must have been converted to an object first
519
+ */
520
+ fixOpContentsObject(contents: any) {
521
+ // do replacement
522
+ if (!this.objectMatchesSchema(contents, opContentsSchema)) {
523
+ this.replaceAny(contents);
524
+ } else {
525
+ if (this.fullScrub) {
526
+ contents.address = this.replaceText(contents.address, TextType.FluidObject);
527
+ }
528
+
529
+ const innerContent = contents.contents.content;
530
+ assert(
531
+ innerContent !== undefined,
532
+ 0x08c /* "innerContent for fixing op contents is undefined!" */,
533
+ );
534
+ if (contents.contents.type === "attach") {
535
+ // attach op
536
+ // handle case where inner content is stringified json
537
+ if (typeof contents.contents.content === "string") {
538
+ try {
539
+ const data = JSON.parse(contents.contents.content);
540
+ this.fixAttachContents(data);
541
+ contents.contents.content = JSON.stringify(data);
542
+ } catch (e) {
543
+ this.debugMsg(e);
544
+ }
545
+ } else {
546
+ this.fixAttachContents(contents.contents.content);
547
+ }
548
+ } else if (this.validator.validate(innerContent, opContentsMapSchema).valid) {
549
+ // map op
550
+ if (this.fullScrub) {
551
+ innerContent.address = this.replaceText(
552
+ innerContent.address,
553
+ TextType.FluidObject,
554
+ );
555
+ innerContent.contents.key = this.replaceText(
556
+ innerContent.contents.key,
557
+ TextType.MapKey,
558
+ );
559
+ }
560
+ if (innerContent.contents.value !== undefined) {
561
+ innerContent.contents.value.value = this.replaceAny(
562
+ innerContent.contents.value.value,
563
+ );
564
+ }
565
+ } else if (
566
+ this.validator.validate(innerContent, opContentsMergeTreeGroupOpSchema).valid
567
+ ) {
568
+ // merge tree group op
569
+ if (this.fullScrub) {
570
+ innerContent.address = this.replaceText(
571
+ innerContent.address,
572
+ TextType.FluidObject,
573
+ );
574
+ }
575
+ innerContent.contents.ops.forEach((deltaOp) => {
576
+ this.fixDeltaOp(deltaOp);
577
+ });
578
+ } else if (
579
+ this.validator.validate(innerContent, opContentsMergeTreeDeltaOpSchema).valid
580
+ ) {
581
+ // merge tree delta op
582
+ if (this.fullScrub) {
583
+ innerContent.address = this.replaceText(
584
+ innerContent.address,
585
+ TextType.FluidObject,
586
+ );
587
+ }
588
+ this.fixDeltaOp(innerContent.contents);
589
+ } else if (
590
+ this.validator.validate(innerContent, opContentsRegisterCollectionSchema).valid
591
+ ) {
592
+ // register collection op
593
+ if (this.fullScrub) {
594
+ innerContent.address = this.replaceText(
595
+ innerContent.address,
596
+ TextType.FluidObject,
597
+ );
598
+ innerContent.contents.key = this.replaceText(
599
+ innerContent.contents.key,
600
+ TextType.MapKey,
601
+ );
602
+ }
603
+ if (innerContent.contents.value !== undefined) {
604
+ innerContent.contents.value.value = this.replaceAny(
605
+ innerContent.contents.value.value,
606
+ );
607
+ }
608
+ } else {
609
+ // message contents don't match any known op format
610
+ this.objectMatchesSchema(contents, false);
611
+ }
612
+ }
613
+ }
614
+
615
+ fixOp(message: any) {
616
+ // handle case where contents is stringified json
617
+ let msgContents;
618
+ if (typeof message.contents === "string") {
619
+ try {
620
+ msgContents = JSON.parse(message.contents);
621
+ } catch (e) {
622
+ this.debugMsg(e);
623
+ return;
624
+ }
625
+ } else {
626
+ msgContents = message.contents;
627
+ }
628
+
629
+ // handle container message types
630
+ switch (msgContents.type) {
631
+ case "attach": {
632
+ // this one is like a regular attach op, except its contents aren't nested as deep
633
+ // run fixAttach directly and return
634
+ this.fixAttach(msgContents);
635
+ break;
636
+ }
637
+ case "component": {
638
+ // this one functionally nests its contents one layer deeper
639
+ // bring up the contents object and continue as usual
640
+ this.fixOpContentsObject(msgContents.contents);
641
+ break;
642
+ }
643
+ case "chunkedOp": {
644
+ // this is a (regular?) op split into multiple parts due to size, e.g. because it
645
+ // has an attached image, and where the chunkedOp is within the top-level op's contents
646
+ // (as opposed to being at the top-level). The contents of the chunks need to be
647
+ // concatenated to form the complete stringified json object
648
+ // Early return here to skip re-stringify because no changes are made until the last
649
+ // chunk, and the ChunkedOpProcessor will handle everything at that point
650
+ return this.fixChunkedOp(message);
651
+ }
652
+ case "blobAttach": {
653
+ // TODO: handle this properly once blob api is used
654
+ this.debugMsg("TODO: blobAttach ops are skipped/unhandled");
655
+ return;
656
+ }
657
+ default: {
658
+ // A regular op
659
+ this.fixOpContentsObject(msgContents);
660
+ }
661
+ }
662
+
663
+ // re-stringify the json if needed
664
+ if (typeof message.contents === "string") {
665
+ try {
666
+ message.contents = JSON.stringify(msgContents);
667
+ } catch (e) {
668
+ this.debugMsg(e);
669
+ return;
670
+ }
671
+ }
672
+ }
673
+
674
+ /**
675
+ * @param message - The top-level chunkedOp message or a top-level op message
676
+ * with a chunkedOp inside its contents
677
+ */
678
+ fixChunkedOp(message: any) {
679
+ this.chunkProcessor.addMessage(message);
680
+ if (!this.chunkProcessor.hasAllMessages()) {
681
+ return;
682
+ }
683
+
684
+ const contents = this.chunkProcessor.getConcatenatedContents();
685
+ this.fixOpContentsObject(contents);
686
+
687
+ this.chunkProcessor.writeSanitizedContents(contents);
688
+ this.chunkProcessor.reset();
689
+ }
690
+
691
+ sanitize(): ISequencedDocumentMessage[] {
692
+ let seq = 0;
693
+
694
+ try {
695
+ this.messages.map((message) => {
696
+ seq = message.sequenceNumber;
697
+ // message types from protocol-definitions' protocol.ts
698
+ switch (message.type) {
699
+ case "join": {
700
+ this.fixJoin(message);
701
+ break;
702
+ }
703
+ case "propose": {
704
+ this.fixPropose(message);
705
+ break;
706
+ }
707
+ case "attach": {
708
+ this.fixAttach(message);
709
+ break;
710
+ }
711
+ case "op": {
712
+ this.fixOp(message);
713
+ break;
714
+ }
715
+ case "chunkedOp": {
716
+ this.fixChunkedOp(message);
717
+ break;
718
+ }
719
+ case "noop":
720
+ case "leave":
721
+ case "noClient":
722
+ case "summarize":
723
+ case "summaryAck":
724
+ case "summaryNack":
725
+ break;
726
+ default:
727
+ this.debugMsg(`Unexpected op type ${message.type}`);
728
+ }
729
+ });
730
+
731
+ // make sure we don't miss an incomplete chunked op at the end
732
+ assert(
733
+ !this.chunkProcessor.isPendingProcessing(),
734
+ 0x08d /* "After sanitize, pending incomplete ops!" */,
735
+ );
736
+ } catch (error) {
737
+ this.debugMsg(`Error while processing sequenceNumber ${seq}`);
738
+ throw error;
739
+ }
740
+
741
+ return this.messages;
742
+ }
682
743
  }