Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval can be harmful (no-eval) How to fix. #308

Closed
wdg opened this issue Oct 26, 2015 · 4 comments

Comments

@wdg
Copy link

commented Oct 26, 2015

Since "Eval can be harmful (no-eval)"

how can we parse this

        var js = change.getElementsByTagName('script')
        for (var i = 0, j = js.length; i < j; i++) {
          eval(js[i].innerHTML)
        }

(page is loaded via AJAX, so no scripts will be executed without eval)

Code Snippet

  function getViaAjax (url) {
    var xmlPhttp

    if (window.XMLHttpRequest) {
      xmlPhttp = new window.XMLHttpRequest() // code for IE7+, Firefox, Chrome, Opera, Safari
    } else {
      xmlPhttp = new window.ActiveXObject('Microsoft.XMLHTTP') // code for IE6, IE5
    }

    xmlPhttp.open('POST', url, true)
    xmlPhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
    xmlPhttp.onreadystatechange = function () {
      if (xmlPhttp.readyState === 4 && xmlPhttp.status === 200) {
        document.getElementById('changeMe').innerHTML = xmlPhttp.responseText

        // JavaScript Fix!
        var js = change.getElementsByTagName('script')
        for (var i = 0, j = js.length; i < j; i++) {
          eval(js[i].innerHTML)
        }
      }
    }
@KevinGrandon

This comment has been minimized.

Copy link

commented Oct 26, 2015

Why don't you just appendChild on a script element and set the src to your URL. Why does it need to be done over ajax?

@Flet

This comment has been minimized.

Copy link
Member

commented Oct 26, 2015

add this to the top of the file?

/*eslint-disable no-eval */
@wdg

This comment has been minimized.

Copy link
Author

commented Oct 26, 2015

@KevinGrandon I'm loading a page.
wich may have javascript content in it.

@Flet Thanks

@dcousens dcousens closed this Oct 26, 2015

@dcousens

This comment has been minimized.

Copy link
Member

commented Oct 26, 2015

@wesdegroot you could still use appendChild.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants
You can’t perform that action at this time.