1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsCSPUtils_h___
8 #define nsCSPUtils_h___
11 #include "nsIContentSecurityPolicy.h"
12 #include "nsILoadInfo.h"
14 #include "nsLiteralString.h"
17 #include "nsUnicharUtils.h"
18 #include "mozilla/Logging.h"
22 namespace mozilla::dom
{
25 } // namespace mozilla::dom
27 /* =============== Logging =================== */
29 void CSP_LogLocalizedStr(const char* aName
, const nsTArray
<nsString
>& aParams
,
30 const nsAString
& aSourceName
,
31 const nsAString
& aSourceLine
, uint32_t aLineNumber
,
32 uint32_t aColumnNumber
, uint32_t aFlags
,
33 const nsACString
& aCategory
, uint64_t aInnerWindowID
,
34 bool aFromPrivateWindow
);
36 void CSP_GetLocalizedStr(const char* aName
, const nsTArray
<nsString
>& aParams
,
37 nsAString
& outResult
);
39 void CSP_LogStrMessage(const nsAString
& aMsg
);
41 void CSP_LogMessage(const nsAString
& aMessage
, const nsAString
& aSourceName
,
42 const nsAString
& aSourceLine
, uint32_t aLineNumber
,
43 uint32_t aColumnNumber
, uint32_t aFlags
,
44 const nsACString
& aCategory
, uint64_t aInnerWindowID
,
45 bool aFromPrivateWindow
);
47 /* =============== Constant and Type Definitions ================== */
49 #define INLINE_STYLE_VIOLATION_OBSERVER_TOPIC \
50 "violated base restriction: Inline Stylesheets will not apply"
51 #define INLINE_SCRIPT_VIOLATION_OBSERVER_TOPIC \
52 "violated base restriction: Inline Scripts will not execute"
53 #define EVAL_VIOLATION_OBSERVER_TOPIC \
54 "violated base restriction: Code will not be created from strings"
55 #define WASM_EVAL_VIOLATION_OBSERVER_TOPIC \
56 "violated base restriction: WebAssembly code will not be created from " \
58 #define SCRIPT_NONCE_VIOLATION_OBSERVER_TOPIC "Inline Script had invalid nonce"
59 #define STYLE_NONCE_VIOLATION_OBSERVER_TOPIC "Inline Style had invalid nonce"
60 #define SCRIPT_HASH_VIOLATION_OBSERVER_TOPIC "Inline Script had invalid hash"
61 #define STYLE_HASH_VIOLATION_OBSERVER_TOPIC "Inline Style had invalid hash"
63 // these strings map to the CSPDirectives in nsIContentSecurityPolicy
64 // NOTE: When implementing a new directive, you will need to add it here but
65 // also add a corresponding entry to the constants in
66 // nsIContentSecurityPolicy.idl and also create an entry for the new directive
67 // in nsCSPDirective::toDomCSPStruct() and add it to CSPDictionaries.webidl.
68 // Order of elements below important! Make sure it matches the order as in
69 // nsIContentSecurityPolicy.idl
70 static const char* CSPStrDirectives
[] = {
71 "-error-", // NO_DIRECTIVE
72 "default-src", // DEFAULT_SRC_DIRECTIVE
73 "script-src", // SCRIPT_SRC_DIRECTIVE
74 "object-src", // OBJECT_SRC_DIRECTIVE
75 "style-src", // STYLE_SRC_DIRECTIVE
76 "img-src", // IMG_SRC_DIRECTIVE
77 "media-src", // MEDIA_SRC_DIRECTIVE
78 "frame-src", // FRAME_SRC_DIRECTIVE
79 "font-src", // FONT_SRC_DIRECTIVE
80 "connect-src", // CONNECT_SRC_DIRECTIVE
81 "report-uri", // REPORT_URI_DIRECTIVE
82 "frame-ancestors", // FRAME_ANCESTORS_DIRECTIVE
83 "reflected-xss", // REFLECTED_XSS_DIRECTIVE
84 "base-uri", // BASE_URI_DIRECTIVE
85 "form-action", // FORM_ACTION_DIRECTIVE
86 "manifest-src", // MANIFEST_SRC_DIRECTIVE
87 "upgrade-insecure-requests", // UPGRADE_IF_INSECURE_DIRECTIVE
88 "child-src", // CHILD_SRC_DIRECTIVE
89 "block-all-mixed-content", // BLOCK_ALL_MIXED_CONTENT
90 "sandbox", // SANDBOX_DIRECTIVE
91 "worker-src", // WORKER_SRC_DIRECTIVE
92 "script-src-elem", // SCRIPT_SRC_ELEM_DIRECTIVE
93 "script-src-attr", // SCRIPT_SRC_ATTR_DIRECTIVE
94 "style-src-elem", // STYLE_SRC_ELEM_DIRECTIVE
95 "style-src-attr", // STYLE_SRC_ATTR_DIRECTIVE
98 inline const char* CSP_CSPDirectiveToString(CSPDirective aDir
) {
99 return CSPStrDirectives
[static_cast<uint32_t>(aDir
)];
102 inline CSPDirective
CSP_StringToCSPDirective(const nsAString
& aDir
) {
103 nsString lowerDir
= PromiseFlatString(aDir
);
104 ToLowerCase(lowerDir
);
106 uint32_t numDirs
= (sizeof(CSPStrDirectives
) / sizeof(CSPStrDirectives
[0]));
107 for (uint32_t i
= 1; i
< numDirs
; i
++) {
108 if (lowerDir
.EqualsASCII(CSPStrDirectives
[i
])) {
109 return static_cast<CSPDirective
>(i
);
112 return nsIContentSecurityPolicy::NO_DIRECTIVE
;
115 #define FOR_EACH_CSP_KEYWORD(MACRO) \
116 MACRO(CSP_SELF, "'self'") \
117 MACRO(CSP_UNSAFE_INLINE, "'unsafe-inline'") \
118 MACRO(CSP_UNSAFE_EVAL, "'unsafe-eval'") \
119 MACRO(CSP_UNSAFE_HASHES, "'unsafe-hashes'") \
120 MACRO(CSP_NONE, "'none'") \
121 MACRO(CSP_NONCE, "'nonce-") \
122 MACRO(CSP_REPORT_SAMPLE, "'report-sample'") \
123 MACRO(CSP_STRICT_DYNAMIC, "'strict-dynamic'") \
124 MACRO(CSP_WASM_UNSAFE_EVAL, "'wasm-unsafe-eval'")
127 #define KEYWORD_ENUM(id_, string_) id_,
128 FOR_EACH_CSP_KEYWORD(KEYWORD_ENUM
)
131 // CSP_LAST_KEYWORD_VALUE always needs to be the last element in the enum
132 // because we use it to calculate the size for the char* array.
133 CSP_LAST_KEYWORD_VALUE
,
135 // Putting CSP_HASH after the delimitor, because CSP_HASH is not a valid
136 // keyword (hash uses e.g. sha256, sha512) but we use CSP_HASH internally
137 // to identify allowed hashes in ::allows.
141 // The keywords, in UTF-8 form.
142 static const char* gCSPUTF8Keywords
[] = {
143 #define KEYWORD_UTF8_LITERAL(id_, string_) string_,
144 FOR_EACH_CSP_KEYWORD(KEYWORD_UTF8_LITERAL
)
145 #undef KEYWORD_UTF8_LITERAL
148 // The keywords, in UTF-16 form.
149 static const char16_t
* gCSPUTF16Keywords
[] = {
150 #define KEYWORD_UTF16_LITERAL(id_, string_) u"" string_,
151 FOR_EACH_CSP_KEYWORD(KEYWORD_UTF16_LITERAL
)
152 #undef KEYWORD_UTF16_LITERAL
155 #undef FOR_EACH_CSP_KEYWORD
157 inline const char* CSP_EnumToUTF8Keyword(enum CSPKeyword aKey
) {
158 // Make sure all elements in enum CSPKeyword got added to gCSPUTF8Keywords.
159 static_assert((sizeof(gCSPUTF8Keywords
) / sizeof(gCSPUTF8Keywords
[0]) ==
160 CSP_LAST_KEYWORD_VALUE
),
161 "CSP_LAST_KEYWORD_VALUE != length(gCSPUTF8Keywords)");
163 if (static_cast<uint32_t>(aKey
) <
164 static_cast<uint32_t>(CSP_LAST_KEYWORD_VALUE
)) {
165 return gCSPUTF8Keywords
[static_cast<uint32_t>(aKey
)];
167 return "error: invalid keyword in CSP_EnumToUTF8Keyword";
170 inline const char16_t
* CSP_EnumToUTF16Keyword(enum CSPKeyword aKey
) {
171 // Make sure all elements in enum CSPKeyword got added to gCSPUTF16Keywords.
172 static_assert((sizeof(gCSPUTF16Keywords
) / sizeof(gCSPUTF16Keywords
[0]) ==
173 CSP_LAST_KEYWORD_VALUE
),
174 "CSP_LAST_KEYWORD_VALUE != length(gCSPUTF16Keywords)");
176 if (static_cast<uint32_t>(aKey
) <
177 static_cast<uint32_t>(CSP_LAST_KEYWORD_VALUE
)) {
178 return gCSPUTF16Keywords
[static_cast<uint32_t>(aKey
)];
180 return u
"error: invalid keyword in CSP_EnumToUTF16Keyword";
183 inline CSPKeyword
CSP_UTF16KeywordToEnum(const nsAString
& aKey
) {
184 nsString lowerKey
= PromiseFlatString(aKey
);
185 ToLowerCase(lowerKey
);
187 for (uint32_t i
= 0; i
< CSP_LAST_KEYWORD_VALUE
; i
++) {
188 if (lowerKey
.Equals(gCSPUTF16Keywords
[i
])) {
189 return static_cast<CSPKeyword
>(i
);
192 NS_ASSERTION(false, "Can not convert unknown Keyword to Enum");
193 return CSP_LAST_KEYWORD_VALUE
;
196 nsresult
CSP_AppendCSPFromHeader(nsIContentSecurityPolicy
* aCsp
,
197 const nsAString
& aHeaderValue
,
200 /* =============== Helpers ================== */
204 nsCSPHostSrc
* CSP_CreateHostSrcFromSelfURI(nsIURI
* aSelfURI
);
205 bool CSP_IsEmptyDirective(const nsAString
& aValue
, const nsAString
& aDir
);
206 bool CSP_IsDirective(const nsAString
& aValue
, CSPDirective aDir
);
207 bool CSP_IsKeyword(const nsAString
& aValue
, enum CSPKeyword aKey
);
208 bool CSP_IsQuotelessKeyword(const nsAString
& aKey
);
209 CSPDirective
CSP_ContentTypeToDirective(nsContentPolicyType aType
);
211 class nsCSPSrcVisitor
;
213 void CSP_PercentDecodeStr(const nsAString
& aEncStr
, nsAString
& outDecStr
);
214 bool CSP_ShouldResponseInheritCSP(nsIChannel
* aChannel
);
216 void CSP_ApplyMetaCSPToDoc(mozilla::dom::Document
& aDoc
,
217 const nsAString
& aPolicyStr
);
219 /* =============== nsCSPSrc ================== */
224 virtual ~nsCSPBaseSrc();
226 virtual bool permits(nsIURI
* aUri
, bool aWasRedirected
, bool aReportOnly
,
227 bool aUpgradeInsecure
) const;
228 virtual bool allows(enum CSPKeyword aKeyword
,
229 const nsAString
& aHashOrNonce
) const;
230 virtual bool visit(nsCSPSrcVisitor
* aVisitor
) const = 0;
231 virtual void toString(nsAString
& outStr
) const = 0;
233 virtual bool isReportSample() const { return false; }
235 virtual bool isHash() const { return false; }
236 virtual bool isNonce() const { return false; }
237 virtual bool isKeyword(CSPKeyword aKeyword
) const { return false; }
240 /* =============== nsCSPSchemeSrc ============ */
242 class nsCSPSchemeSrc
: public nsCSPBaseSrc
{
244 explicit nsCSPSchemeSrc(const nsAString
& aScheme
);
245 virtual ~nsCSPSchemeSrc();
247 bool permits(nsIURI
* aUri
, bool aWasRedirected
, bool aReportOnly
,
248 bool aUpgradeInsecure
) const override
;
249 bool visit(nsCSPSrcVisitor
* aVisitor
) const override
;
250 void toString(nsAString
& outStr
) const override
;
252 inline void getScheme(nsAString
& outStr
) const { outStr
.Assign(mScheme
); };
258 /* =============== nsCSPHostSrc ============== */
260 class nsCSPHostSrc
: public nsCSPBaseSrc
{
262 explicit nsCSPHostSrc(const nsAString
& aHost
);
263 virtual ~nsCSPHostSrc();
265 bool permits(nsIURI
* aUri
, bool aWasRedirected
, bool aReportOnly
,
266 bool aUpgradeInsecure
) const override
;
267 bool visit(nsCSPSrcVisitor
* aVisitor
) const override
;
268 void toString(nsAString
& outStr
) const override
;
270 void setScheme(const nsAString
& aScheme
);
271 void setPort(const nsAString
& aPort
);
272 void appendPath(const nsAString
& aPath
);
274 inline void setGeneratedFromSelfKeyword() const {
275 mGeneratedFromSelfKeyword
= true;
278 inline void setIsUniqueOrigin() const { mIsUniqueOrigin
= true; }
280 inline void setWithinFrameAncestorsDir(bool aValue
) const {
281 mWithinFrameAncstorsDir
= aValue
;
284 inline void getScheme(nsAString
& outStr
) const { outStr
.Assign(mScheme
); };
286 inline void getHost(nsAString
& outStr
) const { outStr
.Assign(mHost
); };
288 inline void getPort(nsAString
& outStr
) const { outStr
.Assign(mPort
); };
290 inline void getPath(nsAString
& outStr
) const { outStr
.Assign(mPath
); };
297 mutable bool mGeneratedFromSelfKeyword
;
298 mutable bool mIsUniqueOrigin
;
299 mutable bool mWithinFrameAncstorsDir
;
302 /* =============== nsCSPKeywordSrc ============ */
304 class nsCSPKeywordSrc
: public nsCSPBaseSrc
{
306 explicit nsCSPKeywordSrc(CSPKeyword aKeyword
);
307 virtual ~nsCSPKeywordSrc();
309 bool allows(enum CSPKeyword aKeyword
,
310 const nsAString
& aHashOrNonce
) const override
;
311 bool visit(nsCSPSrcVisitor
* aVisitor
) const override
;
312 void toString(nsAString
& outStr
) const override
;
314 inline CSPKeyword
getKeyword() const { return mKeyword
; };
316 bool isReportSample() const override
{ return mKeyword
== CSP_REPORT_SAMPLE
; }
318 bool isKeyword(CSPKeyword aKeyword
) const final
{
319 return mKeyword
== aKeyword
;
326 /* =============== nsCSPNonceSource =========== */
328 class nsCSPNonceSrc
: public nsCSPBaseSrc
{
330 explicit nsCSPNonceSrc(const nsAString
& aNonce
);
331 virtual ~nsCSPNonceSrc();
333 bool allows(enum CSPKeyword aKeyword
,
334 const nsAString
& aHashOrNonce
) const override
;
335 bool visit(nsCSPSrcVisitor
* aVisitor
) const override
;
336 void toString(nsAString
& outStr
) const override
;
338 inline void getNonce(nsAString
& outStr
) const { outStr
.Assign(mNonce
); };
340 bool isNonce() const final
{ return true; }
346 /* =============== nsCSPHashSource ============ */
348 class nsCSPHashSrc
: public nsCSPBaseSrc
{
350 nsCSPHashSrc(const nsAString
& algo
, const nsAString
& hash
);
351 virtual ~nsCSPHashSrc();
353 bool allows(enum CSPKeyword aKeyword
,
354 const nsAString
& aHashOrNonce
) const override
;
355 void toString(nsAString
& outStr
) const override
;
356 bool visit(nsCSPSrcVisitor
* aVisitor
) const override
;
358 inline void getAlgorithm(nsAString
& outStr
) const {
359 outStr
.Assign(mAlgorithm
);
362 inline void getHash(nsAString
& outStr
) const { outStr
.Assign(mHash
); };
364 bool isHash() const final
{ return true; }
371 /* =============== nsCSPReportURI ============ */
373 class nsCSPReportURI
: public nsCSPBaseSrc
{
375 explicit nsCSPReportURI(nsIURI
* aURI
);
376 virtual ~nsCSPReportURI();
378 bool visit(nsCSPSrcVisitor
* aVisitor
) const override
;
379 void toString(nsAString
& outStr
) const override
;
382 nsCOMPtr
<nsIURI
> mReportURI
;
385 /* =============== nsCSPSandboxFlags ================== */
387 class nsCSPSandboxFlags
: public nsCSPBaseSrc
{
389 explicit nsCSPSandboxFlags(const nsAString
& aFlags
);
390 virtual ~nsCSPSandboxFlags();
392 bool visit(nsCSPSrcVisitor
* aVisitor
) const override
;
393 void toString(nsAString
& outStr
) const override
;
399 /* =============== nsCSPSrcVisitor ================== */
401 class nsCSPSrcVisitor
{
403 virtual bool visitSchemeSrc(const nsCSPSchemeSrc
& src
) = 0;
405 virtual bool visitHostSrc(const nsCSPHostSrc
& src
) = 0;
407 virtual bool visitKeywordSrc(const nsCSPKeywordSrc
& src
) = 0;
409 virtual bool visitNonceSrc(const nsCSPNonceSrc
& src
) = 0;
411 virtual bool visitHashSrc(const nsCSPHashSrc
& src
) = 0;
414 explicit nsCSPSrcVisitor() = default;
415 virtual ~nsCSPSrcVisitor() = default;
418 /* =============== nsCSPDirective ============= */
420 class nsCSPDirective
{
422 explicit nsCSPDirective(CSPDirective aDirective
);
423 virtual ~nsCSPDirective();
425 virtual bool permits(CSPDirective aDirective
, nsILoadInfo
* aLoadInfo
,
426 nsIURI
* aUri
, bool aWasRedirected
, bool aReportOnly
,
427 bool aUpgradeInsecure
) const;
428 virtual bool allows(enum CSPKeyword aKeyword
,
429 const nsAString
& aHashOrNonce
) const;
430 bool allowsAllInlineBehavior(CSPDirective aDir
) const;
431 virtual void toString(nsAString
& outStr
) const;
432 void toDomCSPStruct(mozilla::dom::CSP
& outCSP
) const;
434 virtual void addSrcs(const nsTArray
<nsCSPBaseSrc
*>& aSrcs
) {
435 mSrcs
= aSrcs
.Clone();
438 inline bool isDefaultDirective() const {
439 return mDirective
== nsIContentSecurityPolicy::DEFAULT_SRC_DIRECTIVE
;
442 virtual bool equals(CSPDirective aDirective
) const;
444 void getReportURIs(nsTArray
<nsString
>& outReportURIs
) const;
446 bool visitSrcs(nsCSPSrcVisitor
* aVisitor
) const;
448 virtual void getDirName(nsAString
& outStr
) const;
450 bool hasReportSampleKeyword() const;
453 CSPDirective mDirective
;
454 nsTArray
<nsCSPBaseSrc
*> mSrcs
;
457 /* =============== nsCSPChildSrcDirective ============= */
460 * In CSP 3 child-src is deprecated. For backwards compatibility
461 * child-src needs to restrict:
462 * (*) frames, in case frame-src is not expicitly specified
463 * (*) workers, in case worker-src is not expicitly specified
465 class nsCSPChildSrcDirective
: public nsCSPDirective
{
467 explicit nsCSPChildSrcDirective(CSPDirective aDirective
);
468 virtual ~nsCSPChildSrcDirective();
470 void setRestrictFrames() { mRestrictFrames
= true; }
472 void setRestrictWorkers() { mRestrictWorkers
= true; }
474 virtual bool equals(CSPDirective aDirective
) const override
;
477 bool mRestrictFrames
;
478 bool mRestrictWorkers
;
481 /* =============== nsCSPScriptSrcDirective ============= */
484 * In CSP 3 worker-src restricts workers, for backwards compatibily
485 * script-src has to restrict workers as the ultimate fallback if
486 * neither worker-src nor child-src is present in a CSP.
488 class nsCSPScriptSrcDirective
: public nsCSPDirective
{
490 explicit nsCSPScriptSrcDirective(CSPDirective aDirective
);
491 virtual ~nsCSPScriptSrcDirective();
493 void setRestrictWorkers() { mRestrictWorkers
= true; }
494 void setRestrictScriptElem() { mRestrictScriptElem
= true; }
495 void setRestrictScriptAttr() { mRestrictScriptAttr
= true; }
497 bool equals(CSPDirective aDirective
) const override
;
500 bool mRestrictWorkers
= false;
501 bool mRestrictScriptElem
= false;
502 bool mRestrictScriptAttr
= false;
505 /* =============== nsCSPStyleSrcDirective ============= */
508 * In CSP 3 style-src is use as a fallback for style-src-elem and
511 class nsCSPStyleSrcDirective
: public nsCSPDirective
{
513 explicit nsCSPStyleSrcDirective(CSPDirective aDirective
);
514 virtual ~nsCSPStyleSrcDirective();
516 void setRestrictStyleElem() { mRestrictStyleElem
= true; }
517 void setRestrictStyleAttr() { mRestrictStyleAttr
= true; }
519 bool equals(CSPDirective aDirective
) const override
;
522 bool mRestrictStyleElem
= false;
523 bool mRestrictStyleAttr
= false;
526 /* =============== nsBlockAllMixedContentDirective === */
528 class nsBlockAllMixedContentDirective
: public nsCSPDirective
{
530 explicit nsBlockAllMixedContentDirective(CSPDirective aDirective
);
531 ~nsBlockAllMixedContentDirective();
533 bool permits(CSPDirective aDirective
, nsILoadInfo
* aLoadInfo
, nsIURI
* aUri
,
534 bool aWasRedirected
, bool aReportOnly
,
535 bool aUpgradeInsecure
) const override
{
539 bool permits(nsIURI
* aUri
) const { return false; }
541 bool allows(enum CSPKeyword aKeyword
,
542 const nsAString
& aHashOrNonce
) const override
{
546 void toString(nsAString
& outStr
) const override
;
548 void addSrcs(const nsTArray
<nsCSPBaseSrc
*>& aSrcs
) override
{
549 MOZ_ASSERT(false, "block-all-mixed-content does not hold any srcs");
552 void getDirName(nsAString
& outStr
) const override
;
555 /* =============== nsUpgradeInsecureDirective === */
558 * Upgrading insecure requests includes the following actors:
560 * The CSP implementation allowlists the http-request
561 * in case the policy is executed in enforcement mode.
562 * The CSP implementation however does not allow http
563 * requests to succeed if executed in report-only mode.
564 * In such a case the CSP implementation reports the
565 * error back to the page.
568 * The evalution of MixedContent allowlists all http
569 * requests with the promise that the http requests
570 * gets upgraded to https before any data is fetched
574 * Does not consider the http request to be of a
575 * different origin in case the scheme is the only
576 * difference in otherwise matching URIs.
579 * Before connecting, the channel gets redirected
582 * (5) WebSocketChannel:
583 * Similar to the httpChannel, the websocketchannel
584 * gets upgraded from ws to wss.
586 class nsUpgradeInsecureDirective
: public nsCSPDirective
{
588 explicit nsUpgradeInsecureDirective(CSPDirective aDirective
);
589 ~nsUpgradeInsecureDirective();
591 bool permits(CSPDirective aDirective
, nsILoadInfo
* aLoadInfo
, nsIURI
* aUri
,
592 bool aWasRedirected
, bool aReportOnly
,
593 bool aUpgradeInsecure
) const override
{
597 bool permits(nsIURI
* aUri
) const { return false; }
599 bool allows(enum CSPKeyword aKeyword
,
600 const nsAString
& aHashOrNonce
) const override
{
604 void toString(nsAString
& outStr
) const override
;
606 void addSrcs(const nsTArray
<nsCSPBaseSrc
*>& aSrcs
) override
{
607 MOZ_ASSERT(false, "upgrade-insecure-requests does not hold any srcs");
610 void getDirName(nsAString
& outStr
) const override
;
613 /* =============== nsCSPPolicy ================== */
618 virtual ~nsCSPPolicy();
620 bool permits(CSPDirective aDirective
, nsILoadInfo
* aLoadInfo
, nsIURI
* aUri
,
621 bool aWasRedirected
, bool aSpecific
,
622 nsAString
& outViolatedDirective
,
623 nsAString
& outViolatedDirectiveString
) const;
624 bool allows(CSPDirective aDirective
, enum CSPKeyword aKeyword
,
625 const nsAString
& aHashOrNonce
) const;
626 void toString(nsAString
& outStr
) const;
627 void toDomCSPStruct(mozilla::dom::CSP
& outCSP
) const;
629 inline void addDirective(nsCSPDirective
* aDir
) {
630 mDirectives
.AppendElement(aDir
);
633 inline void addUpgradeInsecDir(nsUpgradeInsecureDirective
* aDir
) {
634 mUpgradeInsecDir
= aDir
;
638 bool hasDirective(CSPDirective aDir
) const;
640 inline void setDeliveredViaMetaTagFlag(bool aFlag
) {
641 mDeliveredViaMetaTag
= aFlag
;
644 inline bool getDeliveredViaMetaTagFlag() const {
645 return mDeliveredViaMetaTag
;
648 inline void setReportOnlyFlag(bool aFlag
) { mReportOnly
= aFlag
; }
650 inline bool getReportOnlyFlag() const { return mReportOnly
; }
652 void getReportURIs(nsTArray
<nsString
>& outReportURIs
) const;
654 void getViolatedDirectiveInformation(CSPDirective aDirective
,
655 nsAString
& outDirective
,
656 nsAString
& outDirectiveString
,
657 bool* aReportSample
) const;
659 uint32_t getSandboxFlags() const;
661 inline uint32_t getNumDirectives() const { return mDirectives
.Length(); }
663 bool visitDirectiveSrcs(CSPDirective aDir
, nsCSPSrcVisitor
* aVisitor
) const;
665 bool allowsAllInlineBehavior(CSPDirective aDir
) const;
668 nsCSPDirective
* matchingOrDefaultDirective(CSPDirective aDirective
) const;
670 nsUpgradeInsecureDirective
* mUpgradeInsecDir
;
671 nsTArray
<nsCSPDirective
*> mDirectives
;
673 bool mDeliveredViaMetaTag
;
676 #endif /* nsCSPUtils_h___ */