Skip to content

[FR] Disable eval() usage by defaultΒ #62434

@PR3C14D0

Description

@PR3C14D0

What is the problem this feature will solve?

eval() and Function() in Node.js allow executing arbitrary code at runtime. While powerful, they are a common vector for security vulnerabilities and accidental code injection. Currently, eval() is enabled by default, which means that even minor mistakes or untrusted dependencies can execute code dynamically, increasing security risks.

By disabling eval() by default, Node.js can provide a safer runtime out of the box. This change encourages developers to use safer alternatives such as vm or strict sandboxing, reducing potential attack surfaces in Node.js applications.

As you can see in this commit, you can somehow insert arbitrary code on a commit and not even notice.

This video (in spanish, by @midudev), explains how they attacked him through this method. Is crazy

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

Introduce a new opt-in flag --enable-eval in Node.js.

  • Default behavior: eval() and Function() are disabled in the runtime. Any attempt to use them without the flag will throw an error.

  • Opt-in: Users can explicitly enable eval() for legacy applications or specific use cases by passing node --enable-eval index.js

  • Benefits:

    • Improves default security for Node.js applications.
    • Prevents accidental dynamic code execution in production.
    • Allows developers to consciously decide when they need eval().

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions