Closed Bug 312124 Opened 19 years ago Closed 19 years ago

http://www.squarefree.com/jsenv/ no longer works: "function eval must be called directly, and not by way of a function of another name"

Categories

(Core :: DOM: Core & HTML, defect, P2)

PowerPC
macOS
defect

Tracking

()

RESOLVED FIXED
mozilla1.8rc1

People

(Reporter: jruderman, Assigned: mrbkap)

References

()

Details

(Keywords: fixed1.8, regression, testcase, Whiteboard: [patch])

Attachments

(2 files, 1 obsolete file)

Steps to reproduce: 1. Go to http://www.squarefree.com/jsenv/ 2. Click "Execute" Expected: Print 0, 1, 4, 9, 16 Result: "Error on line 1: function eval must be called directly, and not by way of a function of another name" Regression range: PASS: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b3) Gecko/20050714 Firefox/1.0+ FAIL: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050715 Firefox/1.0+
Attached file simple testcase
Flags: blocking1.8rc1?
So the problem here is that the javascript URL principals inherit the principals of their owner (the attachment page) and the iframe has about:blank principals, so eval does not think that its principals (of the attachment page) can subsume the principals of the scope object (the about:blank window) and says, "go away, you can't do that." Brendan and I were talking about making the principals of newly-opened windows be that of their parent document (e.g., the attachment page for the iframe in the testcase) or their opener if there was no parent document. I think this should be possible with changes (in docshell?). Thoughts appreciated.
Assignee: general → mrbkap
Priority: -- → P2
Target Milestone: --- → mozilla1.8rc1
This would only be for about:blank pages, right? I'd have to think through changing the security context of those pretty carefully....
Right. As soon as a page has loaded something in it, it would have new principals (which would be subject to all of the same-origin checks that we do now).
How about treating about:blank like a data: URL? With data: URLs, if the page has both a parent and an opener, I think the opener's principal is used.
Are you saying that about:blank would have no principals defined until a script "claims" it by loading a JavaScript URL, sticking nodes in, etc? I guess that could work too, but it might be more complicated than it needs to be.
No, my idea was closer to what you said in comment 5.
Flags: blocking1.8rc1? → blocking1.8rc1+
Actually, this is more easily implemented in nsPrincipal::Subsume(). Non-about:blank principals subsuming about:blank principals fixes this bug. I'm still cleaning up my patch, and I still need to make sure that this isn't going to open up any security problems.
Status: NEW → ASSIGNED
I think the approach in comment 5 is better than the approach in comment 8, at least in the long term. I don't want scripts from other sites to be able to access my content/scripts just because I put it in a frame with the URL about:blank.
Attached patch Potential patch (obsolete) — Splinter Review
Jesse, the approach in comment 5 is incompatible with current behavior. This patch is specific to the |eval| and |new Script| cases (bringing them up to speed with our current treatment of about:blank documents, which is the "anybody can touch me" treatment). This approach is compatible, and, I believe fixes the original oversight in Subsume() [see also nsScriptSecurityManager::CheckSameOriginPrincipalInternal].
Attachment #199367 - Flags: review?(caillon)
Fair enough. I'll file a new bug for treating about:blank differently, since that change would affect compatibility.
Comment on attachment 199367 [details] [diff] [review] Potential patch sr=me if it helps (I originated subsumes). We should endeavor on the trunk to undo this change, by making about: URLs like data: URLs (and javascript: URls on a good day): their origin is the origin of the script that loaded them, or if statically src'ed, the origin of the embedding or parent doc. We should make not-a-principal real on the trunk too. Followup bugs welcome. /be
Attachment #199367 - Flags: superreview+
Comment on attachment 199367 [details] [diff] [review] Potential patch > NS_IMETHODIMP > nsPrincipal::Subsumes(nsIPrincipal *aOther, PRBool *aResult) > { >+ // First, check if aOther is an about:blank principal. If it is, then we can >+ // subsume it. >+ >+ nsCOMPtr<nsIURI> otherOrigin; >+ aOther->GetURI(getter_AddRefs(otherOrigin)); >+ >+ if (otherOrigin) { >+ PRBool isAbout = PR_FALSE; >+ if (NS_SUCCEEDED(otherOrigin->SchemeIs("about", &isAbout)) && isAbout) { >+ nsCAutoString str; >+ otherOrigin->GetSpec(str); >+ >+ // Note: about:blank principals do not necessarily subsume about:blank >+ // principals (unless aOther == this, which is checked in the Equals call >+ // below). >+ >+ if (str.Equals("about:blank")) { >+ PRBool isEqual = PR_FALSE; >+ if (NS_SUCCEEDED(otherOrigin->Equals(mCodebase, &isEqual)) && !isEqual) { >+ return PR_TRUE; Argh, you are in a NS_IMETHODIMP -- need to set *aResult and return NS_OK.
Attachment #199367 - Flags: superreview+ → superreview-
Comment on attachment 199367 [details] [diff] [review] Potential patch Quite.
Attachment #199367 - Attachment is obsolete: true
Attachment #199367 - Flags: superreview-
Attachment #199390 - Flags: superreview?(brendan)
Attachment #199390 - Flags: review?(caillon)
Attachment #199367 - Flags: review?(caillon) → superreview-
Comment on attachment 199390 [details] [diff] [review] With COM rules followed You probably don't need to initialize PRBool isAbout or PRBool isEqual. If the methods fail, you won't look at their value, but if they succeed, COM rules should warrant you get a valid value in them. But that's a very minor nit. r=caillon
Attachment #199390 - Flags: review?(caillon) → review+
Whiteboard: [patch]
Comment on attachment 199390 [details] [diff] [review] With COM rules followed I say don't trust nsIURI impls, they could come from anything (some wacky plugin). The cost of initializing is teeny. sr=me. /be
Attachment #199390 - Flags: superreview?(brendan)
Attachment #199390 - Flags: superreview+
Attachment #199390 - Flags: approval1.8rc1?
Fix checked into trunk.
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Attachment #199390 - Flags: approval1.8rc1? → approval1.8rc1+
Fix checked into MOZILLA_1_8_BRANCH.
Keywords: fixed1.8
Filed followup bug 313070, "Treat about:blank like a data: URL".
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: