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 278205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:12:05+00:00 2026-05-12T01:12:05+00:00

From a security perspective, I can see simply doing an ‘eval’ on incoming JSON

  • 0

From a security perspective, I can see simply doing an ‘eval’ on incoming JSON data as a critical mistake. If you got data like below you’d have some problems.

{ someData:((function() { 
    alert("i'm in ur code hackin' ur page"); 
})()) }

I wondered what do most popular Javascript libraries do? Is it a manual parse or simply an eval?

[Edit]

I’m not asking if I should eval/parse – I was asking what methods some of the popular Javascript libraries used (jQuery, Prototype, etc…)

  • 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-12T01:12:05+00:00Added an answer on May 12, 2026 at 1:12 am

    Here’s what the official JavaScript parser does:

    // In the second stage, we run the text against regular expressions that look
    // for non-JSON patterns. We are especially concerned with '()' and 'new'
    // because they can cause invocation, and '=' because it can cause mutation.
    // But just to be safe, we want to reject all unexpected forms.
    
    // We split the second stage into 4 regexp operations in order to work around
    // crippling inefficiencies in IE's and Safari's regexp engines. First we
    // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
    // replace all simple value tokens with ']' characters. Third, we delete all
    // open brackets that follow a colon or comma or that begin the text. Finally,
    // we look to see that the remaining characters are only whitespace or ']' or
    // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
    
    if (/^[\],:{}\s]*$/.
        test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
        replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
        replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
    
    // In the third stage we use the eval function to compile the text into a
    // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
    // in JavaScript: it can begin a block or an object literal. We wrap the text
    // in parens to eliminate the ambiguity.
    
        j = eval('(' + text + ')');
    
        ...
    

    With the exception of the built-in JSON parsing support that is in modern browsers, this is what all (library-based) secure JSON parsers do (ie, a regex test before eval).

    Secure libraries (in addition to the official json2 implementation)

    Prototype’s isJSON function.

    Mootools’ JSON.decode function (again, via a regex test before eval).

    Unsecure libraries:

    dojo’s fromJson does not provide secure evaling. Here is their entire implementation (minus comments):

    dojo.fromJson = function(json) {
        return eval("(" + json + ")");
    }
    

    jQuery does not provide secure JSON eval‘ing, but see the official plugin’s secureEvalJSON function (line 143).

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

Sidebar

Ask A Question

Stats

  • Questions 204k
  • Answers 204k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This can be achieved using fileno, dup and dup2 calls.… May 12, 2026 at 8:44 pm
  • Editorial Team
    Editorial Team added an answer Escape it: &amp;. string item = "<field>http://mylink.com/page.aspx?id=1&amp;disp=2</field>"; May 12, 2026 at 8:44 pm
  • Editorial Team
    Editorial Team added an answer There is no best practice. The primary thing you should… May 12, 2026 at 8:44 pm

Related Questions

From a security perspective, I can see simply doing an 'eval' on incoming JSON
I'm looking at an existing site and they are using separate databases. The databases
At work we have two competing theories for salts. The products I work on
I am running SQL Server Reporting Services on SQL Server 2008 Standard and trying
I've always used a proper per-entry salt string when hashing passwords for database storage.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.