Javascript restricts?

Is it possible to limit javascript libraries to the ability to manipulate dom?

im trying to create a system that has a main system with api that can manipulate dom, and then I want to give the opportunity to create third-party scripts, but limit them to api functions only.

+4
source share
4 answers

I would recommend you see the Google Caja project.

Caja allows websites to securely embed widgets and any web content from third parties using the "object security model" to provide a wide range of flexible security policies.

+4
source

Not. The global context is the window object, and the window property is document . DOM methods are available from document . Anywhere, anyone can use window .

+1
source

I don’t believe that. You could make it difficult (security through an obscure kind of nonsense), but not impossible.

+1
source

You can override some basic JavaScript functions that redirect all calls to DOM manipulations to your infrastructure. For example, you can override document.getElementById or setAttribute and appendChild. You can even override them as empty functions. However, this is really not a good practice.

+1
source

Source: https://habr.com/ru/post/1300133/


All Articles