GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add tests ensuring worker threads cannot access internals · nodejs/node@beba631

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-worker-internal-modules.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-worker-internal-modules.mjs‎

Copy file name to clipboard
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import '../common/index.mjs';
2+
import tmpdir from '../common/tmpdir.js';
3+
import assert from 'node:assert/strict';
4+
import { once } from 'node:events';
5+
import fs from 'node:fs/promises';
6+
import { describe, test, before } from 'node:test';
7+
import { Worker } from 'node:worker_threads';
8+
9+
const accessInternalsSource = `
10+
import 'node:internal/freelist';
11+
`;
12+
13+
function convertScriptSourceToDataUrl(script) {
14+
return new URL(`data:text/javascript,${encodeURIComponent(script)}`);
15+
}
16+
17+
describe('Worker threads should not be able to access internal modules', () => {
18+
before(() => tmpdir.refresh());
19+
20+
test('worker instantiated with module file path', async () => {
21+
const moduleFilepath = tmpdir.resolve('test-worker-internal-modules.mjs');
22+
await fs.writeFile(moduleFilepath, accessInternalsSource);
23+
const w = new Worker(moduleFilepath);
24+
await assert.rejects(once(w, 'exit'), { code: 'ERR_UNKNOWN_BUILTIN_MODULE' });
25+
});
26+
27+
test('worker instantiated with module source', async () => {
28+
const w = new Worker(accessInternalsSource, { eval: true });
29+
await assert.rejects(once(w, 'exit'), { code: 'ERR_UNKNOWN_BUILTIN_MODULE' });
30+
});
31+
32+
test('worker instantiated with data: URL', async () => {
33+
const w = new Worker(convertScriptSourceToDataUrl(accessInternalsSource));
34+
await assert.rejects(once(w, 'exit'), { code: 'ERR_UNKNOWN_BUILTIN_MODULE' });
35+
});
36+
});

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.