Skip to content

fix(ext/node): improve worker_threads path validation and error handling#32791

Merged
bartlomieju merged 3 commits intodenoland:mainfrom
bartlomieju:fix/worker-threads-path-validation
Mar 18, 2026
Merged

fix(ext/node): improve worker_threads path validation and error handling#32791
bartlomieju merged 3 commits intodenoland:mainfrom
bartlomieju:fix/worker-threads-path-validation

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

@bartlomieju bartlomieju commented Mar 17, 2026

Summary

  • Implement ERR_WORKER_PATH error class for proper Node.js-compatible path validation in worker_threads.Worker
  • Reject string URL specifiers (file://, data:, http://, https://) with ERR_WORKER_PATH (must use new URL())
  • Reject relative paths that don't start with ./ or ../ (or .\/..\ on Windows)
  • Throw ERR_INVALID_URL_SCHEME for URL objects with non-file/data protocols
  • Validate eval: true requires a string specifier, not a URL object
  • Preserve native error constructor (SyntaxError, TypeError, etc.) on worker error events so err.constructor matches
  • Fix spec tests to use new URL() instead of import.meta.resolve() strings

Newly passing Node.js compat tests

  • test-worker-unsupported-path.js
  • test-worker-unsupported-eval-on-url.mjs
  • test-worker-syntax-error.js
  • test-worker-syntax-error-file.js

Test plan

  • All 4 newly enabled Node.js compat tests pass
  • message_port and message_port_transfer spec tests pass
  • Existing worker_threads unit tests pass
  • Format and lint clean

🤖 Generated with Claude Code

@bartlomieju bartlomieju requested a review from littledivy March 17, 2026 20:56
bartlomieju and others added 2 commits March 17, 2026 22:00
- Allow .\ and ..\ (Windows backslash) in worker path validation
- Use correct native error constructor (SyntaxError, TypeError, etc.)
  for worker error events so err.constructor matches
- Fix spec tests to use new URL() instead of import.meta.resolve()
  string for Worker specifiers
- Enable test-worker-syntax-error.js and test-worker-syntax-error-file.js

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bartlomieju bartlomieju changed the title fix(ext/node): worker_threads validation fix(ext/node): improve worker_threads path validation and error handling Mar 17, 2026
Copy link
Copy Markdown
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju bartlomieju merged commit cca89e6 into denoland:main Mar 18, 2026
113 checks passed
@bartlomieju bartlomieju deleted the fix/worker-threads-path-validation branch March 18, 2026 06:19
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.

2 participants