@@ -121,12 +121,37 @@ policy.
121
121
configured.
122
122
123
123
.. note ::
124
- The "special" source values of ``'self' ``, ``'unsafe-inline' ``, ``'unsafe-eval' ``,
125
- ``'strict-dynamic' ``, ``'none' ``, etc. must be quoted! e.g.: ``"default-src": ["'self'"] ``.
126
- Without quotes they will not work as intended.
124
+
125
+ The CSP keyword values of ``'self' ``, ``'unsafe-inline' ``, ``'strict-dynamic' ``, etc. must be
126
+ quoted! e.g.: ``"default-src": ["'self'"] ``. Without quotes they will not work as intended.
127
+
128
+ New in version 4.0 are CSP keyword constants. Use these to minimize quoting mistakes and typos.
129
+
130
+ The following CSP keywords are available:
131
+
132
+ * ``NONE `` = ``"'none'" ``
133
+ * ``REPORT_SAMPLE `` = ``"'report-sample'" ``
134
+ * ``SELF `` = ``"'self'" ``
135
+ * ``STRICT_DYNAMIC `` = ``"'strict-dynamic'" ``
136
+ * ``UNSAFE_ALLOW_REDIRECTS `` = ``"'unsafe-allow-redirects'" ``
137
+ * ``UNSAFE_EVAL `` = ``"'unsafe-eval'" ``
138
+ * ``UNSAFE_HASHES `` = ``"'unsafe-hashes'" ``
139
+ * ``UNSAFE_INLINE `` = ``"'unsafe-inline'" ``
140
+ * ``WASM_UNSAFE_EVAL `` = ``"'wasm-unsafe-eval'" ``
141
+
142
+ Example usage:
143
+
144
+ .. code-block :: python
127
145
128
- Consider using the ``csp.constants `` module to get these values to help avoiding quoting
129
- errors or typos, e.g., ``from csp.constants import SELF, STRICT_DYNAMIC ``.
146
+ from csp.constants import SELF , STRICT_DYNAMIC
147
+
148
+ CONTENT_SECURITY_POLICY = {
149
+ " DIRECTIVES" : {
150
+ " default-src" : [SELF , " cdn.example.net" ],
151
+ " script-src" : [SELF , STRICT_DYNAMIC ],
152
+ " style-src" : [SELF ],
153
+ }
154
+ }
130
155
131
156
.. note ::
132
157
Deprecated features of CSP in general have been moved to the bottom of this list.
@@ -248,17 +273,6 @@ policy.
248
273
Valid values: a ``list `` of allowed policy names that may include
249
274
``default `` and/or ``'allow-duplicates' ``
250
275
251
- ``include-nonce-in ``
252
- A ``tuple `` of directives to include a nonce in. *['default-src'] * Any directive that is
253
- included in this list will have a nonce value added to it of the form ``'nonce-{nonce-value}' ``.
254
-
255
- Note: This is a bit of a "pseudo"-directive. It's not a real CSP directive as defined by the
256
- spec, but it's used to determine which directives should include a nonce value. This is
257
- useful for adding nonces to scripts and styles.
258
-
259
- Note: The nonce value will only be generated if ``request.csp_nonce `` is accessed during the
260
- request/response cycle.
261
-
262
276
263
277
Deprecated CSP settings
264
278
-----------------------
0 commit comments