Security risks of using eval() to execute user input in JavaScript

前端 未结 7 1439
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 02:31

I\'m planning on throwing together a quick web page for my students to teach them about JavaScript programming. On this page, I\'d like to give them a text box and allow the

7条回答
  •  一向
    一向 (楼主)
    2020-12-07 02:43

    You could try using a JavaScript sandboxing library. Dean Edward's solution Caja do not restrict code from accessing the current window or document. The JSandbox library fully sandboxes code execution using Web Worker Threads (you won't be able to use the DOM because of this) but it only works in browsers that support them.

    JSandbox is asynchronous so you will need to change your code to make use of callbacks if you choose to use it.

提交回复
热议问题