Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:21:43+00:00 2026-06-12T08:21:43+00:00

Possible Duplicate: How to run user-submitted scripts securely in a node.js sandbox? I want

  • 0

Possible Duplicate:
How to run user-submitted scripts securely in a node.js sandbox?

I want that my user can create their own format function that work with a particular object. I find two ways of doing it but I don’t know if that functions can be hacked. It is run inside nodeJS.

//First way with eval (evil ?)
function convertObj(formula) {
   return function (obj) {
        return eval(formula);
    };
}

// Second way with function (same as eval ?)
function convertObj2(formula) {
  return new Function("obj", "return " + formula);
}

var inst = {
      "name": "BOB",
      "age": "30"    
    };

var formula = "obj.name.toLowerCase() + ' is ' + obj.age + ' years old'";

var next = convertObj(formula);
var next2 = convertObj2(formula);

document.write('<p>' + next(inst) + '</p>');
document.write('<p>' + next2(inst) + '</p>');​

Print

bob is 30 years old
bob is 30 years old

The example is also available at http://jsfiddle.net/DeWYy/2/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:21:44+00:00Added an answer on June 12, 2026 at 8:21 am

    Both are vulnerable, because you are literally leaving anyone run anything without any control.

    What you probably want to do is run the code inside a sandbox. There are library that will help you with that (a quick Google search comes up with Sandbox). Do note that even if you run user-submitted code in a sandbox there will always be risk, but they are mostly mitigated. So unless you run a critical service, it can be consider secure.

    I also recommend you to take a look at this question about running user-submitted code securely.

    • How to run user-submitted scripts securely in a node.js sandbox?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can I run from command line program created by Eclipse? I am
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How can I write a Java application that can update itself at
Possible Duplicate: Run javascript function when user finishes typing instead of on key up?
Possible Duplicate: Can't run a ruby hello world application in Aptana I've just installed
Possible Duplicate: Getting python.exe path at run time I have a python app that
Possible Duplicate: Can I run a .NET garbage collection from WinDbg? I'm debugging a
Possible Duplicate: How can I run Perl system commands in the background? I have
Possible Duplicate: ASP.Net:Best way to run scheduled tasks I have to make a scheduled
Possible Duplicate: Change icon on of an App in iOS 4 in run-time Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.