@secure-exec/core 0.1.1-rc.3 → 0.2.0-rc.1
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/esm-compiler.d.ts +5 -1
- package/dist/esm-compiler.js +5 -1
- package/dist/fs-helpers.d.ts +1 -1
- package/dist/generated/isolate-runtime.d.ts +15 -15
- package/dist/generated/isolate-runtime.js +15 -15
- package/dist/index.d.ts +24 -5
- package/dist/index.js +23 -3
- package/dist/isolate-runtime/apply-custom-global-policy.js +3 -3
- package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +2 -2
- package/dist/isolate-runtime/apply-timing-mitigation-off.js +2 -2
- package/dist/isolate-runtime/bridge-attach.js +2 -2
- package/dist/isolate-runtime/bridge-initial-globals.js +145 -6
- package/dist/isolate-runtime/eval-script-result.js +1 -1
- package/dist/isolate-runtime/global-exposure-helpers.js +2 -2
- package/dist/isolate-runtime/init-commonjs-module-globals.js +2 -2
- package/dist/isolate-runtime/override-process-cwd.js +1 -1
- package/dist/isolate-runtime/override-process-env.js +1 -1
- package/dist/isolate-runtime/require-setup.js +1600 -338
- package/dist/isolate-runtime/set-commonjs-file-globals.js +2 -2
- package/dist/isolate-runtime/set-stdin-data.js +1 -1
- package/dist/isolate-runtime/setup-dynamic-import.js +47 -19
- package/dist/isolate-runtime/setup-fs-facade.js +62 -23
- package/dist/kernel/command-registry.d.ts +44 -0
- package/dist/kernel/command-registry.js +114 -0
- package/dist/kernel/device-layer.d.ts +12 -0
- package/dist/kernel/device-layer.js +262 -0
- package/dist/kernel/dns-cache.d.ts +29 -0
- package/dist/kernel/dns-cache.js +52 -0
- package/dist/kernel/fd-table.d.ts +84 -0
- package/dist/kernel/fd-table.js +278 -0
- package/dist/kernel/file-lock.d.ts +34 -0
- package/dist/kernel/file-lock.js +123 -0
- package/dist/kernel/host-adapter.d.ts +50 -0
- package/dist/kernel/host-adapter.js +8 -0
- package/dist/kernel/index.d.ts +36 -0
- package/dist/kernel/index.js +34 -0
- package/dist/kernel/inode-table.d.ts +43 -0
- package/dist/kernel/inode-table.js +85 -0
- package/dist/kernel/kernel.d.ts +9 -0
- package/dist/kernel/kernel.js +1396 -0
- package/dist/kernel/permissions.d.ts +27 -0
- package/dist/kernel/permissions.js +118 -0
- package/dist/kernel/pipe-manager.d.ts +64 -0
- package/dist/kernel/pipe-manager.js +267 -0
- package/dist/kernel/proc-layer.d.ts +11 -0
- package/dist/kernel/proc-layer.js +501 -0
- package/dist/kernel/process-table.d.ts +124 -0
- package/dist/kernel/process-table.js +631 -0
- package/dist/kernel/pty.d.ts +108 -0
- package/dist/kernel/pty.js +541 -0
- package/dist/kernel/socket-table.d.ts +305 -0
- package/dist/kernel/socket-table.js +1124 -0
- package/dist/kernel/timer-table.d.ts +54 -0
- package/dist/kernel/timer-table.js +108 -0
- package/dist/kernel/types.d.ts +500 -0
- package/dist/kernel/types.js +89 -0
- package/dist/kernel/user.d.ts +29 -0
- package/dist/kernel/user.js +35 -0
- package/dist/kernel/vfs.d.ts +54 -0
- package/dist/kernel/vfs.js +8 -0
- package/dist/kernel/wait.d.ts +45 -0
- package/dist/kernel/wait.js +112 -0
- package/dist/kernel/wstatus.d.ts +21 -0
- package/dist/kernel/wstatus.js +33 -0
- package/dist/module-resolver.d.ts +4 -0
- package/dist/module-resolver.js +4 -0
- package/dist/package-bundler.d.ts +6 -1
- package/dist/runtime-driver.d.ts +3 -1
- package/dist/shared/bridge-contract.d.ts +329 -20
- package/dist/shared/bridge-contract.js +60 -5
- package/dist/shared/console-formatter.js +8 -4
- package/dist/shared/global-exposure.js +269 -19
- package/dist/shared/in-memory-fs.d.ts +30 -11
- package/dist/shared/in-memory-fs.js +383 -109
- package/dist/shared/permissions.d.ts +4 -6
- package/dist/shared/permissions.js +19 -39
- package/dist/types.d.ts +8 -159
- package/dist/types.js +5 -0
- package/package.json +12 -22
- package/dist/bridge/active-handles.d.ts +0 -22
- package/dist/bridge/active-handles.js +0 -55
- package/dist/bridge/child-process.d.ts +0 -99
- package/dist/bridge/child-process.js +0 -670
- package/dist/bridge/fs.d.ts +0 -281
- package/dist/bridge/fs.js +0 -2235
- package/dist/bridge/index.d.ts +0 -10
- package/dist/bridge/index.js +0 -41
- package/dist/bridge/module.d.ts +0 -75
- package/dist/bridge/module.js +0 -308
- package/dist/bridge/network.d.ts +0 -350
- package/dist/bridge/network.js +0 -2050
- package/dist/bridge/os.d.ts +0 -13
- package/dist/bridge/os.js +0 -256
- package/dist/bridge/polyfills.d.ts +0 -2
- package/dist/bridge/polyfills.js +0 -11
- package/dist/bridge/process.d.ts +0 -89
- package/dist/bridge/process.js +0 -1015
- package/dist/bridge.js +0 -12496
- package/dist/python-runtime.d.ts +0 -16
- package/dist/python-runtime.js +0 -45
- package/dist/runtime.d.ts +0 -31
- package/dist/runtime.js +0 -69
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @secure-exec/kernel
|
|
3
|
+
*
|
|
4
|
+
* OS kernel providing VFS, FD table, process table, device layer,
|
|
5
|
+
* pipes, command registry, and permissions. All runtimes share the
|
|
6
|
+
* same kernel instance.
|
|
7
|
+
*/
|
|
8
|
+
export { createKernel } from "./kernel.js";
|
|
9
|
+
export type { Kernel, KernelOptions, KernelInterface, ExecOptions, ExecResult, SpawnOptions, ManagedProcess, RuntimeDriver, ProcessContext, DriverProcess, ProcessEntry, ProcessInfo, FDStat, FileDescription, FDEntry, Pipe, Permissions, PermissionDecision, PermissionCheck, FsAccessRequest, NetworkAccessRequest, ChildProcessAccessRequest, EnvAccessRequest, KernelErrorCode, SignalDisposition, SignalHandler, ProcessSignalState, Termios, TermiosCC, OpenShellOptions, ShellHandle, ConnectTerminalOptions, } from "./types.js";
|
|
10
|
+
export { KernelError, defaultTermios } from "./types.js";
|
|
11
|
+
export type { VirtualFileSystem, VirtualDirEntry, VirtualStat, } from "./vfs.js";
|
|
12
|
+
export { FDTableManager, ProcessFDTable } from "./fd-table.js";
|
|
13
|
+
export { ProcessTable } from "./process-table.js";
|
|
14
|
+
export { createDeviceLayer } from "./device-layer.js";
|
|
15
|
+
export { createProcLayer, createProcessScopedFileSystem, resolveProcSelfPath, } from "./proc-layer.js";
|
|
16
|
+
export { PipeManager } from "./pipe-manager.js";
|
|
17
|
+
export { PtyManager } from "./pty.js";
|
|
18
|
+
export type { LineDisciplineConfig } from "./pty.js";
|
|
19
|
+
export { CommandRegistry } from "./command-registry.js";
|
|
20
|
+
export { FileLockManager, LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB } from "./file-lock.js";
|
|
21
|
+
export { WaitHandle, WaitQueue } from "./wait.js";
|
|
22
|
+
export { InodeTable } from "./inode-table.js";
|
|
23
|
+
export type { Inode } from "./inode-table.js";
|
|
24
|
+
export { TimerTable } from "./timer-table.js";
|
|
25
|
+
export type { KernelTimer, TimerTableOptions } from "./timer-table.js";
|
|
26
|
+
export { DnsCache } from "./dns-cache.js";
|
|
27
|
+
export type { DnsCacheOptions } from "./dns-cache.js";
|
|
28
|
+
export { UserManager } from "./user.js";
|
|
29
|
+
export type { UserConfig } from "./user.js";
|
|
30
|
+
export { SocketTable } from "./socket-table.js";
|
|
31
|
+
export type { KernelSocket, SocketState, SockAddr, InetAddr, UnixAddr, UdpDatagram, } from "./socket-table.js";
|
|
32
|
+
export { AF_INET, AF_INET6, AF_UNIX, SOCK_STREAM, SOCK_DGRAM, SOL_SOCKET, IPPROTO_TCP, SO_REUSEADDR, SO_KEEPALIVE, SO_RCVBUF, SO_SNDBUF, TCP_NODELAY, MSG_PEEK, MSG_DONTWAIT, MSG_NOSIGNAL, MAX_DATAGRAM_SIZE, MAX_UDP_QUEUE_DEPTH, S_IFSOCK, isInetAddr, isUnixAddr, addrKey, optKey, } from "./socket-table.js";
|
|
33
|
+
export type { HostNetworkAdapter, HostSocket, HostListener, HostUdpSocket, DnsResult, } from "./host-adapter.js";
|
|
34
|
+
export { wrapFileSystem, filterEnv, checkChildProcess, allowAll, allowAllFs, allowAllNetwork, allowAllChildProcess, allowAllEnv, } from "./permissions.js";
|
|
35
|
+
export { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, FD_CLOEXEC, SEEK_SET, SEEK_CUR, SEEK_END, FILETYPE_UNKNOWN, FILETYPE_CHARACTER_DEVICE, FILETYPE_DIRECTORY, FILETYPE_REGULAR_FILE, FILETYPE_SYMBOLIC_LINK, FILETYPE_PIPE, SIGHUP, SIGINT, SIGQUIT, SIGKILL, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, SIGWINCH, SA_RESTART, SA_RESETHAND, SA_NOCLDSTOP, SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK, WNOHANG, } from "./types.js";
|
|
36
|
+
export { encodeExitStatus, encodeSignalStatus, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, } from "./wstatus.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @secure-exec/kernel
|
|
3
|
+
*
|
|
4
|
+
* OS kernel providing VFS, FD table, process table, device layer,
|
|
5
|
+
* pipes, command registry, and permissions. All runtimes share the
|
|
6
|
+
* same kernel instance.
|
|
7
|
+
*/
|
|
8
|
+
// Kernel factory
|
|
9
|
+
export { createKernel } from "./kernel.js";
|
|
10
|
+
// Structured kernel error and termios defaults
|
|
11
|
+
export { KernelError, defaultTermios } from "./types.js";
|
|
12
|
+
// Kernel components (for direct use / testing)
|
|
13
|
+
export { FDTableManager, ProcessFDTable } from "./fd-table.js";
|
|
14
|
+
export { ProcessTable } from "./process-table.js";
|
|
15
|
+
export { createDeviceLayer } from "./device-layer.js";
|
|
16
|
+
export { createProcLayer, createProcessScopedFileSystem, resolveProcSelfPath, } from "./proc-layer.js";
|
|
17
|
+
export { PipeManager } from "./pipe-manager.js";
|
|
18
|
+
export { PtyManager } from "./pty.js";
|
|
19
|
+
export { CommandRegistry } from "./command-registry.js";
|
|
20
|
+
export { FileLockManager, LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB } from "./file-lock.js";
|
|
21
|
+
export { WaitHandle, WaitQueue } from "./wait.js";
|
|
22
|
+
export { InodeTable } from "./inode-table.js";
|
|
23
|
+
export { TimerTable } from "./timer-table.js";
|
|
24
|
+
export { DnsCache } from "./dns-cache.js";
|
|
25
|
+
export { UserManager } from "./user.js";
|
|
26
|
+
// Socket table
|
|
27
|
+
export { SocketTable } from "./socket-table.js";
|
|
28
|
+
export { AF_INET, AF_INET6, AF_UNIX, SOCK_STREAM, SOCK_DGRAM, SOL_SOCKET, IPPROTO_TCP, SO_REUSEADDR, SO_KEEPALIVE, SO_RCVBUF, SO_SNDBUF, TCP_NODELAY, MSG_PEEK, MSG_DONTWAIT, MSG_NOSIGNAL, MAX_DATAGRAM_SIZE, MAX_UDP_QUEUE_DEPTH, S_IFSOCK, isInetAddr, isUnixAddr, addrKey, optKey, } from "./socket-table.js";
|
|
29
|
+
// Permissions
|
|
30
|
+
export { wrapFileSystem, filterEnv, checkChildProcess, allowAll, allowAllFs, allowAllNetwork, allowAllChildProcess, allowAllEnv, } from "./permissions.js";
|
|
31
|
+
// Constants
|
|
32
|
+
export { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, FD_CLOEXEC, SEEK_SET, SEEK_CUR, SEEK_END, FILETYPE_UNKNOWN, FILETYPE_CHARACTER_DEVICE, FILETYPE_DIRECTORY, FILETYPE_REGULAR_FILE, FILETYPE_SYMBOLIC_LINK, FILETYPE_PIPE, SIGHUP, SIGINT, SIGQUIT, SIGKILL, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, SIGWINCH, SA_RESTART, SA_RESETHAND, SA_NOCLDSTOP, SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK, WNOHANG, } from "./types.js";
|
|
33
|
+
// POSIX wstatus encoding/decoding
|
|
34
|
+
export { encodeExitStatus, encodeSignalStatus, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, } from "./wstatus.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inode table with refcounting and deferred unlink.
|
|
3
|
+
*
|
|
4
|
+
* Provides a POSIX-style inode layer: hard link counts (nlink),
|
|
5
|
+
* open FD reference counting (openRefCount), and deferred deletion
|
|
6
|
+
* when nlink reaches 0 but FDs are still open.
|
|
7
|
+
*/
|
|
8
|
+
export interface Inode {
|
|
9
|
+
readonly ino: number;
|
|
10
|
+
nlink: number;
|
|
11
|
+
openRefCount: number;
|
|
12
|
+
mode: number;
|
|
13
|
+
uid: number;
|
|
14
|
+
gid: number;
|
|
15
|
+
size: number;
|
|
16
|
+
atime: Date;
|
|
17
|
+
mtime: Date;
|
|
18
|
+
ctime: Date;
|
|
19
|
+
birthtime: Date;
|
|
20
|
+
}
|
|
21
|
+
export declare class InodeTable {
|
|
22
|
+
private inodes;
|
|
23
|
+
private nextIno;
|
|
24
|
+
/** Allocate a new inode with the given mode, uid, gid. Returns the inode. */
|
|
25
|
+
allocate(mode: number, uid: number, gid: number): Inode;
|
|
26
|
+
/** Look up an inode by number. */
|
|
27
|
+
get(ino: number): Inode | null;
|
|
28
|
+
/** Increment hard link count (new directory entry pointing to this inode). */
|
|
29
|
+
incrementLinks(ino: number): void;
|
|
30
|
+
/** Decrement hard link count (directory entry removed). */
|
|
31
|
+
decrementLinks(ino: number): void;
|
|
32
|
+
/** Increment open FD reference count. */
|
|
33
|
+
incrementOpenRefs(ino: number): void;
|
|
34
|
+
/** Decrement open FD reference count. */
|
|
35
|
+
decrementOpenRefs(ino: number): void;
|
|
36
|
+
/** True when nlink=0 AND openRefCount=0 — inode data can be freed. */
|
|
37
|
+
shouldDelete(ino: number): boolean;
|
|
38
|
+
/** Remove the inode from the table. Called after shouldDelete returns true. */
|
|
39
|
+
delete(ino: number): void;
|
|
40
|
+
/** Number of inodes in the table. */
|
|
41
|
+
get size(): number;
|
|
42
|
+
private requireInode;
|
|
43
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inode table with refcounting and deferred unlink.
|
|
3
|
+
*
|
|
4
|
+
* Provides a POSIX-style inode layer: hard link counts (nlink),
|
|
5
|
+
* open FD reference counting (openRefCount), and deferred deletion
|
|
6
|
+
* when nlink reaches 0 but FDs are still open.
|
|
7
|
+
*/
|
|
8
|
+
import { KernelError } from "./types.js";
|
|
9
|
+
export class InodeTable {
|
|
10
|
+
inodes = new Map();
|
|
11
|
+
nextIno = 1;
|
|
12
|
+
/** Allocate a new inode with the given mode, uid, gid. Returns the inode. */
|
|
13
|
+
allocate(mode, uid, gid) {
|
|
14
|
+
const now = new Date();
|
|
15
|
+
const inode = {
|
|
16
|
+
ino: this.nextIno++,
|
|
17
|
+
nlink: 1,
|
|
18
|
+
openRefCount: 0,
|
|
19
|
+
mode,
|
|
20
|
+
uid,
|
|
21
|
+
gid,
|
|
22
|
+
size: 0,
|
|
23
|
+
atime: now,
|
|
24
|
+
mtime: now,
|
|
25
|
+
ctime: now,
|
|
26
|
+
birthtime: now,
|
|
27
|
+
};
|
|
28
|
+
this.inodes.set(inode.ino, inode);
|
|
29
|
+
return inode;
|
|
30
|
+
}
|
|
31
|
+
/** Look up an inode by number. */
|
|
32
|
+
get(ino) {
|
|
33
|
+
return this.inodes.get(ino) ?? null;
|
|
34
|
+
}
|
|
35
|
+
/** Increment hard link count (new directory entry pointing to this inode). */
|
|
36
|
+
incrementLinks(ino) {
|
|
37
|
+
const inode = this.requireInode(ino);
|
|
38
|
+
inode.nlink++;
|
|
39
|
+
inode.ctime = new Date();
|
|
40
|
+
}
|
|
41
|
+
/** Decrement hard link count (directory entry removed). */
|
|
42
|
+
decrementLinks(ino) {
|
|
43
|
+
const inode = this.requireInode(ino);
|
|
44
|
+
if (inode.nlink <= 0) {
|
|
45
|
+
throw new KernelError("EINVAL", `inode ${ino} nlink already 0`);
|
|
46
|
+
}
|
|
47
|
+
inode.nlink--;
|
|
48
|
+
inode.ctime = new Date();
|
|
49
|
+
}
|
|
50
|
+
/** Increment open FD reference count. */
|
|
51
|
+
incrementOpenRefs(ino) {
|
|
52
|
+
const inode = this.requireInode(ino);
|
|
53
|
+
inode.openRefCount++;
|
|
54
|
+
}
|
|
55
|
+
/** Decrement open FD reference count. */
|
|
56
|
+
decrementOpenRefs(ino) {
|
|
57
|
+
const inode = this.requireInode(ino);
|
|
58
|
+
if (inode.openRefCount <= 0) {
|
|
59
|
+
throw new KernelError("EINVAL", `inode ${ino} openRefCount already 0`);
|
|
60
|
+
}
|
|
61
|
+
inode.openRefCount--;
|
|
62
|
+
}
|
|
63
|
+
/** True when nlink=0 AND openRefCount=0 — inode data can be freed. */
|
|
64
|
+
shouldDelete(ino) {
|
|
65
|
+
const inode = this.inodes.get(ino);
|
|
66
|
+
if (!inode)
|
|
67
|
+
return false;
|
|
68
|
+
return inode.nlink === 0 && inode.openRefCount === 0;
|
|
69
|
+
}
|
|
70
|
+
/** Remove the inode from the table. Called after shouldDelete returns true. */
|
|
71
|
+
delete(ino) {
|
|
72
|
+
this.inodes.delete(ino);
|
|
73
|
+
}
|
|
74
|
+
/** Number of inodes in the table. */
|
|
75
|
+
get size() {
|
|
76
|
+
return this.inodes.size;
|
|
77
|
+
}
|
|
78
|
+
requireInode(ino) {
|
|
79
|
+
const inode = this.inodes.get(ino);
|
|
80
|
+
if (!inode) {
|
|
81
|
+
throw new KernelError("ENOENT", `inode ${ino} not found`);
|
|
82
|
+
}
|
|
83
|
+
return inode;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel implementation.
|
|
3
|
+
*
|
|
4
|
+
* The kernel is the OS. It owns VFS, FD table, process table, device layer,
|
|
5
|
+
* pipe manager, command registry, and permissions. Runtimes are execution
|
|
6
|
+
* engines that make "syscalls" to the kernel.
|
|
7
|
+
*/
|
|
8
|
+
import type { Kernel, KernelOptions } from "./types.js";
|
|
9
|
+
export declare function createKernel(options: KernelOptions): Kernel;
|