views:

74

answers:

4

is it possible to restrict javascript libraries from being able to manipulate the dom?

im trying to create a system that has a main system with the api which will be able to manipulate the dom and then i want to give the ability to create third party scripts but have them limited to only the api functions.

+1  A: 

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

Jonathon
+1  A: 

I don't believe so. You could make it difficult (security through obscurity type of nonsense), but not impossible.

Jonathan Sampson
+1  A: 

You can override some of the core function of the JavaScript, that will redirect all DOM manipulation calls to your framework. For example you could override document.getElementById, or setAttribute and appendChild. You could even override them to be empty functions.
However it's really not a good practice to do so.

Ilya Volodin
thank you very much this is very helpful
theunilife
+4  A: 

I would recommend you to give a look to the Google Caja project.

Caja allows websites to safely embed widgets and any web content from third parties using an "object-capability security model" to allow for a wide range of flexible security policies.

CMS
+1 Nice find, @CMS.
Jonathan Sampson
Thanks @Jonathan, the Crockford's ADSafe project (http://www.adsafe.org/) can be another good option...
CMS