Menu

Security

mmartz

This page is a description of Greasemonkey's security model.

Overview

Historically, Greasemonkey would inject a User script into a page by creating a <script> tag with the User script contents inline, and appending it to the content page's DOM.

Mark Pilgrim originally described a security flaw with this design, on July 19th 2005, while Greasemonkey was at version 0.3.4. Greasemonkey 0.3.5 was immediately released, with all GM_* functions disabled, to plug the security hole.

To fix the security flaw, XPCNativeWrappers, a new feature of the then-in-development Firefox 1.5, were used to isolate privileged User script code from insecure content pages. Certain other changes were made, including restrictions on the GM_xmlhttpRequest method, to disallow access to local files.

unsafeWindow

Wrapping the User script environment this way creates a Sandbox. This sandbox introduces many side effects and limitations.

To allow maximum flexibility for User script authors, the unsafeWindow property was added in to the sandbox. The window object functions as the global scope in JavaScript.

For User scripts, this global window option is in fact a "deep wrapper" of the content window. The content window can be accessed by User scripts, but only indirectly through the wrapper.

The unsafeWindow property is a direct line to the actual content window. Use of the unsafeWindow property should be avoided whenever possible.

Its use has the potential to open up all the original security holes that introducing the XPCNativeWrappers fixed.

When a User script] relies on the unsafeWindow property, it should be included only on trusted pages, and even then is not guaranteed to be safe.

See Also


Related

Wiki: GM_xmlhttpRequest
Wiki: Greasemonkey_Manual:Environment
Wiki: Greasemonkey_Manual:Other_Useful_Tools
Wiki: Main_Page
Wiki: Sandbox
Wiki: User_script
Wiki: Version_history
Wiki: XPCNativeWrapper
Wiki: unsafeWindow

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.