@innovatorved/code-lab 0.3.1 → 0.3.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.
Files changed (48) hide show
  1. package/ARCHITECTURE.md +4 -2
  2. package/CHANGELOG.md +25 -0
  3. package/README.md +15 -5
  4. package/dist/code-lab.css +52 -2
  5. package/dist/code-lab.d.ts +1 -1
  6. package/dist/code-lab.esm.js +1247 -377
  7. package/dist/code-lab.js +1246 -376
  8. package/dist/diagnostics.d.ts +5 -0
  9. package/dist/extensions/cpp.esm.js +51 -9
  10. package/dist/extensions/cpp.js +51 -9
  11. package/dist/extensions/python.esm.js +116 -103
  12. package/dist/extensions/python.js +116 -103
  13. package/dist/index.d.ts +1 -1
  14. package/dist/preview-sw.js +34 -17
  15. package/dist/runtime.esm.js +38 -31
  16. package/dist/runtime.js +38 -31
  17. package/dist/schemas.d.ts +1 -1
  18. package/dist/scm.d.ts +13 -2
  19. package/dist/search.d.ts +5 -1
  20. package/dist/shell.esm.js +72 -16
  21. package/dist/shell.js +72 -16
  22. package/dist/terminal.esm.js +183 -54
  23. package/dist/terminal.js +183 -54
  24. package/dist/workbench/index.d.ts +1 -1
  25. package/dist/workbench/styles.d.ts +1 -1
  26. package/dist/zip.d.ts +4 -3
  27. package/package.json +1 -1
  28. package/src/code-lab.css +52 -2
  29. package/src/csp.ts +7 -10
  30. package/src/diagnostics.ts +42 -3
  31. package/src/extensions/cpp.ts +47 -9
  32. package/src/extensions/python.ts +128 -116
  33. package/src/index.ts +1 -1
  34. package/src/preview-sw.js +25 -5
  35. package/src/runtime.ts +36 -29
  36. package/src/schemas.ts +1 -1
  37. package/src/scm.ts +106 -19
  38. package/src/search.ts +71 -27
  39. package/src/shell.ts +70 -14
  40. package/src/terminal.ts +181 -52
  41. package/src/workbench/diff-editor.ts +41 -13
  42. package/src/workbench/drawer.ts +17 -4
  43. package/src/workbench/guided-pane.ts +12 -2
  44. package/src/workbench/share.ts +37 -8
  45. package/src/workbench/styles.ts +2 -1
  46. package/src/workbench/toolbar.ts +15 -4
  47. package/src/workbench.ts +482 -79
  48. package/src/zip.ts +29 -7
package/src/zip.ts CHANGED
@@ -57,8 +57,18 @@ export function computeCrc32(data: string | Uint8Array | ArrayBuffer): number {
57
57
  return (crc ^ 0xffffffff) >>> 0;
58
58
  }
59
59
 
60
+ const DANGEROUS_PATH_SEGMENTS: ReadonlySet<string> = new Set([
61
+ '__proto__',
62
+ 'constructor',
63
+ 'prototype'
64
+ ]);
65
+
66
+ const MAX_ZIP_ENTRIES = 10000;
67
+ const MAX_ZIP_UNCOMPRESSED_BYTES = 100 * 1024 * 1024; // 100 MB
68
+
60
69
  /**
61
- * Sanitizes an archive entry path to prevent Zip-Slip directory traversal attacks.
70
+ * Sanitizes an archive entry path to prevent Zip-Slip directory traversal attacks
71
+ * and prototype-pollution key injection.
62
72
  * Normalizes backslashes, strips drive prefixes and leading slashes, and collapses
63
73
  * or removes `..` and `.` segments so the resulting path is strictly relative.
64
74
  */
@@ -71,6 +81,9 @@ export function sanitizeZipPath(rawPath: string): string {
71
81
  for (const part of parts) {
72
82
  const trimmed = part.trim();
73
83
  if (!trimmed || trimmed === '.') continue;
84
+ if (DANGEROUS_PATH_SEGMENTS.has(trimmed)) {
85
+ return '';
86
+ }
74
87
  if (trimmed === '..') {
75
88
  if (safeParts.length > 0) {
76
89
  safeParts.pop();
@@ -117,9 +130,9 @@ interface ZipEntryInternal {
117
130
  /**
118
131
  * Creates a standard PKZip v2.0 archive from a map of file paths to contents.
119
132
  */
120
- export async function createZip(
133
+ export function createZip(
121
134
  files: Record<string, string | Uint8Array>
122
- ): Promise<Uint8Array> {
135
+ ): Uint8Array {
123
136
  const entries: ZipEntryInternal[] = [];
124
137
  let localSectionSize = 0;
125
138
  let centralDirSize = 0;
@@ -215,9 +228,9 @@ export async function createZip(
215
228
  * Extracts a PKZip v2.0 archive into a UTF-8 file dictionary (`Record<string, string>`).
216
229
  * Validates magic headers, checks boundaries, and sanitizes paths against Zip-Slip.
217
230
  */
218
- export async function extractZip(
231
+ export function extractZip(
219
232
  data: Uint8Array | ArrayBuffer
220
- ): Promise<Record<string, string>> {
233
+ ): Record<string, string> {
221
234
  const bytes = toUint8Array(data);
222
235
  if (bytes.length < 22) {
223
236
  throw new Error('Invalid or truncated ZIP archive: buffer shorter than minimum 22-byte EOCD record');
@@ -238,6 +251,9 @@ export async function extractZip(
238
251
  }
239
252
 
240
253
  const totalEntries = readUInt16LE(bytes, eocdOffset + 10);
254
+ if (totalEntries > MAX_ZIP_ENTRIES) {
255
+ throw new Error(`ZIP archive exceeds maximum allowed entry count (${MAX_ZIP_ENTRIES})`);
256
+ }
241
257
  const centralDirSize = readUInt32LE(bytes, eocdOffset + 12);
242
258
  const centralDirOffset = readUInt32LE(bytes, eocdOffset + 16);
243
259
 
@@ -245,8 +261,9 @@ export async function extractZip(
245
261
  throw new Error('Corrupted ZIP archive: Central Directory extends past end of buffer');
246
262
  }
247
263
 
248
- const result: Record<string, string> = {};
264
+ const result: Record<string, string> = Object.create(null) as Record<string, string>;
249
265
  let cdCursor = centralDirOffset;
266
+ let totalExtractedBytes = 0;
250
267
 
251
268
  for (let i = 0; i < totalEntries; i++) {
252
269
  if (cdCursor + 46 > bytes.length) {
@@ -299,6 +316,11 @@ export async function extractZip(
299
316
  throw new Error(`Corrupted ZIP archive: file data truncated for ${safeName}`);
300
317
  }
301
318
 
319
+ totalExtractedBytes += compressedSize;
320
+ if (totalExtractedBytes > MAX_ZIP_UNCOMPRESSED_BYTES) {
321
+ throw new Error(`ZIP archive exceeds maximum uncompressed size limit (${MAX_ZIP_UNCOMPRESSED_BYTES} bytes)`);
322
+ }
323
+
302
324
  const rawFileBytes = bytes.subarray(dataStart, dataEnd);
303
325
  if (compressionMethod !== 0) {
304
326
  throw new Error(`Unsupported ZIP compression method ${compressionMethod} for ${safeName} (only Store=0 is supported)`);
@@ -314,7 +336,7 @@ export async function extractZip(
314
336
  result[safeName] = textDecoder.decode(rawFileBytes);
315
337
  }
316
338
 
317
- return result;
339
+ return { ...result };
318
340
  }
319
341
 
320
342
  export default {