Skip to content

feat: Add deny-by-default module allowlist - #5

Merged
ThomasHartDev merged 1 commit into
mainfrom
thomas/feat/capability-allowlist
Jul 26, 2026
Merged

feat: Add deny-by-default module allowlist#5
ThomasHartDev merged 1 commit into
mainfrom
thomas/feat/capability-allowlist

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

Adds an explicit allowedModules option so untrusted code only gets require when the caller opts in. Empty list still injects a require that denies everything; a non-empty list is exact-match only with bare and node: treated as the same id. Relative and absolute paths are dropped from the allowlist and refused at load time so nothing reopens filesystem resolution through a sneaky entry. Wired into both run and runInWorker, and the allowlist gate wins over a grant-supplied require so you cannot accidentally hand in the full host loader while meaning to restrict it. Had a small gotcha on the worker tier where freezeRealm freezes Error.prototype and a plain err.name assignment blows up, so the gate sets the error name with defineProperty instead.

Gate require behind an explicit allowedModules list on both the in-process
and worker_threads tiers. Paths are always refused; bare and node: ids match.
@ThomasHartDev
ThomasHartDev merged commit a1f72e6 into main Jul 26, 2026
1 check passed
@ThomasHartDev
ThomasHartDev deleted the thomas/feat/capability-allowlist branch July 26, 2026 21:30
Comment thread src/modules.ts
Comment thread src/sandbox.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant