What are the risks of letting users upload and run Javascript

前端 未结 4 1647
死守一世寂寞
死守一世寂寞 2021-01-03 05:38

If you have say an HTML5 games arcade, that allows users to upload a script that runs a game with HTML5 and Javascript, assuming you have no filters on their input (apart fr

4条回答
  •  感情败类
    2021-01-03 06:27

    Writing a bot that wins.
    Then the game would quickly move to writing a better bot to beat the other bots ;)

    If you load these scripts in an iframe with another domain, subdomain, port or protocol, the same origin policy will prevent these script to read the content of the main page.

    And you can set a string communication between these iframe and your main page through window.postMessage for modern browser or using the window.name hack for older browsers.

    And to prevent cookie stealing, you can have a secret key in your main page that you send back to your server for each request.

提交回复
热议问题