Skip to content

Add support for "--disallow-code-generation-from-strings" flag to workers #60371

Closed as not planned

Description

@capricorn86

What is the problem this feature will solve?

I'm the creator and main maintainer of happy-dom. We recommend users to use the flags --disallow-code-generation-from-strings and --frozen-intrinsics when Javascript evaluation is enabled in happy-dom to make it harder for a potential attacker to escape a VM context and execute code at process level.

One of the packages uses Workers and it would be great if these flags could be sent in to "execArgv" when creating the Worker. It seems like --frozen-intrinsics is already supported.

What is the feature you are proposing to solve the problem?

Add support for --disallow-code-generation-from-strings to "execArgv" in Worker.

Example:

const worker = new Worker(new URL('ServerRendererWorker.js', import.meta.url), {
   execArgv: ['--disallow-code-generation-from-strings']
});

What alternatives have you considered?

No response

Activity

  1. added
    workerIssues and PRs related to the worker_threads module and Worker API.
    on Oct 22, 2025
  2. juanarbol commented on Oct 22, 2025

    @juanarbol
    Member

    I'll take a look, thanks! This is a very interesting feature request

  3. juanarbol commented on Oct 25, 2025

    @juanarbol
    Member

    Based on docs

    V8 options (such as --max-old-space-size) and options that affect the process (such as --title) are not supported. If set, this is provided as process.execArgv inside the worker. By default, options are inherited from the parent thread.

    I'll ping @nodejs/workers, can I ask why aren't v8 options supported for a worker thread? Is there a feasible way to support them? Or at least a handful of them? This --disallow-code-generation-from-strings seems a quite interesting security feature -as OP mentioned-.

    Refs: https://nodejs.org/docs/latest/api/worker_threads.html#new-workerfilename-options

  4. legendecas commented on Nov 2, 2025

    @legendecas
    Member

    can I ask why aren't v8 options supported for a worker thread?

    Most V8 flags are per process flags. Changing it for one worker thread will also change the flag value for other threads.

    This per-process storage applies to --disallow-code-generation-from-strings as well. It is the default value for new context's code generation setting, for all threads.

    In addition, --disallow-code-generation-from-strings is not a security flag. It is implemented in V8 and only disallows eval and new Function: #58328

  5. capricorn86 commented on Nov 3, 2025

    @capricorn86
    Author

    Thank you for looking into this!

  6. github-actions commented on Jun 2, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  7. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 2, 2026
  8. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 240 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.workerIssues and PRs related to the worker_threads module and Worker API.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions