@secure-exec/core 0.2.0-rc.1 → 0.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 (60) hide show
  1. package/dist/generated/isolate-runtime.d.ts +2 -2
  2. package/dist/generated/isolate-runtime.js +2 -2
  3. package/dist/index.d.ts +17 -4
  4. package/dist/index.js +10 -2
  5. package/dist/isolate-runtime/require-setup.js +1489 -239
  6. package/dist/isolate-runtime/setup-dynamic-import.js +31 -0
  7. package/dist/kernel/device-backend.d.ts +14 -0
  8. package/dist/kernel/device-backend.js +251 -0
  9. package/dist/kernel/device-layer.js +9 -0
  10. package/dist/kernel/file-lock.js +2 -3
  11. package/dist/kernel/index.d.ts +4 -4
  12. package/dist/kernel/index.js +3 -3
  13. package/dist/kernel/kernel.js +141 -122
  14. package/dist/kernel/mount-table.d.ts +75 -0
  15. package/dist/kernel/mount-table.js +353 -0
  16. package/dist/kernel/permissions.d.ts +9 -0
  17. package/dist/kernel/permissions.js +33 -1
  18. package/dist/kernel/proc-backend.d.ts +30 -0
  19. package/dist/kernel/proc-backend.js +428 -0
  20. package/dist/kernel/proc-layer.js +6 -0
  21. package/dist/kernel/process-table.d.ts +3 -1
  22. package/dist/kernel/process-table.js +23 -3
  23. package/dist/kernel/pty.d.ts +3 -2
  24. package/dist/kernel/pty.js +13 -2
  25. package/dist/kernel/socket-table.d.ts +7 -0
  26. package/dist/kernel/socket-table.js +99 -35
  27. package/dist/kernel/types.d.ts +45 -4
  28. package/dist/kernel/types.js +9 -0
  29. package/dist/kernel/vfs.d.ts +30 -2
  30. package/dist/kernel/vfs.js +19 -2
  31. package/dist/shared/api-types.d.ts +6 -0
  32. package/dist/shared/bridge-contract.d.ts +21 -3
  33. package/dist/shared/bridge-contract.js +2 -0
  34. package/dist/shared/console-formatter.js +8 -8
  35. package/dist/shared/global-exposure.js +95 -0
  36. package/dist/shared/in-memory-fs.d.ts +14 -59
  37. package/dist/shared/in-memory-fs.js +97 -597
  38. package/dist/shared/permissions.js +5 -0
  39. package/dist/test/block-store-conformance.d.ts +34 -0
  40. package/dist/test/block-store-conformance.js +251 -0
  41. package/dist/test/metadata-store-conformance.d.ts +37 -0
  42. package/dist/test/metadata-store-conformance.js +646 -0
  43. package/dist/test/vfs-conformance.d.ts +65 -0
  44. package/dist/test/vfs-conformance.js +842 -0
  45. package/dist/types.d.ts +1 -0
  46. package/dist/vfs/chunked-vfs.d.ts +66 -0
  47. package/dist/vfs/chunked-vfs.js +1290 -0
  48. package/dist/vfs/host-block-store.d.ts +19 -0
  49. package/dist/vfs/host-block-store.js +97 -0
  50. package/dist/vfs/memory-block-store.d.ts +16 -0
  51. package/dist/vfs/memory-block-store.js +45 -0
  52. package/dist/vfs/memory-metadata.d.ts +75 -0
  53. package/dist/vfs/memory-metadata.js +528 -0
  54. package/dist/vfs/sqlite-metadata.d.ts +91 -0
  55. package/dist/vfs/sqlite-metadata.js +582 -0
  56. package/dist/vfs/types.d.ts +210 -0
  57. package/dist/vfs/types.js +8 -0
  58. package/package.json +20 -1
  59. package/dist/kernel/inode-table.d.ts +0 -43
  60. package/dist/kernel/inode-table.js +0 -85
@@ -91,6 +91,7 @@ export declare const HOST_BRIDGE_GLOBAL_KEYS: {
91
91
  readonly networkHttp2StreamPushStreamRaw: "_networkHttp2StreamPushStreamRaw";
92
92
  readonly networkHttp2StreamWriteRaw: "_networkHttp2StreamWriteRaw";
93
93
  readonly networkHttp2StreamEndRaw: "_networkHttp2StreamEndRaw";
94
+ readonly networkHttp2StreamCloseRaw: "_networkHttp2StreamCloseRaw";
94
95
  readonly networkHttp2StreamPauseRaw: "_networkHttp2StreamPauseRaw";
95
96
  readonly networkHttp2StreamResumeRaw: "_networkHttp2StreamResumeRaw";
96
97
  readonly networkHttp2StreamRespondWithFileRaw: "_networkHttp2StreamRespondWithFileRaw";
@@ -124,6 +125,7 @@ export declare const HOST_BRIDGE_GLOBAL_KEYS: {
124
125
  readonly resolveModuleSync: "_resolveModuleSync";
125
126
  readonly loadFileSync: "_loadFileSync";
126
127
  readonly ptySetRawMode: "_ptySetRawMode";
128
+ readonly kernelStdinRead: "_kernelStdinRead";
127
129
  readonly processConfig: "_processConfig";
128
130
  readonly osConfig: "_osConfig";
129
131
  readonly log: "_log";
@@ -237,6 +239,7 @@ export declare const HOST_BRIDGE_GLOBAL_KEY_LIST: ValueOf<{
237
239
  readonly networkHttp2StreamPushStreamRaw: "_networkHttp2StreamPushStreamRaw";
238
240
  readonly networkHttp2StreamWriteRaw: "_networkHttp2StreamWriteRaw";
239
241
  readonly networkHttp2StreamEndRaw: "_networkHttp2StreamEndRaw";
242
+ readonly networkHttp2StreamCloseRaw: "_networkHttp2StreamCloseRaw";
240
243
  readonly networkHttp2StreamPauseRaw: "_networkHttp2StreamPauseRaw";
241
244
  readonly networkHttp2StreamResumeRaw: "_networkHttp2StreamResumeRaw";
242
245
  readonly networkHttp2StreamRespondWithFileRaw: "_networkHttp2StreamRespondWithFileRaw";
@@ -270,6 +273,7 @@ export declare const HOST_BRIDGE_GLOBAL_KEY_LIST: ValueOf<{
270
273
  readonly resolveModuleSync: "_resolveModuleSync";
271
274
  readonly loadFileSync: "_loadFileSync";
272
275
  readonly ptySetRawMode: "_ptySetRawMode";
276
+ readonly kernelStdinRead: "_kernelStdinRead";
273
277
  readonly processConfig: "_processConfig";
274
278
  readonly osConfig: "_osConfig";
275
279
  readonly log: "_log";
@@ -379,6 +383,7 @@ export declare const BRIDGE_GLOBAL_KEY_LIST: readonly (ValueOf<{
379
383
  readonly networkHttp2StreamPushStreamRaw: "_networkHttp2StreamPushStreamRaw";
380
384
  readonly networkHttp2StreamWriteRaw: "_networkHttp2StreamWriteRaw";
381
385
  readonly networkHttp2StreamEndRaw: "_networkHttp2StreamEndRaw";
386
+ readonly networkHttp2StreamCloseRaw: "_networkHttp2StreamCloseRaw";
382
387
  readonly networkHttp2StreamPauseRaw: "_networkHttp2StreamPauseRaw";
383
388
  readonly networkHttp2StreamResumeRaw: "_networkHttp2StreamResumeRaw";
384
389
  readonly networkHttp2StreamRespondWithFileRaw: "_networkHttp2StreamRespondWithFileRaw";
@@ -412,6 +417,7 @@ export declare const BRIDGE_GLOBAL_KEY_LIST: readonly (ValueOf<{
412
417
  readonly resolveModuleSync: "_resolveModuleSync";
413
418
  readonly loadFileSync: "_loadFileSync";
414
419
  readonly ptySetRawMode: "_ptySetRawMode";
420
+ readonly kernelStdinRead: "_kernelStdinRead";
415
421
  readonly processConfig: "_processConfig";
416
422
  readonly osConfig: "_osConfig";
417
423
  readonly log: "_log";
@@ -463,6 +469,7 @@ export interface BridgeApplySyncRef<TArgs extends unknown[], TResult> {
463
469
  export interface BridgeApplySyncPromiseRef<TArgs extends unknown[], TResult> {
464
470
  applySyncPromise(ctx: undefined, args: TArgs): TResult;
465
471
  }
472
+ export type ModuleLoadMode = "require" | "import";
466
473
  export type DynamicImportBridgeRef = BridgeApplyRef<[
467
474
  string,
468
475
  string
@@ -471,13 +478,20 @@ export type LoadPolyfillBridgeRef = BridgeApplyRef<[string], string | null>;
471
478
  export type ResolveModuleBridgeRef = BridgeApplySyncPromiseRef<[
472
479
  string,
473
480
  string
474
- ], string | null>;
475
- export type LoadFileBridgeRef = BridgeApplySyncPromiseRef<[string], string | null>;
481
+ ] | [string, string, ModuleLoadMode], string | null>;
482
+ export type LoadFileBridgeRef = BridgeApplySyncPromiseRef<[
483
+ string
484
+ ] | [string, ModuleLoadMode], string | null>;
476
485
  export type RequireFromBridgeFn = (request: string, dirname: string) => unknown;
477
486
  export type ModuleCacheBridgeRecord = Record<string, unknown>;
478
487
  export type ProcessLogBridgeRef = BridgeApplySyncRef<[string], void>;
479
488
  export type ProcessErrorBridgeRef = BridgeApplySyncRef<[string], void>;
480
489
  export type ScheduleTimerBridgeRef = BridgeApplyRef<[number], void>;
490
+ export type KernelStdinReadBridgeRef = BridgeApplyRef<[
491
+ ], {
492
+ done: boolean;
493
+ dataBase64?: string;
494
+ }>;
481
495
  export type CryptoRandomFillBridgeRef = BridgeApplySyncRef<[number], string>;
482
496
  export type CryptoRandomUuidBridgeRef = BridgeApplySyncRef<[], string>;
483
497
  export type CryptoHashDigestBridgeRef = BridgeApplySyncRef<[string, string], string>;
@@ -678,7 +692,7 @@ export type NetworkHttp2StreamRespondRawBridgeRef = BridgeApplySyncRef<[
678
692
  number,
679
693
  string
680
694
  ], void>;
681
- export type NetworkHttp2StreamPushStreamRawBridgeRef = BridgeApplySyncPromiseRef<[
695
+ export type NetworkHttp2StreamPushStreamRawBridgeRef = BridgeApplySyncRef<[
682
696
  number,
683
697
  string,
684
698
  string
@@ -691,6 +705,10 @@ export type NetworkHttp2StreamEndRawBridgeRef = BridgeApplySyncRef<[
691
705
  number,
692
706
  string | null
693
707
  ], void>;
708
+ export type NetworkHttp2StreamCloseRawBridgeRef = BridgeApplySyncRef<[
709
+ number,
710
+ number | null
711
+ ], void>;
694
712
  export type NetworkHttp2StreamPauseRawBridgeRef = BridgeApplySyncRef<[number], void>;
695
713
  export type NetworkHttp2StreamResumeRawBridgeRef = BridgeApplySyncRef<[number], void>;
696
714
  export type NetworkHttp2StreamRespondWithFileRawBridgeRef = BridgeApplySyncRef<[
@@ -93,6 +93,7 @@ export const HOST_BRIDGE_GLOBAL_KEYS = {
93
93
  networkHttp2StreamPushStreamRaw: "_networkHttp2StreamPushStreamRaw",
94
94
  networkHttp2StreamWriteRaw: "_networkHttp2StreamWriteRaw",
95
95
  networkHttp2StreamEndRaw: "_networkHttp2StreamEndRaw",
96
+ networkHttp2StreamCloseRaw: "_networkHttp2StreamCloseRaw",
96
97
  networkHttp2StreamPauseRaw: "_networkHttp2StreamPauseRaw",
97
98
  networkHttp2StreamResumeRaw: "_networkHttp2StreamResumeRaw",
98
99
  networkHttp2StreamRespondWithFileRaw: "_networkHttp2StreamRespondWithFileRaw",
@@ -126,6 +127,7 @@ export const HOST_BRIDGE_GLOBAL_KEYS = {
126
127
  resolveModuleSync: "_resolveModuleSync",
127
128
  loadFileSync: "_loadFileSync",
128
129
  ptySetRawMode: "_ptySetRawMode",
130
+ kernelStdinRead: "_kernelStdinRead",
129
131
  processConfig: "_processConfig",
130
132
  osConfig: "_osConfig",
131
133
  log: "_log",
@@ -148,14 +148,14 @@ export function getConsoleSetupCode(budget = DEFAULT_CONSOLE_SERIALIZATION_BUDGE
148
148
  const formatConsoleArgs = ${formatConsoleArgs.toString()};
149
149
 
150
150
  globalThis.console = {
151
- log: (...args) => _log(formatConsoleArgs(args, __consoleBudget)),
152
- error: (...args) => _error(formatConsoleArgs(args, __consoleBudget)),
153
- warn: (...args) => _error(formatConsoleArgs(args, __consoleBudget)),
154
- info: (...args) => _log(formatConsoleArgs(args, __consoleBudget)),
155
- debug: (...args) => _log(formatConsoleArgs(args, __consoleBudget)),
156
- trace: (...args) => _error(formatConsoleArgs(args, __consoleBudget)),
157
- dir: (...args) => _log(formatConsoleArgs(args, __consoleBudget)),
158
- table: (...args) => _log(formatConsoleArgs(args, __consoleBudget)),
151
+ log: (...args) => _log(formatConsoleArgs(args, __consoleBudget) + "\\n"),
152
+ error: (...args) => _error(formatConsoleArgs(args, __consoleBudget) + "\\n"),
153
+ warn: (...args) => _error(formatConsoleArgs(args, __consoleBudget) + "\\n"),
154
+ info: (...args) => _log(formatConsoleArgs(args, __consoleBudget) + "\\n"),
155
+ debug: (...args) => _log(formatConsoleArgs(args, __consoleBudget) + "\\n"),
156
+ trace: (...args) => _error(formatConsoleArgs(args, __consoleBudget) + "\\n"),
157
+ dir: (...args) => _log(formatConsoleArgs(args, __consoleBudget) + "\\n"),
158
+ table: (...args) => _log(formatConsoleArgs(args, __consoleBudget) + "\\n"),
159
159
  };
160
160
  `;
161
161
  }
@@ -480,6 +480,11 @@ export const NODE_CUSTOM_GLOBAL_INVENTORY = [
480
480
  classification: "hardened",
481
481
  rationale: "Host HTTP/2 session settings bridge reference.",
482
482
  },
483
+ {
484
+ name: "_networkHttp2SessionSetLocalWindowSizeRaw",
485
+ classification: "hardened",
486
+ rationale: "Host HTTP/2 session local-window bridge reference.",
487
+ },
483
488
  {
484
489
  name: "_networkHttp2SessionGoawayRaw",
485
490
  classification: "hardened",
@@ -500,6 +505,16 @@ export const NODE_CUSTOM_GLOBAL_INVENTORY = [
500
505
  classification: "hardened",
501
506
  rationale: "Host HTTP/2 session lifetime bridge reference.",
502
507
  },
508
+ {
509
+ name: "_networkHttp2ServerPollRaw",
510
+ classification: "hardened",
511
+ rationale: "Host HTTP/2 server event-poll bridge reference.",
512
+ },
513
+ {
514
+ name: "_networkHttp2SessionPollRaw",
515
+ classification: "hardened",
516
+ rationale: "Host HTTP/2 session event-poll bridge reference.",
517
+ },
503
518
  {
504
519
  name: "_networkHttp2StreamRespondRaw",
505
520
  classification: "hardened",
@@ -520,6 +535,31 @@ export const NODE_CUSTOM_GLOBAL_INVENTORY = [
520
535
  classification: "hardened",
521
536
  rationale: "Host HTTP/2 stream end bridge reference.",
522
537
  },
538
+ {
539
+ name: "_networkHttp2StreamCloseRaw",
540
+ classification: "hardened",
541
+ rationale: "Host HTTP/2 stream close bridge reference.",
542
+ },
543
+ {
544
+ name: "_networkHttp2StreamPauseRaw",
545
+ classification: "hardened",
546
+ rationale: "Host HTTP/2 stream pause bridge reference.",
547
+ },
548
+ {
549
+ name: "_networkHttp2StreamResumeRaw",
550
+ classification: "hardened",
551
+ rationale: "Host HTTP/2 stream resume bridge reference.",
552
+ },
553
+ {
554
+ name: "_networkHttp2StreamRespondWithFileRaw",
555
+ classification: "hardened",
556
+ rationale: "Host HTTP/2 stream respondWithFile bridge reference.",
557
+ },
558
+ {
559
+ name: "_networkHttp2ServerRespondRaw",
560
+ classification: "hardened",
561
+ rationale: "Host HTTP/2 server-response bridge reference.",
562
+ },
523
563
  {
524
564
  name: "_upgradeSocketWriteRaw",
525
565
  classification: "hardened",
@@ -610,6 +650,46 @@ export const NODE_CUSTOM_GLOBAL_INVENTORY = [
610
650
  classification: "hardened",
611
651
  rationale: "Host net server close bridge reference.",
612
652
  },
653
+ {
654
+ name: "_dgramSocketCreateRaw",
655
+ classification: "hardened",
656
+ rationale: "Host dgram socket create bridge reference.",
657
+ },
658
+ {
659
+ name: "_dgramSocketBindRaw",
660
+ classification: "hardened",
661
+ rationale: "Host dgram socket bind bridge reference.",
662
+ },
663
+ {
664
+ name: "_dgramSocketRecvRaw",
665
+ classification: "hardened",
666
+ rationale: "Host dgram socket receive bridge reference.",
667
+ },
668
+ {
669
+ name: "_dgramSocketSendRaw",
670
+ classification: "hardened",
671
+ rationale: "Host dgram socket send bridge reference.",
672
+ },
673
+ {
674
+ name: "_dgramSocketCloseRaw",
675
+ classification: "hardened",
676
+ rationale: "Host dgram socket close bridge reference.",
677
+ },
678
+ {
679
+ name: "_dgramSocketAddressRaw",
680
+ classification: "hardened",
681
+ rationale: "Host dgram socket address bridge reference.",
682
+ },
683
+ {
684
+ name: "_dgramSocketSetBufferSizeRaw",
685
+ classification: "hardened",
686
+ rationale: "Host dgram socket buffer-size setter bridge reference.",
687
+ },
688
+ {
689
+ name: "_dgramSocketGetBufferSizeRaw",
690
+ classification: "hardened",
691
+ rationale: "Host dgram socket buffer-size getter bridge reference.",
692
+ },
613
693
  {
614
694
  name: "_batchResolveModules",
615
695
  classification: "hardened",
@@ -715,11 +795,26 @@ export const NODE_CUSTOM_GLOBAL_INVENTORY = [
715
795
  classification: "hardened",
716
796
  rationale: "Network Response API global — must not be replaceable by sandbox code.",
717
797
  },
798
+ {
799
+ name: "DOMException",
800
+ classification: "hardened",
801
+ rationale: "DOMException global stub for undici/bootstrap compatibility.",
802
+ },
803
+ {
804
+ name: "__importMetaResolve",
805
+ classification: "hardened",
806
+ rationale: "Internal import.meta.resolve helper for transformed ESM modules.",
807
+ },
718
808
  {
719
809
  name: "Blob",
720
810
  classification: "hardened",
721
811
  rationale: "Blob API global stub — must not be replaceable by sandbox code.",
722
812
  },
813
+ {
814
+ name: "File",
815
+ classification: "hardened",
816
+ rationale: "File API global stub — must not be replaceable by sandbox code.",
817
+ },
723
818
  {
724
819
  name: "FormData",
725
820
  classification: "hardened",
@@ -1,61 +1,16 @@
1
- import { InodeTable } from "../kernel/inode-table.js";
2
- import type { VirtualDirEntry, VirtualFileSystem, VirtualStat } from "../kernel/vfs.js";
3
1
  /**
4
- * A fully in-memory VirtualFileSystem backed by inode-aware Maps.
5
- * Used as the default filesystem for the browser sandbox and for tests.
6
- * Paths are always POSIX-style (forward slashes, rooted at "/").
2
+ * Factory for creating an in-memory VirtualFileSystem backed by ChunkedVFS.
3
+ *
4
+ * Replaces the old monolithic InMemoryFileSystem with
5
+ * ChunkedVFS(InMemoryMetadataStore + InMemoryBlockStore).
7
6
  */
8
- export declare class InMemoryFileSystem implements VirtualFileSystem {
9
- private inodeTable;
10
- private files;
11
- private fileContents;
12
- private dirs;
13
- private symlinks;
14
- constructor(inodeTable?: InodeTable);
15
- setInodeTable(inodeTable: InodeTable): void;
16
- getInodeForPath(path: string): number | null;
17
- readFileByInode(ino: number): Uint8Array;
18
- writeFileByInode(ino: number, content: Uint8Array): void;
19
- preadByInode(ino: number, offset: number, length: number): Uint8Array;
20
- statByInode(ino: number): VirtualStat;
21
- deleteInodeData(ino: number): void;
22
- private listDirEntries;
23
- readFile(path: string): Promise<Uint8Array>;
24
- readTextFile(path: string): Promise<string>;
25
- readDir(path: string): Promise<string[]>;
26
- readDirWithTypes(path: string): Promise<VirtualDirEntry[]>;
27
- writeFile(path: string, content: string | Uint8Array): Promise<void>;
28
- prepareOpenSync(path: string, flags: number): boolean;
29
- createDir(path: string): Promise<void>;
30
- mkdir(path: string, _options?: {
31
- recursive?: boolean;
32
- }): Promise<void>;
33
- private resolveIfSymlink;
34
- private resolveSymlink;
35
- private statForInode;
36
- private statEntry;
37
- exists(path: string): Promise<boolean>;
38
- stat(path: string): Promise<VirtualStat>;
39
- removeFile(path: string): Promise<void>;
40
- removeDir(path: string): Promise<void>;
41
- rename(oldPath: string, newPath: string): Promise<void>;
42
- symlink(target: string, linkPath: string): Promise<void>;
43
- readlink(path: string): Promise<string>;
44
- lstat(path: string): Promise<VirtualStat>;
45
- link(oldPath: string, newPath: string): Promise<void>;
46
- chmod(path: string, mode: number): Promise<void>;
47
- chown(path: string, uid: number, gid: number): Promise<void>;
48
- utimes(path: string, atime: number, mtime: number): Promise<void>;
49
- realpath(path: string): Promise<string>;
50
- pread(path: string, offset: number, length: number): Promise<Uint8Array>;
51
- truncate(path: string, length: number): Promise<void>;
52
- private reindexInodes;
53
- private cloneInode;
54
- private allocateFileInode;
55
- private allocateDirectoryInode;
56
- private updateFileMetadata;
57
- private requirePathInode;
58
- private requireFileInode;
59
- private requireInode;
60
- }
61
- export declare function createInMemoryFileSystem(): InMemoryFileSystem;
7
+ import type { VirtualFileSystem } from "../kernel/vfs.js";
8
+ /**
9
+ * Create an in-memory VirtualFileSystem using the chunked storage architecture.
10
+ *
11
+ * The returned VFS stores all data in memory via InMemoryMetadataStore and
12
+ * InMemoryBlockStore, composed through ChunkedVFS. It also includes a
13
+ * synchronous `prepareOpenSync` method used by the kernel for O_CREAT/O_EXCL/O_TRUNC
14
+ * handling during fdOpen.
15
+ */
16
+ export declare function createInMemoryFileSystem(): VirtualFileSystem;