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

  • Home
  • SEARCH
  • 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 4597616
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:16:57+00:00 2026-05-21T23:16:57+00:00

I was making(not now, but still I’m curious about this one) a game using

  • 0

I was making(not now, but still I’m curious about this one) a game using HTML5 and JS, and one I wanted was that people can insert custom script, but secure.

function executeCustomJS(code){
 eval(code);//bad
}

Of course this code is very bad, because if code is something like document.location.href='http://meatspn.com', then the result will become very…(…)

One solution I found is escaping(like eval -> ___eval___) all keywords, and un-escape keywords in whitelist, such as ‘while’, ‘for’, ‘if’, ‘var’, ‘true’, ‘false’, … and ‘func0’, ‘func1’, …., which are something (like API) of the game and are secure.

For example,

function executeCustomJS(code){
 code = code.replace(/(Keyword RegEx)/g,'___$1___');
 /*unescape keywords in whitelist*/
 eval(code);
}

I haven’t made RegEx and things in comment, but that’s not the question.

Let’s assume strings in code are not escaped, there’s no function which can be made by escaping a string, and ‘eval’, ‘window’, ‘document’, ‘alert’, ‘location’ are NOT in the whitelist. Still some people can execute code like while(true){}, they can’t execute any code like document.location.href='http://meatspn.com'.

Is this method secure? Or, is better way exists or not?

  • 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-05-21T23:16:57+00:00Added an answer on May 21, 2026 at 11:16 pm

    I recommend you expose a limited scripting language over JSON. So document a scripting engine that requires you to create a JSON object as your code.

    This has the large advantage that it’s impossible to inject bad code into JSON because it’s just data.

    So you can create some kind of declarative syntax for your scripting code. For example

    {
        "0": {
            "Action": "move",
            "X": 10,
            "Y": -5
        },
        "1": {
            "Action": "emote",
            "type": "dance"
        }
    }
    

    Now what is a good design for a tiny declarative scripting language is a completely different question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found a similar post about this but still not sure. As I am
I'm making a php web application which stores user specific information that is not
I have a large query (not written by me, but I'm making some modifications).
This is beyond both making sense and my control. That being said here is
I am making a app in this app i am using uitextfield on table
I had a look at some other questions but I'm still not sure how
Hi there I developed an applicaiton that uses SQLlite database but after making setup
I'm making a program which the user build directories (not in windows, in my
I was thinking of making a small tool. It is not important what the
I'm making a simple Image Debugger Visualizer. Code is below. I'm not sure if

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.