diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 513ea902571..6650a53d104 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -1560,6 +1560,17 @@ nsXMLHttpRequest::GetResponseHeader(const nsACString& header, nsresult rv = NS_OK; _retval.Truncate(); + // See bug #380418. Hide "Set-Cookie" headers from non-chrome scripts. + PRBool chrome = PR_FALSE; // default to false in case IsCapabilityEnabled fails + IsCapabilityEnabled("UniversalXPConnect", &chrome); + if (!chrome && + (header.LowerCaseEqualsASCII("set-cookie") || + header.LowerCaseEqualsASCII("set-cookie2"))) { + NS_WARNING("blocked access to response header"); + _retval.SetIsVoid(PR_TRUE); + return NS_OK; + } + // Check for dangerous headers if (mState & XML_HTTP_REQUEST_USE_XSITE_AC) { @@ -3343,10 +3354,19 @@ NS_IMPL_ISUPPORTS1(nsXMLHttpRequest::nsHeaderVisitor, nsIHttpHeaderVisitor) NS_IMETHODIMP nsXMLHttpRequest:: nsHeaderVisitor::VisitHeader(const nsACString &header, const nsACString &value) { - mHeaders.Append(header); - mHeaders.Append(": "); - mHeaders.Append(value); - mHeaders.Append('\n'); + // See bug #380418. Hide "Set-Cookie" headers from non-chrome scripts. + PRBool chrome = PR_FALSE; // default to false in case IsCapabilityEnabled fails + IsCapabilityEnabled("UniversalXPConnect", &chrome); + if (!chrome && + (header.LowerCaseEqualsASCII("set-cookie") || + header.LowerCaseEqualsASCII("set-cookie2"))) { + NS_WARNING("blocked access to response header"); + } else { + mHeaders.Append(header); + mHeaders.Append(": "); + mHeaders.Append(value); + mHeaders.Append('\n'); + } return NS_OK; } diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index d917e387f99..6a46e7c993b 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -258,6 +258,8 @@ _TEST_FILES = test_bug5141.html \ bug461735-redirect2.sjs \ bug461735-post-redirect.js \ test_bug461735.html \ + test_bug380418.html \ + test_bug380418.html^headers^ \ $(NULL) # Disabled for now. Mochitest isn't reliable enough for these. diff --git a/content/base/test/test_bug380418.html b/content/base/test/test_bug380418.html new file mode 100644 index 00000000000..1059027f21f --- /dev/null +++ b/content/base/test/test_bug380418.html @@ -0,0 +1,51 @@ + + + + + Test for Bug 380418 + + + + + +Mozilla Bug 380418 +

+ +
+
+
+ + diff --git a/content/base/test/test_bug380418.html^headers^ b/content/base/test/test_bug380418.html^headers^ new file mode 100644 index 00000000000..5f8d4969c0b --- /dev/null +++ b/content/base/test/test_bug380418.html^headers^ @@ -0,0 +1,4 @@ +Set-Cookie: test +Set-Cookie2: test2 +X-Dummy: test +Cache-Control: max-age=0