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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:50:40+00:00 2026-05-24T21:50:40+00:00

Mozilla’s Content Security Policy disallows the use of javascript eval function as well as

  • 0

Mozilla’s Content Security Policy disallows the use of javascript eval function as well as inline scripts. They claim that all instances of eval can be replaced by another (hopefully safer) function. I agree in most scenarios, Javascript eval can be replaced, but I’m not sure whether the replacement is possible for every case.

My question is twofold:

  1. Is there a generic way to replace every javascript eval function? (doesn’t have to be safe)
  2. Is there a case where the Javascript eval cannot be replaced?
  • 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-24T21:50:41+00:00Added an answer on May 24, 2026 at 9:50 pm

    The most common uses which can be substituted are the following ones. I would certainly use these first.

    1. Accessing dynamic properties

      Do use: obj[keyAsVariable]

      Don’t use eval('obj.' + keyAsVariable)

    2. Parsing JSON

      Do use JSON.parse(data)

      Don’t use eval('(' + data + ')')

    3. Calculating user input

      Do use a certain library

      Don’t use eval(input)

    If really necessary, you can also send the script to a server which simply echoes it back, and you can request it as a script tag. It won’t use eval but still execute it. It isn’t safe as it’s sent twice over the Internet.

    var s = document.createElement('script')
    s.src = 'request_script?data=' + data;
    document.getElementsByTagName('head')[0].appendChild(s);
    

    request_script could be a file implemented in PHP, like the following. Again, it’s bad practice but is a generic way of circumventing eval.

    <?
    echo $_GET['data'];
    ?>
    

    You could say that this also automatically answers your second question with ‘no’.

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

Sidebar

Related Questions

i want https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind#Currying in PHP: $x = function ($a, $b) { echo $a .
stated here https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function the constructor property of an instance of a function object specifies
It sounds like Mozilla is having good luck improving JavaScript performance with TraceMonkey .
Example taken from Mozilla's help page <script type="text/javascript"> re = /(\w+)\s(\w+)/; str = "John
I use Firebug and the Mozilla JS console heavily, but every now and then
This is Mozilla's Code in Mozilla's Array.prototype.indexOf if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt) {
I use the webkit/mozilla border radius and box shadow CSS properties, but I want
I want to use Mozilla Gecko as web browser instead default IE in C#.
From: https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript The same origin policy prevents a document or script loaded from one
I use Mozilla Firefox 4. I can run a php test case with selenium

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.