Closed Bug 632796 Opened 15 years ago Closed 14 years ago

Build helper functions for document.write(), document.open() which can be accessed via Web Console

Categories

(DevTools :: General, defect)

x86
Windows 7
defect
Not set
major

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 663406

People

(Reporter: vladmaniac, Assigned: miker)

References

Details

(Whiteboard: [console-3])

Build ID: Mozilla/5.0 (Windows NT 6.1; rv:2.0b12pre) Gecko/20110208 Firefox/4.0b12pre At the moment, accessing document.write(), document.open() in the console results in echoing of this error: [14:57:54.244] [Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "Web Console Line: 1"] which occurs when a script tries to modify DOM content from another domain. This makes sense while the input code in the console is executed though a sandbox. My question is: Why these functions specifically throw security errors? We can't have these functions inaccessible. So I propose building some helper functions for them, as you guys did for document.getElementById()
Severity: normal → major
Whiteboard: [console-3]
Blocks: 663406
Assignee: nobody → mratcliffe
Status: NEW → ASSIGNED
This is similar to bug 663406. Rather than create aliases here we need to solve the actual problem. Here is the offending code: nsHTMLDocument.cpp 1572 // Note: We want to use GetDocumentFromContext here because this document 1573 // should inherit the security information of the document that's opening us, 1574 // (since if it's secure, then it's presumably trusted). 1575 nsCOMPtr<nsIDocument> callerDoc = 1576 do_QueryInterface(nsContentUtils::GetDocumentFromContext()); 1577 if (!callerDoc) { 1578 // If we're called from C++ or in some other way without an originating 1579 // document we can't do a document.open w/o changing the principal of the 1580 // document to something like about:blank (as that's the only sane thing to 1581 // do when we don't know the origin of this call), and since we can't 1582 // change the principals of a document for security reasons we'll have to 1583 // refuse to go ahead with this call. 1584 1585 return NS_ERROR_DOM_SECURITY_ERR; 1586 } nsContentUtils::GetDocumentFromContext() returns NULL/0x0 because nsJSUtils::GetDynamicScriptGlobal(cx) is NULL. There is a comment in bug 647727 which mentions that code executed in a sandbox doesn't really run in a window. Because window is null document will also be null. I will need to close this as a duplicate but will comment in the other bug that this also affects the web console.
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → DUPLICATE
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.