Revert "Issue #2258 - Part 3: Allow sniffing with XCTO:nosniff + empty MIME type."

This reverts commit a56f978f70e2d96ba501d6a944be33460afc481a.
This commit is contained in:
Moonchild 2025-09-23 18:17:39 +02:00 committed by roytam1
commit 2d4d48db72
5 changed files with 35 additions and 31 deletions

View file

@ -316,6 +316,13 @@ nsUnknownDecoder::GetMIMETypeFromContent(nsIRequest* aRequest,
nsACString& type)
{
// Note: This is only used by sniffer, therefore we do not need to lock anything here.
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
if (channel) {
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
if (loadInfo->GetSkipContentSniffing()) {
return NS_ERROR_NOT_AVAILABLE;
}
}
mBuffer = const_cast<char*>(reinterpret_cast<const char*>(aData));
mBufferLen = aLength;
DetermineContentType(aRequest);
@ -346,6 +353,11 @@ bool nsUnknownDecoder::AllowSniffing(nsIRequest* aRequest)
return false;
}
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
if (loadInfo->GetSkipContentSniffing()) {
return false;
}
bool isLocalFile = false;
if (NS_FAILED(uri->SchemeIs("file", &isLocalFile)) || isLocalFile) {
return false;
@ -393,6 +405,13 @@ void nsUnknownDecoder::DetermineContentType(nsIRequest* aRequest)
if (!mContentType.IsEmpty()) return;
nsCOMPtr<nsIHttpChannel> channel(do_QueryInterface(aRequest));
if (channel) {
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
if (loadInfo->GetSkipContentSniffing()) {
return;
}
}
const char* testData = mBuffer;
uint32_t testDataLen = mBufferLen;
// Check if data are compressed.
@ -564,6 +583,9 @@ bool nsUnknownDecoder::SniffURI(nsIRequest* aRequest)
{
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
if (loadInfo->GetSkipContentSniffing()) {
return false;
}
nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1"));
if (mimeService) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);