mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-27 02:47:31 +09:00
Issue #2258 - Part 2: Move XCTO:nosniff check into sniffers.
This fixes a regression for the JSON viewer from part 1 as it relies on sniffing to prettify (and should carve out the exception even if `nosniff` headers are sent). No real functional changes otherwise. Just catering to a corner case.
This commit is contained in:
parent
e56e5d6cb1
commit
cca20ae131
5 changed files with 17 additions and 14 deletions
|
|
@ -2489,6 +2489,13 @@ imgLoader::GetMIMETypeFromContent(nsIRequest* aRequest,
|
||||||
uint32_t aLength,
|
uint32_t aLength,
|
||||||
nsACString& aContentType)
|
nsACString& aContentType)
|
||||||
{
|
{
|
||||||
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
||||||
|
if (channel) {
|
||||||
|
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
||||||
|
if (loadInfo->GetSkipContentSniffing()) {
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
return GetMimeTypeFromContent((const char*)aContents, aLength, aContentType);
|
return GetMimeTypeFromContent((const char*)aContents, aLength, aContentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2129,16 +2129,6 @@ NS_SniffContent(const char *aSnifferType, nsIRequest *aRequest,
|
||||||
const uint8_t *aData, uint32_t aLength,
|
const uint8_t *aData, uint32_t aLength,
|
||||||
nsACString &aSniffedType)
|
nsACString &aSniffedType)
|
||||||
{
|
{
|
||||||
// In case XCTO nosniff was present, we could just skip sniffing here
|
|
||||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
|
||||||
if (channel) {
|
|
||||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
|
||||||
if (loadInfo->GetSkipContentSniffing()) {
|
|
||||||
aSniffedType.Truncate();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef nsCategoryCache<nsIContentSniffer> ContentSnifferCache;
|
typedef nsCategoryCache<nsIContentSniffer> ContentSnifferCache;
|
||||||
extern ContentSnifferCache* gNetSniffers;
|
extern ContentSnifferCache* gNetSniffers;
|
||||||
extern ContentSnifferCache* gDataSniffers;
|
extern ContentSnifferCache* gDataSniffers;
|
||||||
|
|
|
||||||
|
|
@ -1106,7 +1106,7 @@ ProcessXCTO(nsIURI* aURI, nsHttpResponseHead* aResponseHead, nsILoadInfo* aLoadI
|
||||||
policyType == nsIContentPolicy::TYPE_SUBDOCUMENT) {
|
policyType == nsIContentPolicy::TYPE_SUBDOCUMENT) {
|
||||||
// If the header XCTO nosniff is set for any browsing context, then
|
// If the header XCTO nosniff is set for any browsing context, then
|
||||||
// we set the skipContentSniffing flag on the Loadinfo. Within
|
// we set the skipContentSniffing flag on the Loadinfo. Within
|
||||||
// NS_SniffContent we then bail early and do not do any sniffing.
|
// GetMIMETypeFromContent we then bail early and do not do any sniffing.
|
||||||
aLoadInfo->SetSkipContentSniffing(true);
|
aLoadInfo->SetSkipContentSniffing(true);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -317,9 +317,11 @@ nsUnknownDecoder::GetMIMETypeFromContent(nsIRequest* aRequest,
|
||||||
{
|
{
|
||||||
// Note: This is only used by sniffer, therefore we do not need to lock anything here.
|
// Note: This is only used by sniffer, therefore we do not need to lock anything here.
|
||||||
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
||||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
if (channel) {
|
||||||
if (loadInfo->GetSkipContentSniffing()) {
|
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
||||||
return NS_OK;
|
if (loadInfo->GetSkipContentSniffing()) {
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mBuffer = const_cast<char*>(reinterpret_cast<const char*>(aData));
|
mBuffer = const_cast<char*>(reinterpret_cast<const char*>(aData));
|
||||||
mBufferLen = aLength;
|
mBufferLen = aLength;
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,10 @@ nsMediaSniffer::GetMIMETypeFromContent(nsIRequest* aRequest,
|
||||||
nsACString& aSniffedType) {
|
nsACString& aSniffedType) {
|
||||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
|
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
||||||
|
if (loadInfo->GetSkipContentSniffing()) {
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
nsLoadFlags loadFlags = 0;
|
nsLoadFlags loadFlags = 0;
|
||||||
channel->GetLoadFlags(&loadFlags);
|
channel->GetLoadFlags(&loadFlags);
|
||||||
if (!(loadFlags & nsIChannel::LOAD_MEDIA_SNIFFER_OVERRIDES_CONTENT_TYPE)) {
|
if (!(loadFlags & nsIChannel::LOAD_MEDIA_SNIFFER_OVERRIDES_CONTENT_TYPE)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue