From 3f1d0fd7a4c2eeab0edf328e55830dbb4fc9fe53 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Fri, 14 Jul 2006 21:41:08 +0000 Subject: [PATCH] Fixing bug 337755. Make IsCallerSecure() deal with jar: URIs. r=enndeakin@sympatico.ca, sr=bugmail@sicking.cc, a=mtschrep@gmail.com git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@202181 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/dom/src/storage/Makefile.in | 1 + mozilla/dom/src/storage/nsDOMStorage.cpp | 28 +++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/mozilla/dom/src/storage/Makefile.in b/mozilla/dom/src/storage/Makefile.in index eca7de11bca..858a0ac7942 100644 --- a/mozilla/dom/src/storage/Makefile.in +++ b/mozilla/dom/src/storage/Makefile.in @@ -55,6 +55,7 @@ REQUIRES = xpcom \ layout \ locale \ necko \ + jar \ pref \ unicharutil \ widget \ diff --git a/mozilla/dom/src/storage/nsDOMStorage.cpp b/mozilla/dom/src/storage/nsDOMStorage.cpp index 17432601593..f6c92c727be 100644 --- a/mozilla/dom/src/storage/nsDOMStorage.cpp +++ b/mozilla/dom/src/storage/nsDOMStorage.cpp @@ -49,6 +49,7 @@ #include "nsIURI.h" #include "nsReadableUtils.h" #include "nsIObserverService.h" +#include "nsIJARURI.h" // // Helper that tells us whether the caller is secure or not. @@ -57,21 +58,36 @@ static PRBool IsCallerSecure() { - nsCOMPtr callerDoc = - do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); + nsCOMPtr subjectPrincipal; + nsContentUtils::GetSecurityManager()-> + GetSubjectPrincipal(getter_AddRefs(subjectPrincipal)); + + if (!subjectPrincipal) { + // No subject principal means no code is running. Default to not + // being secure in that case. - if (!callerDoc) { return PR_FALSE; } - nsIURI *uri = callerDoc->GetDocumentURI(); + nsCOMPtr codebase; + subjectPrincipal->GetURI(getter_AddRefs(codebase)); - if (!uri) { + if (!codebase) { + return PR_FALSE; + } + + nsCOMPtr jarURI; + nsCOMPtr innerUri(codebase); + while((jarURI = do_QueryInterface(innerUri))) { + jarURI->GetJARFile(getter_AddRefs(innerUri)); + } + + if (!innerUri) { return PR_FALSE; } PRBool isHttps = PR_FALSE; - nsresult rv = uri->SchemeIs("https", &isHttps); + nsresult rv = innerUri->SchemeIs("https", &isHttps); return NS_SUCCEEDED(rv) && isHttps; }