/* -*- 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/. */
/* =============== Constant and Type Definitions ================== */
#define INLINE_STYLE_VIOLATION_OBSERVER_TOPIC \ "violated base restriction: Inline Stylesheets will not apply" #define INLINE_SCRIPT_VIOLATION_OBSERVER_TOPIC \ "violated base restriction: Inline Scripts will not execute" #define EVAL_VIOLATION_OBSERVER_TOPIC \ "violated base restriction: Code will not be created from strings" #define WASM_EVAL_VIOLATION_OBSERVER_TOPIC \ "violated base restriction: WebAssembly code will not be created from " \ "dynamically" #define SCRIPT_NONCE_VIOLATION_OBSERVER_TOPIC "Inline Script had invalid nonce" #define STYLE_NONCE_VIOLATION_OBSERVER_TOPIC "Inline Style had invalid nonce" #define SCRIPT_HASH_VIOLATION_OBSERVER_TOPIC "Inline Script had invalid hash" #define STYLE_HASH_VIOLATION_OBSERVER_TOPIC "Inline Style had invalid hash" #define TRUSTED_TYPES_VIOLATION_OBSERVER_TOPIC \ "Tried to create a trusted-types policy with a forbidden policy name" #define REQUIRE_TRUSTED_TYPES_FOR_SCRIPT_OBSERVER_TOPIC \ "Type mismatch for injection sink"
// these strings map to the CSPDirectives in nsIContentSecurityPolicy // NOTE: When implementing a new directive, you will need to add it here but // also add a corresponding entry to the constants in // nsIContentSecurityPolicy.idl and also create an entry for the new directive // in nsCSPDirective::toDomCSPStruct() and add it to CSPDictionaries.webidl. // Order of elements below important! Make sure it matches the order as in // nsIContentSecurityPolicy.idl staticconstchar* CSPStrDirectives[] = { "-error-", // NO_DIRECTIVE "default-src", // DEFAULT_SRC_DIRECTIVE "script-src", // SCRIPT_SRC_DIRECTIVE "object-src", // OBJECT_SRC_DIRECTIVE "style-src", // STYLE_SRC_DIRECTIVE "img-src", // IMG_SRC_DIRECTIVE "media-src", // MEDIA_SRC_DIRECTIVE "frame-src", // FRAME_SRC_DIRECTIVE "font-src", // FONT_SRC_DIRECTIVE "connect-src", // CONNECT_SRC_DIRECTIVE "report-uri", // REPORT_URI_DIRECTIVE "frame-ancestors", // FRAME_ANCESTORS_DIRECTIVE "reflected-xss", // REFLECTED_XSS_DIRECTIVE "base-uri", // BASE_URI_DIRECTIVE "form-action", // FORM_ACTION_DIRECTIVE "manifest-src", // MANIFEST_SRC_DIRECTIVE "upgrade-insecure-requests", // UPGRADE_IF_INSECURE_DIRECTIVE "child-src", // CHILD_SRC_DIRECTIVE "block-all-mixed-content", // BLOCK_ALL_MIXED_CONTENT "sandbox", // SANDBOX_DIRECTIVE "worker-src", // WORKER_SRC_DIRECTIVE "script-src-elem", // SCRIPT_SRC_ELEM_DIRECTIVE "script-src-attr", // SCRIPT_SRC_ATTR_DIRECTIVE "style-src-elem", // STYLE_SRC_ELEM_DIRECTIVE "style-src-attr", // STYLE_SRC_ATTR_DIRECTIVE "require-trusted-types-for", // REQUIRE_TRUSTED_TYPES_FOR_DIRECTIVE "trusted-types", // TRUSTED_TYPES_DIRECTIVE "report-to", // REPORT_TO_DIRECTIVE
};
// CSP_LAST_KEYWORD_VALUE always needs to be the last element in the enum // because we use it to calculate the size for the char* array.
CSP_LAST_KEYWORD_VALUE,
// Putting CSP_HASH after the delimitor, because CSP_HASH is not a valid // keyword (hash uses e.g. sha256, sha512) but we use CSP_HASH internally // to identify allowed hashes in ::allows.
CSP_HASH
};
// The keywords, in UTF-8 form. staticconstchar* gCSPUTF8Keywords[] = { #define KEYWORD_UTF8_LITERAL(id_, string_) string_,
FOR_EACH_CSP_KEYWORD(KEYWORD_UTF8_LITERAL) #undef KEYWORD_UTF8_LITERAL
};
// The keywords, in UTF-16 form. staticconst char16_t* gCSPUTF16Keywords[] = { #define KEYWORD_UTF16_LITERAL(id_, string_) u"" string_,
FOR_EACH_CSP_KEYWORD(KEYWORD_UTF16_LITERAL) #undef KEYWORD_UTF16_LITERAL
};
#undef FOR_EACH_CSP_KEYWORD
inlineconstchar* CSP_EnumToUTF8Keyword(enum CSPKeyword aKey) { // Make sure all elements in enum CSPKeyword got added to gCSPUTF8Keywords.
static_assert((sizeof(gCSPUTF8Keywords) / sizeof(gCSPUTF8Keywords[0]) ==
CSP_LAST_KEYWORD_VALUE), "CSP_LAST_KEYWORD_VALUE != length(gCSPUTF8Keywords)");
if (static_cast<uint32_t>(aKey) < static_cast<uint32_t>(CSP_LAST_KEYWORD_VALUE)) { return gCSPUTF8Keywords[static_cast<uint32_t>(aKey)];
} return"error: invalid keyword in CSP_EnumToUTF8Keyword";
}
inlineconst char16_t* CSP_EnumToUTF16Keyword(enum CSPKeyword aKey) { // Make sure all elements in enum CSPKeyword got added to gCSPUTF16Keywords.
static_assert((sizeof(gCSPUTF16Keywords) / sizeof(gCSPUTF16Keywords[0]) ==
CSP_LAST_KEYWORD_VALUE), "CSP_LAST_KEYWORD_VALUE != length(gCSPUTF16Keywords)");
if (static_cast<uint32_t>(aKey) < static_cast<uint32_t>(CSP_LAST_KEYWORD_VALUE)) { return gCSPUTF16Keywords[static_cast<uint32_t>(aKey)];
} return u"error: invalid keyword in CSP_EnumToUTF16Keyword";
}
for (uint32_t i = 0; i < CSP_LAST_KEYWORD_VALUE; i++) { if (lowerKey.Equals(gCSPUTF16Keywords[i])) { returnstatic_cast<CSPKeyword>(i);
}
}
NS_ASSERTION(false, "Can not convert unknown Keyword to Enum"); return CSP_LAST_KEYWORD_VALUE;
}
/* * In CSP 3 child-src is deprecated. For backwards compatibility * child-src needs to restrict: * (*) frames, in case frame-src is not expicitly specified * (*) workers, in case worker-src is not expicitly specified
*/ class nsCSPChildSrcDirective : public nsCSPDirective { public: explicit nsCSPChildSrcDirective(CSPDirective aDirective); virtual ~nsCSPChildSrcDirective();
/* * In CSP 3 worker-src restricts workers, for backwards compatibily * script-src has to restrict workers as the ultimate fallback if * neither worker-src nor child-src is present in a CSP.
*/ class nsCSPScriptSrcDirective : public nsCSPDirective { public: explicit nsCSPScriptSrcDirective(CSPDirective aDirective); virtual ~nsCSPScriptSrcDirective();
/* * In CSP 3 style-src is use as a fallback for style-src-elem and * style-src-attr.
*/ class nsCSPStyleSrcDirective : public nsCSPDirective { public: explicit nsCSPStyleSrcDirective(CSPDirective aDirective); virtual ~nsCSPStyleSrcDirective();
/* * Upgrading insecure requests includes the following actors: * (1) CSP: * The CSP implementation allowlists the http-request * in case the policy is executed in enforcement mode. * The CSP implementation however does not allow http * requests to succeed if executed in report-only mode. * In such a case the CSP implementation reports the * error back to the page. * * (2) MixedContent: * The evalution of MixedContent allowlists all http * requests with the promise that the http requests * gets upgraded to https before any data is fetched * from the network. * * (3) CORS: * Does not consider the http request to be of a * different origin in case the scheme is the only * difference in otherwise matching URIs. * * (4) nsHttpChannel: * Before connecting, the channel gets redirected * to use https. * * (5) WebSocketChannel: * Similar to the httpChannel, the websocketchannel * gets upgraded from ws to wss.
*/ class nsUpgradeInsecureDirective : public nsCSPDirective { public: explicit nsUpgradeInsecureDirective(CSPDirective aDirective);
~nsUpgradeInsecureDirective();
/* * Implements step 2.1 to 2.7 of * <https://w3c.github.io/trusted-types/dist/spec/#should-block-create-policy>. * and returns the result of "createViolation". * * @param aCreatedPolicyNames The already created policy names. * @return true if a violation for aPolicyName should be created.
*/ bool ShouldCreateViolationForNewTrustedTypesPolicy( const nsAString& aPolicyName, const nsTArray<nsString>& aCreatedPolicyNames) const;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.