Bug 1696111 - Add functions to determine opaque-safelisted MIME type, opaque-blocklisted MIME type and opaque-blocklisted-never-sniffed MIME type; r=necko-reviewers,dragana

These functions are defined at https://github.com/annevk/orb.

Differential Revision: https://phabricator.services.mozilla.com/D102447
This commit is contained in:
Tom Tung 2021-03-30 00:52:29 +00:00
parent cd108619ed
commit cafaf3f705
4 changed files with 140 additions and 0 deletions

View File

@ -76,6 +76,45 @@
#define APPLICATION_WAPXHTML_XML "application/vnd.wap.xhtml+xml"
#define APPLICATION_PACKAGE "application/package"
#define APPLICATION_WASM "application/wasm"
#define APPLICATION_MSEXCEL "application/msexcel"
#define APPLICATION_MSPPT "application/mspowerpoint"
#define APPLICATION_MSWORD "application/msword"
#define APPLICATION_MSWORD_TEMPLATE "application/msword-template"
#define APPLICATION_VND_CES_QUICKPOINT "application/vnd.ces-quickpoint"
#define APPLICATION_VND_CES_QUICKSHEET "application/vnd.ces-quicksheet"
#define APPLICATION_VND_CES_QUICKWORD "application/vnd.ces-quickword"
#define APPLICATION_VND_MS_EXCEL "application/vnd.ms-excel"
#define APPLICATION_VND_MS_EXCEL2 \
"application/vnd.ms-excel.sheet.macroenabled.12"
#define APPLICATION_VND_MS_PPT "application/vnd.ms-powerpoint"
#define APPLICATION_VND_MS_PPT2 \
"application/vnd.ms-powerpoint.presentation.macroenabled.12"
#define APPLICATION_VND_MS_WORD "application/vnd.ms-word"
#define APPLICATION_VND_MS_WORD2 "application/vnd.ms-word.document.12"
#define APPLICATION_VND_MS_WORD3 \
"application/vnd.ms-word.document.macroenabled.12"
#define APPLICATION_VND_MSWORD "application/vnd.msword"
#define APPLICATION_VND_PRESENTATIONML_PRESENTATION \
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
#define APPLICATION_VND_PRESENTATIONML_TEMPLATE \
"application/vnd.openxmlformats-officedocument.presentationml.template"
#define APPLICATION_VND_SPREADSHEETML_SHEET \
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
#define APPLICATION_VND_SPREADSHEETML_TEMPLATE \
"application/vnd.openxmlformats-officedocument.spreadsheetml.template"
#define APPLICATION_VND_WORDPROCESSINGML_DOCUMENT \
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
#define APPLICATION_VND_WORDPROCESSINGML_TEMPLATE \
"application/vnd.openxmlformats-officedocument.wordprocessingml.template"
#define APPLICATION_VND_PRESENTATION_OPENXML \
"application/vnd.presentation-openxml"
#define APPLICATION_VND_PRESENTATION_OPENXMLM \
"application/vnd.presentation-openxmlm"
#define APPLICATION_VND_SPREADSHEET_OPENXML \
"application/vnd.spreadsheet-openxml"
#define APPLICATION_VND_WORDPROSSING_OPENXML \
"application/vnd.wordprocessing-openxml"
#define APPLICATION_XPROTOBUF "application/x-protobuf"
#define AUDIO_BASIC "audio/basic"
#define AUDIO_OGG "audio/ogg"
@ -157,6 +196,7 @@
#define TEXT_XSL "text/xsl"
#define TEXT_EVENT_STREAM "text/event-stream"
#define TEXT_CACHE_MANIFEST "text/cache-manifest"
#define TEXT_CSV "text/csv"
#define VIDEO_MPEG "video/mpeg"
#define VIDEO_MP4 "video/mp4"

View File

@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/net/OpaqueResponseUtils.h"
#include "nsMimeTypes.h"
namespace mozilla {
namespace net {
bool IsOpaqueSafeListedMIMEType(const nsACString& aContentType) {
if (aContentType.EqualsLiteral(TEXT_CSS) ||
aContentType.EqualsLiteral(IMAGE_SVG_XML)) {
return true;
}
NS_ConvertUTF8toUTF16 typeString(aContentType);
return nsContentUtils::IsJavascriptMIMEType(typeString);
}
bool IsOpaqueBlockListedMIMEType(const nsACString& aContentType) {
return aContentType.EqualsLiteral(TEXT_HTML) ||
StringEndsWith(aContentType, "+json"_ns) ||
aContentType.EqualsLiteral(APPLICATION_JSON) ||
aContentType.EqualsLiteral(TEXT_JSON) ||
StringEndsWith(aContentType, "+xml"_ns) ||
aContentType.EqualsLiteral(APPLICATION_XML) ||
aContentType.EqualsLiteral(TEXT_XML);
}
bool IsOpaqueBlockListedNeverSniffedMIMEType(const nsACString& aContentType) {
return aContentType.EqualsLiteral(APPLICATION_GZIP2) ||
aContentType.EqualsLiteral(APPLICATION_MSEXCEL) ||
aContentType.EqualsLiteral(APPLICATION_MSPPT) ||
aContentType.EqualsLiteral(APPLICATION_MSWORD) ||
aContentType.EqualsLiteral(APPLICATION_MSWORD_TEMPLATE) ||
aContentType.EqualsLiteral(APPLICATION_PDF) ||
aContentType.EqualsLiteral(APPLICATION_VND_CES_QUICKPOINT) ||
aContentType.EqualsLiteral(APPLICATION_VND_CES_QUICKSHEET) ||
aContentType.EqualsLiteral(APPLICATION_VND_CES_QUICKWORD) ||
aContentType.EqualsLiteral(APPLICATION_VND_MS_EXCEL) ||
aContentType.EqualsLiteral(APPLICATION_VND_MS_EXCEL2) ||
aContentType.EqualsLiteral(APPLICATION_VND_MS_PPT) ||
aContentType.EqualsLiteral(APPLICATION_VND_MS_PPT2) ||
aContentType.EqualsLiteral(APPLICATION_VND_MS_WORD) ||
aContentType.EqualsLiteral(APPLICATION_VND_MS_WORD2) ||
aContentType.EqualsLiteral(APPLICATION_VND_MS_WORD3) ||
aContentType.EqualsLiteral(APPLICATION_VND_MSWORD) ||
aContentType.EqualsLiteral(
APPLICATION_VND_PRESENTATIONML_PRESENTATION) ||
aContentType.EqualsLiteral(APPLICATION_VND_PRESENTATIONML_TEMPLATE) ||
aContentType.EqualsLiteral(APPLICATION_VND_SPREADSHEETML_SHEET) ||
aContentType.EqualsLiteral(APPLICATION_VND_SPREADSHEETML_TEMPLATE) ||
aContentType.EqualsLiteral(
APPLICATION_VND_WORDPROCESSINGML_DOCUMENT) ||
aContentType.EqualsLiteral(
APPLICATION_VND_WORDPROCESSINGML_TEMPLATE) ||
aContentType.EqualsLiteral(APPLICATION_VND_PRESENTATION_OPENXML) ||
aContentType.EqualsLiteral(APPLICATION_VND_PRESENTATION_OPENXMLM) ||
aContentType.EqualsLiteral(APPLICATION_VND_SPREADSHEET_OPENXML) ||
aContentType.EqualsLiteral(APPLICATION_VND_WORDPROSSING_OPENXML) ||
aContentType.EqualsLiteral(APPLICATION_GZIP) ||
aContentType.EqualsLiteral(APPLICATION_XPROTOBUF) ||
aContentType.EqualsLiteral(APPLICATION_ZIP) ||
aContentType.EqualsLiteral(MULTIPART_BYTERANGES) ||
aContentType.EqualsLiteral(MULTIPART_SIGNED) ||
aContentType.EqualsLiteral(TEXT_EVENT_STREAM) ||
aContentType.EqualsLiteral(TEXT_CSV);
}
} // namespace net
} // namespace mozilla

View File

@ -0,0 +1,23 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_net_OpaqueResponseUtils_h
#define mozilla_net_OpaqueResponseUtils_h
namespace mozilla {
namespace net {
bool IsOpaqueSafeListedMIMEType(const nsACString& aContentType);
bool IsOpaqueBlockListedMIMEType(const nsACString& aContentType);
bool IsOpaqueBlockListedNeverSniffedMIMEType(const nsACString& aContentType);
} // namespace net
} // namespace mozilla
#endif // mozilla_net_OpaqueResponseUtils_h

View File

@ -64,6 +64,7 @@ EXPORTS.mozilla.net += [
"nsServerTiming.h",
"NullHttpChannel.h",
"NullHttpTransaction.h",
"OpaqueResponseUtils.h",
"ParentChannelListener.h",
"PHttpChannelParams.h",
"PSpdyPush.h",
@ -140,6 +141,7 @@ UNIFIED_SOURCES += [
"nsServerTiming.cpp",
"NullHttpChannel.cpp",
"NullHttpTransaction.cpp",
"OpaqueResponseUtils.cpp",
"ParentChannelListener.cpp",
"PendingTransactionInfo.cpp",
"PendingTransactionQueue.cpp",