On Mon, Feb 27, 2012 at 11:32 PM, Huy Nguyen <
nvqua...@gmail.com> wrote:
> Thanks so much for your response, bholley!
>
> If you're trying to make it secure/tamper-proof, you'll find the task to
>> be significantly more difficult, since a clever adversary can try to find a
>> reference to the original document.getElementById and |apply| it
>> |document|. What are you trying to do?
>
>
> I'm trying to make it secure/tamper-proof like you said. If the JS try to
> make any changes to any DOM element, I want to do certain simple checking
> before allowing that to happen.
>
> The idea I'm trying out is to define a security level to both the script
> scope and the DOM object, and allow DOM access to script that has the level
> higher than the level of DOM object.
>
> <div id='A' slevel='1'></div>
>
> <script slevel='2' type="text/javascript">
> document.getElementById('A').innerHTML = "Hello"; // allowed
> </script>
>
> <script slevel='0' type="text/javascript">
> document.getElementById('A').innerHTML = "Hello"; // denied
> </script>
>
> If there's other ways to access the DOM object without using
> document.getElementById then I want to intercept it too. I guess it better
> be done by modifying the actual firefox/spidermonkey code?
>
Trying to maintain a patch against gecko for something like this is going
to be a world of pain. There's a huge amount of code, and we're changing a
lot of the dom and security stuff in the coming months. I strongly
recommend against pursuing this.
Security polices are, in general, very hard to get right. We spend an
immense amount of engineering effort maintaining the ones we provide
(cross-origin security, mostly). So creating a new one from scratch isn't a
great way to go.
What I'd recommend instead is to try to leverage the existing security
infrastructure Mozilla and the DOM provide in order to do what you want. In
general, this would involve sandboxing the untrusted code, and forcing it
to marshal its DOM access over some restricted API. Cross-origin iframes,
worker threads, and sandboxes all provide some degree of isolation for the
code running in their scope. You could then postMessage() the operations
you want to perform, and evaluate them in the master scope before
proceeding. If you need something synchronous, you can probably make
something work with sandboxes.
Cheers,
bholley
On Tue, Feb 28, 2012 at 3:09 PM, Bobby Holley <
bobby...@gmail.com> wrote:
> The most supported and painless method to extend Firefox is to create a
> javascript addon using the addon SDK:
>
https://addons.mozilla.org/en-US/developers/tools/builder
>
> You'll probably find that the SDK does what you want (you can use a
> page-mod to run your script in the context of web pages).
>
> If you're just trying to affect regular web pages, the task is pretty easy
> - just set |document.getElementById = yourFunction|.
>
> If you're trying to make it secure/tamper-proof, you'll find the task to
> be significantly more difficult, since a clever adversary can try to find a
> reference to the original document.getElementById and |apply| it
> |document|. What are you trying to do?
>
> Cheers,
> bholley
>
> On Mon, Feb 27, 2012 at 10:42 PM, Huy Nguyen <
nvqua...@gmail.com> wrote:
>