From 3fdc8e4fa1b4d58db4afb88ff3bc2b2731789f98 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 19 Dec 2011 12:48:12 -0500 Subject: [PATCH] Bug 624621 part 3. Use the pre-redirect filename as the script filename and the channel principal as the origin principal, and base our cross-origin check on the origin principal. r=mrbkap --- content/base/src/nsScriptLoader.cpp | 15 ++++++---- content/base/test/test_bug461735.html | 8 +++-- dom/base/nsJSEnvironment.cpp | 31 ++++++++------------ js/src/tests/js1_5/Regress/regress-328897.js | 2 +- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/content/base/src/nsScriptLoader.cpp b/content/base/src/nsScriptLoader.cpp index 6001d3329a9..030026db69f 100644 --- a/content/base/src/nsScriptLoader.cpp +++ b/content/base/src/nsScriptLoader.cpp @@ -120,7 +120,7 @@ public: nsString mScriptText; // Holds script for loaded scripts PRUint32 mJSVersion; nsCOMPtr mURI; - nsCOMPtr mFinalURI; + nsCOMPtr mOriginPrincipal; PRInt32 mLineNo; }; @@ -882,8 +882,6 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest, return NS_ERROR_FAILURE; } - nsIURI* uri = aRequest->mFinalURI ? aRequest->mFinalURI : aRequest->mURI; - bool oldProcessingScriptTag = context->GetProcessingScriptTag(); context->SetProcessingScriptTag(true); @@ -891,13 +889,15 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest, nsCOMPtr oldCurrent = mCurrentScript; mCurrentScript = aRequest->mElement; + // It's very important to use aRequest->mURI, not the final URI of the channel + // aRequest ended up getting script data from, as the script filename. nsCAutoString url; - nsContentUtils::GetWrapperSafeScriptFilename(mDocument, uri, url); + nsContentUtils::GetWrapperSafeScriptFilename(mDocument, aRequest->mURI, url); bool isUndefined; rv = context->EvaluateString(aScript, globalObject->GetGlobalJSObject(), mDocument->NodePrincipal(), - mDocument->NodePrincipal(), + aRequest->mOriginPrincipal, url.get(), aRequest->mLineNo, aRequest->mJSVersion, nsnull, &isUndefined); @@ -1214,7 +1214,10 @@ nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest, } nsCOMPtr channel = do_QueryInterface(req); - NS_GetFinalChannelURI(channel, getter_AddRefs(aRequest->mFinalURI)); + rv = nsContentUtils::GetSecurityManager()-> + GetChannelPrincipal(channel, getter_AddRefs(aRequest->mOriginPrincipal)); + NS_ENSURE_SUCCESS(rv, rv); + if (aStringLen) { // Check the charset attribute to determine script charset. nsAutoString hintCharset; diff --git a/content/base/test/test_bug461735.html b/content/base/test/test_bug461735.html index 3c08173ad3e..14cb247428b 100644 --- a/content/base/test/test_bug461735.html +++ b/content/base/test/test_bug461735.html @@ -19,7 +19,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=461735 var errorFired = false; window.onerror = function(message, uri, line) { is(message, "Script error.", "Should have empty error message"); - is(uri, "", "Should have empty error location URI"); + is(uri, + "http://mochi.test:8888/tests/content/base/test/bug461735-redirect1.sjs", + "Should have pre-redirect error location URI"); is(line, 0, "Shouldn't have a line here"); errorFired = true; } @@ -32,7 +34,9 @@ window.onerror = function(message, uri, line) {