diff --git a/ipc/glue/BackgroundUtils.cpp b/ipc/glue/BackgroundUtils.cpp index 036b38f985..587b70faa5 100644 --- a/ipc/glue/BackgroundUtils.cpp +++ b/ipc/glue/BackgroundUtils.cpp @@ -295,7 +295,6 @@ LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo, aLoadInfo->GetForcePreflight(), aLoadInfo->GetIsPreflight(), aLoadInfo->GetLoadTriggeredFromExternal(), - aLoadInfo->GetSkipContentSniffing(), aLoadInfo->GetIsFromProcessingFrameAttributes() ); @@ -373,8 +372,7 @@ LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs, loadInfoArgs.corsUnsafeHeaders(), loadInfoArgs.forcePreflight(), loadInfoArgs.isPreflight(), - loadInfoArgs.loadTriggeredFromExternal(), - loadInfoArgs.skipContentSniffing() + loadInfoArgs.loadTriggeredFromExternal() ); if (loadInfoArgs.isFromProcessingFrameAttributes()) { diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp index 9b3532a8c5..54f59c8252 100644 --- a/netwerk/base/LoadInfo.cpp +++ b/netwerk/base/LoadInfo.cpp @@ -66,7 +66,6 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, , mForcePreflight(false) , mIsPreflight(false) , mLoadTriggeredFromExternal(false) - , mSkipContentSniffing(false) , mIsFromProcessingFrameAttributes(false) { MOZ_ASSERT(mLoadingPrincipal); @@ -242,7 +241,6 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow, , mForcePreflight(false) , mIsPreflight(false) , mLoadTriggeredFromExternal(false) - , mSkipContentSniffing(false) , mIsFromProcessingFrameAttributes(false) { // Top-level loads are never third-party @@ -307,7 +305,6 @@ LoadInfo::LoadInfo(const LoadInfo& rhs) , mForcePreflight(rhs.mForcePreflight) , mIsPreflight(rhs.mIsPreflight) , mLoadTriggeredFromExternal(rhs.mLoadTriggeredFromExternal) - , mSkipContentSniffing(rhs.mSkipContentSniffing) , mIsFromProcessingFrameAttributes(rhs.mIsFromProcessingFrameAttributes) { } @@ -336,8 +333,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, const nsTArray& aCorsUnsafeHeaders, bool aForcePreflight, bool aIsPreflight, - bool aLoadTriggeredFromExternal, - bool aSkipContentSniffing) + bool aLoadTriggeredFromExternal) : mLoadingPrincipal(aLoadingPrincipal) , mTriggeringPrincipal(aTriggeringPrincipal) , mPrincipalToInherit(aPrincipalToInherit) @@ -361,7 +357,6 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, , mForcePreflight(aForcePreflight) , mIsPreflight(aIsPreflight) , mLoadTriggeredFromExternal(aLoadTriggeredFromExternal) - , mSkipContentSniffing(aSkipContentSniffing) , mIsFromProcessingFrameAttributes(false) { // Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal @@ -970,17 +965,6 @@ LoadInfo::MaybeIncreaseTainting(uint32_t aTainting) return NS_OK; } -NS_IMETHODIMP -LoadInfo::GetSkipContentSniffing(bool* aSkipContentSniffing) { - *aSkipContentSniffing = mSkipContentSniffing; - return NS_OK; -} - -NS_IMETHODIMP -LoadInfo::SetSkipContentSniffing(bool aSkipContentSniffing) { - mSkipContentSniffing = aSkipContentSniffing; - return NS_OK; -} NS_IMETHODIMP LoadInfo::GetIsTopLevelLoad(bool *aResult) { diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h index 7edfc044c4..24dc83a59d 100644 --- a/netwerk/base/LoadInfo.h +++ b/netwerk/base/LoadInfo.h @@ -111,8 +111,7 @@ private: const nsTArray& aUnsafeHeaders, bool aForcePreflight, bool aIsPreflight, - bool aLoadTriggeredFromExternal, - bool aSkipContentSniffing); + bool aLoadTriggeredFromExternal); LoadInfo(const LoadInfo& rhs); friend nsresult @@ -158,7 +157,6 @@ private: bool mForcePreflight; bool mIsPreflight; bool mLoadTriggeredFromExternal; - bool mSkipContentSniffing; // Is true if this load was triggered by processing the attributes of the // browsing context container. diff --git a/netwerk/base/nsILoadInfo.idl b/netwerk/base/nsILoadInfo.idl index 41c2ac09bb..4baa8a682c 100644 --- a/netwerk/base/nsILoadInfo.idl +++ b/netwerk/base/nsILoadInfo.idl @@ -367,15 +367,6 @@ interface nsILoadInfo : nsISupports */ [infallible] readonly attribute unsigned long securityMode; - - /** - * This flag is used for any browsing context where we should not sniff - * the content type. E.g if an iframe has the XCTO nosniff header, then - * that flag is set to true so we skip content sniffing for that browsing - * context. - */ - [infallible] attribute boolean skipContentSniffing; - /** * True if this request is embedded in a context that can't be third-party * (i.e. an iframe embedded in a cross-origin parent window). If this is diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 2207e9e24d..ce62cfa8fc 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -16,7 +16,6 @@ #include "nsContentUtils.h" #include "nsHashKeys.h" #include "nsHttp.h" -#include "nsMimeTypes.h" #include "nsIAsyncStreamCopier.h" #include "nsIAuthPrompt.h" #include "nsIAuthPrompt2.h" @@ -2150,33 +2149,6 @@ NS_SniffContent(const char *aSnifferType, nsIRequest *aRequest, return; } - aSniffedType.Truncate(); - - nsCOMPtr channel = do_QueryInterface(aRequest); - if (channel) { - nsCOMPtr loadInfo = channel->GetLoadInfo(); - if (loadInfo->GetSkipContentSniffing()) { - // In case XCTO nosniff was present, we should skip sniffing here, but... - nsAutoCString currentContentType; - channel->GetContentType(currentContentType); - // We cannot skip sniffing if the current MIME type is a JSON file. - // The JSON-Viewer relies on its own sniffer to determine if it can render - // the page, so we need to make an exception if the Server provides a valid - // JSON MIME type (application/json, application/web-manifest or text/json). - // We also don't skip sniffing if the currently-known content type is empty, - // to deal with webmaster errors (nosniff is set but no content-type supplied) - // See Issue #2258. - if (!currentContentType.Equals(APPLICATION_JSON) && - !currentContentType.Equals(APPLICATION_WEB_MANIFEST) && - !currentContentType.Equals(TEXT_JSON) && - !currentContentType.IsEmpty()) { - // Content type supplied and it's not a JSON type; honor XCTO:nosniff. - return; - } - } - } - - // Iterate through the sniffers... nsCOMArray sniffers; cache->GetEntries(sniffers); for (int32_t i = 0; i < sniffers.Count(); ++i) { @@ -2185,9 +2157,8 @@ NS_SniffContent(const char *aSnifferType, nsIRequest *aRequest, return; } } - - // If we get here, there's nothing more to be done, return with a truncated aSniffedType. + aSniffedType.Truncate(); } bool diff --git a/netwerk/ipc/NeckoChannelParams.ipdlh b/netwerk/ipc/NeckoChannelParams.ipdlh index 038382f94d..91265b8953 100644 --- a/netwerk/ipc/NeckoChannelParams.ipdlh +++ b/netwerk/ipc/NeckoChannelParams.ipdlh @@ -55,7 +55,6 @@ struct LoadInfoArgs bool forcePreflight; bool isPreflight; bool loadTriggeredFromExternal; - bool skipContentSniffing; bool isFromProcessingFrameAttributes; }; diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index c28606982e..f83c2ef90b 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -14,7 +14,6 @@ #include "nsHttp.h" #include "nsHttpChannel.h" #include "nsHttpHandler.h" -#include "nsString.h" #include "nsIApplicationCacheService.h" #include "nsIApplicationCacheContainer.h" #include "nsICacheStorageService.h" @@ -1101,16 +1100,6 @@ ProcessXCTO(nsIURI* aURI, nsHttpResponseHead* aResponseHead, nsILoadInfo* aLoadI ReportTypeBlocking(aURI, aLoadInfo, "MimeTypeMismatch"); return NS_ERROR_CORRUPTED_CONTENT; } - auto policyType = aLoadInfo->GetExternalContentPolicyType(); - if (policyType == nsIContentPolicy::TYPE_DOCUMENT || - policyType == nsIContentPolicy::TYPE_SUBDOCUMENT) { - // If the header XCTO nosniff is set for any browsing context, then - // we set the skipContentSniffing flag on the Loadinfo. Within - // NS_SniffContent we then bail early and do not do any sniffing. - aLoadInfo->SetSkipContentSniffing(true); - return NS_OK; - } - return NS_OK; } diff --git a/netwerk/streamconv/converters/nsUnknownDecoder.cpp b/netwerk/streamconv/converters/nsUnknownDecoder.cpp index 5fe9bba442..dabdca2ed5 100644 --- a/netwerk/streamconv/converters/nsUnknownDecoder.cpp +++ b/netwerk/streamconv/converters/nsUnknownDecoder.cpp @@ -315,7 +315,6 @@ nsUnknownDecoder::GetMIMETypeFromContent(nsIRequest* aRequest, uint32_t aLength, nsACString& type) { - // Note: This is only used by sniffer, therefore we do not need to lock anything here. mBuffer = const_cast(reinterpret_cast(aData)); mBufferLen = aLength; DetermineContentType(aRequest); @@ -392,10 +391,10 @@ void nsUnknownDecoder::DetermineContentType(nsIRequest* aRequest) NS_ASSERTION(mContentType.IsEmpty(), "Content type is already known."); if (!mContentType.IsEmpty()) return; - nsCOMPtr channel(do_QueryInterface(aRequest)); const char* testData = mBuffer; uint32_t testDataLen = mBufferLen; // Check if data are compressed. + nsCOMPtr channel(do_QueryInterface(aRequest)); if (channel) { nsresult rv = ConvertEncodedData(aRequest, mBuffer, mBufferLen); if (NS_SUCCEEDED(rv)) { @@ -593,12 +592,6 @@ bool nsUnknownDecoder::LastDitchSniff(nsIRequest* aRequest) // All we can do now is try to guess whether this is text/plain or // application/octet-stream - nsCOMPtr channel(do_QueryInterface(aRequest)); - nsCOMPtr loadInfo = channel->GetLoadInfo(); - if (loadInfo->GetSkipContentSniffing()) { - return false; - } - const char* testData; uint32_t testDataLen; if (mDecodedData.IsEmpty()) { @@ -798,11 +791,6 @@ nsBinaryDetector::DetermineContentType(nsIRequest* aRequest) return; } - nsCOMPtr loadInfo = httpChannel->GetLoadInfo(); - if (loadInfo->GetSkipContentSniffing()) { - return; - } - // It's an HTTP channel. Check for the text/plain mess nsAutoCString contentTypeHdr; httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Type"), @@ -817,11 +805,14 @@ nsBinaryDetector::DetermineContentType(nsIRequest* aRequest) // FC7, RHEL4, and Ubuntu Feisty send charset=UTF-8. Don't do general // case-insensitive comparison, since we really want to apply this crap as // rarely as we can. + // Bail only if the Content-Type header isn't empty, to catch + // empty/unspecified MIME type headers webmaster error. if (!contentType.EqualsLiteral("text/plain") || (!contentTypeHdr.EqualsLiteral("text/plain") && !contentTypeHdr.EqualsLiteral("text/plain; charset=ISO-8859-1") && !contentTypeHdr.EqualsLiteral("text/plain; charset=iso-8859-1") && - !contentTypeHdr.EqualsLiteral("text/plain; charset=UTF-8"))) { + !contentTypeHdr.EqualsLiteral("text/plain; charset=UTF-8") && + !contentTypeHdr.IsEmpty())) { return; } diff --git a/parser/html/nsHtml5StreamParser.cpp b/parser/html/nsHtml5StreamParser.cpp index 47de91ba02..9779aa194e 100644 --- a/parser/html/nsHtml5StreamParser.cpp +++ b/parser/html/nsHtml5StreamParser.cpp @@ -166,7 +166,6 @@ nsHtml5StreamParser::nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor, , mLoadFlusher(new nsHtml5LoadFlusher(aExecutor)) , mFlushTimer(do_CreateInstance("@mozilla.org/timer;1")) , mMode(aMode) - , mSkipContentSniffing(false) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); mFlushTimer->SetTarget(mThread); @@ -550,7 +549,7 @@ nsHtml5StreamParser::FinalizeSniffing(const uint8_t* aFromSegment, // can be nul } // meta scan failed. - if (!mSkipContentSniffing && mCharsetSource >= kCharsetFromHintPrevDoc) { + if (mCharsetSource >= kCharsetFromHintPrevDoc) { mFeedChardet = false; return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment, aCount, aWriteCount); } @@ -875,13 +874,6 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext) mObserver->OnStartRequest(aRequest, aContext); } mRequest = aRequest; - nsCOMPtr myChannel(do_QueryInterface(aRequest)); - nsCOMPtr loadInfo = myChannel->GetLoadInfo(); - mSkipContentSniffing = loadInfo->GetSkipContentSniffing(); - - if (mSkipContentSniffing) { - mFeedChardet = false; - } mStreamState = STREAM_BEING_READ; diff --git a/parser/html/nsHtml5StreamParser.h b/parser/html/nsHtml5StreamParser.h index 2b48378239..2560f84abb 100644 --- a/parser/html/nsHtml5StreamParser.h +++ b/parser/html/nsHtml5StreamParser.h @@ -561,11 +561,6 @@ class nsHtml5StreamParser : public nsICharsetDetectionObserver { */ eParserMode mMode; - /** - * Whether the parser should not sniff the content type. - */ - bool mSkipContentSniffing; - /** * The pref html5.flushtimer.initialdelay: Time in milliseconds between * the time a network buffer is seen and the timer firing when the