Completed
Pull Request — master (#5462)
by Thomas
16:42
created
lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -362,77 +362,77 @@
 block discarded – undo
362 362
 		$policy .= "base-uri 'none';";
363 363
 		$policy .= "manifest-src 'self';";
364 364
 
365
-		if(!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) {
365
+		if (!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) {
366 366
 			$policy .= 'script-src ';
367
-			if(is_string($this->useJsNonce)) {
367
+			if (is_string($this->useJsNonce)) {
368 368
 				$policy .= '\'nonce-'.base64_encode($this->useJsNonce).'\'';
369 369
 				$allowedScriptDomains = array_flip($this->allowedScriptDomains);
370 370
 				unset($allowedScriptDomains['\'self\'']);
371 371
 				$this->allowedScriptDomains = array_flip($allowedScriptDomains);
372
-				if(count($allowedScriptDomains) !== 0) {
372
+				if (count($allowedScriptDomains) !== 0) {
373 373
 					$policy .= ' ';
374 374
 				}
375 375
 			}
376
-			if(is_array($this->allowedScriptDomains)) {
376
+			if (is_array($this->allowedScriptDomains)) {
377 377
 				$policy .= implode(' ', $this->allowedScriptDomains);
378 378
 			}
379
-			if($this->inlineScriptAllowed) {
379
+			if ($this->inlineScriptAllowed) {
380 380
 				$policy .= ' \'unsafe-inline\'';
381 381
 			}
382
-			if($this->evalScriptAllowed) {
382
+			if ($this->evalScriptAllowed) {
383 383
 				$policy .= ' \'unsafe-eval\'';
384 384
 			}
385 385
 			$policy .= ';';
386 386
 		}
387 387
 
388
-		if(!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) {
388
+		if (!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) {
389 389
 			$policy .= 'style-src ';
390
-			if(is_array($this->allowedStyleDomains)) {
390
+			if (is_array($this->allowedStyleDomains)) {
391 391
 				$policy .= implode(' ', $this->allowedStyleDomains);
392 392
 			}
393
-			if($this->inlineStyleAllowed) {
393
+			if ($this->inlineStyleAllowed) {
394 394
 				$policy .= ' \'unsafe-inline\'';
395 395
 			}
396 396
 			$policy .= ';';
397 397
 		}
398 398
 
399
-		if(!empty($this->allowedImageDomains)) {
400
-			$policy .= 'img-src ' . implode(' ', $this->allowedImageDomains);
399
+		if (!empty($this->allowedImageDomains)) {
400
+			$policy .= 'img-src '.implode(' ', $this->allowedImageDomains);
401 401
 			$policy .= ';';
402 402
 		}
403 403
 
404
-		if(!empty($this->allowedFontDomains)) {
405
-			$policy .= 'font-src ' . implode(' ', $this->allowedFontDomains);
404
+		if (!empty($this->allowedFontDomains)) {
405
+			$policy .= 'font-src '.implode(' ', $this->allowedFontDomains);
406 406
 			$policy .= ';';
407 407
 		}
408 408
 
409
-		if(!empty($this->allowedConnectDomains)) {
410
-			$policy .= 'connect-src ' . implode(' ', $this->allowedConnectDomains);
409
+		if (!empty($this->allowedConnectDomains)) {
410
+			$policy .= 'connect-src '.implode(' ', $this->allowedConnectDomains);
411 411
 			$policy .= ';';
412 412
 		}
413 413
 
414
-		if(!empty($this->allowedMediaDomains)) {
415
-			$policy .= 'media-src ' . implode(' ', $this->allowedMediaDomains);
414
+		if (!empty($this->allowedMediaDomains)) {
415
+			$policy .= 'media-src '.implode(' ', $this->allowedMediaDomains);
416 416
 			$policy .= ';';
417 417
 		}
418 418
 
419
-		if(!empty($this->allowedObjectDomains)) {
420
-			$policy .= 'object-src ' . implode(' ', $this->allowedObjectDomains);
419
+		if (!empty($this->allowedObjectDomains)) {
420
+			$policy .= 'object-src '.implode(' ', $this->allowedObjectDomains);
421 421
 			$policy .= ';';
422 422
 		}
423 423
 
424
-		if(!empty($this->allowedFrameDomains)) {
425
-			$policy .= 'frame-src ' . implode(' ', $this->allowedFrameDomains);
424
+		if (!empty($this->allowedFrameDomains)) {
425
+			$policy .= 'frame-src '.implode(' ', $this->allowedFrameDomains);
426 426
 			$policy .= ';';
427 427
 		}
428 428
 
429
-		if(!empty($this->allowedChildSrcDomains)) {
430
-			$policy .= 'child-src ' . implode(' ', $this->allowedChildSrcDomains);
429
+		if (!empty($this->allowedChildSrcDomains)) {
430
+			$policy .= 'child-src '.implode(' ', $this->allowedChildSrcDomains);
431 431
 			$policy .= ';';
432 432
 		}
433 433
 
434
-		if(!empty($this->allowedFrameAncestors)) {
435
-			$policy .= 'frame-ancestors ' . implode(' ', $this->allowedFrameAncestors);
434
+		if (!empty($this->allowedFrameAncestors)) {
435
+			$policy .= 'frame-ancestors '.implode(' ', $this->allowedFrameAncestors);
436 436
 			$policy .= ';';
437 437
 		}
438 438
 
Please login to merge, or discard this patch.
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -34,408 +34,408 @@
 block discarded – undo
34 34
  * @since 9.0.0
35 35
  */
36 36
 class EmptyContentSecurityPolicy {
37
-	/** @var bool Whether inline JS snippets are allowed */
38
-	protected $inlineScriptAllowed = null;
39
-	/** @var string Whether JS nonces should be used */
40
-	protected $useJsNonce = null;
41
-	/**
42
-	 * @var bool Whether eval in JS scripts is allowed
43
-	 * TODO: Disallow per default
44
-	 * @link https://github.com/owncloud/core/issues/11925
45
-	 */
46
-	protected $evalScriptAllowed = null;
47
-	/** @var array Domains from which scripts can get loaded */
48
-	protected $allowedScriptDomains = null;
49
-	/**
50
-	 * @var bool Whether inline CSS is allowed
51
-	 * TODO: Disallow per default
52
-	 * @link https://github.com/owncloud/core/issues/13458
53
-	 */
54
-	protected $inlineStyleAllowed = null;
55
-	/** @var array Domains from which CSS can get loaded */
56
-	protected $allowedStyleDomains = null;
57
-	/** @var array Domains from which images can get loaded */
58
-	protected $allowedImageDomains = null;
59
-	/** @var array Domains to which connections can be done */
60
-	protected $allowedConnectDomains = null;
61
-	/** @var array Domains from which media elements can be loaded */
62
-	protected $allowedMediaDomains = null;
63
-	/** @var array Domains from which object elements can be loaded */
64
-	protected $allowedObjectDomains = null;
65
-	/** @var array Domains from which iframes can be loaded */
66
-	protected $allowedFrameDomains = null;
67
-	/** @var array Domains from which fonts can be loaded */
68
-	protected $allowedFontDomains = null;
69
-	/** @var array Domains from which web-workers and nested browsing content can load elements */
70
-	protected $allowedChildSrcDomains = null;
71
-	/** @var array Domains which can embed this Nextcloud instance */
72
-	protected $allowedFrameAncestors = null;
73
-
74
-	/**
75
-	 * Whether inline JavaScript snippets are allowed or forbidden
76
-	 * @param bool $state
77
-	 * @return $this
78
-	 * @since 8.1.0
79
-	 * @deprecated 10.0 CSP tokens are now used
80
-	 */
81
-	public function allowInlineScript($state = false) {
82
-		$this->inlineScriptAllowed = $state;
83
-		return $this;
84
-	}
85
-
86
-	/**
87
-	 * Use the according JS nonce
88
-	 *
89
-	 * @param string $nonce
90
-	 * @return $this
91
-	 * @since 11.0.0
92
-	 */
93
-	public function useJsNonce($nonce) {
94
-		$this->useJsNonce = $nonce;
95
-		return $this;
96
-	}
97
-
98
-	/**
99
-	 * Whether eval in JavaScript is allowed or forbidden
100
-	 * @param bool $state
101
-	 * @return $this
102
-	 * @since 8.1.0
103
-	 */
104
-	public function allowEvalScript($state = true) {
105
-		$this->evalScriptAllowed = $state;
106
-		return $this;
107
-	}
108
-
109
-	/**
110
-	 * Allows to execute JavaScript files from a specific domain. Use * to
111
-	 * allow JavaScript from all domains.
112
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
113
-	 * @return $this
114
-	 * @since 8.1.0
115
-	 */
116
-	public function addAllowedScriptDomain($domain) {
117
-		$this->allowedScriptDomains[] = $domain;
118
-		return $this;
119
-	}
120
-
121
-	/**
122
-	 * Remove the specified allowed script domain from the allowed domains.
123
-	 *
124
-	 * @param string $domain
125
-	 * @return $this
126
-	 * @since 8.1.0
127
-	 */
128
-	public function disallowScriptDomain($domain) {
129
-		$this->allowedScriptDomains = array_diff($this->allowedScriptDomains, [$domain]);
130
-		return $this;
131
-	}
132
-
133
-	/**
134
-	 * Whether inline CSS snippets are allowed or forbidden
135
-	 * @param bool $state
136
-	 * @return $this
137
-	 * @since 8.1.0
138
-	 */
139
-	public function allowInlineStyle($state = true) {
140
-		$this->inlineStyleAllowed = $state;
141
-		return $this;
142
-	}
143
-
144
-	/**
145
-	 * Allows to execute CSS files from a specific domain. Use * to allow
146
-	 * CSS from all domains.
147
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
148
-	 * @return $this
149
-	 * @since 8.1.0
150
-	 */
151
-	public function addAllowedStyleDomain($domain) {
152
-		$this->allowedStyleDomains[] = $domain;
153
-		return $this;
154
-	}
155
-
156
-	/**
157
-	 * Remove the specified allowed style domain from the allowed domains.
158
-	 *
159
-	 * @param string $domain
160
-	 * @return $this
161
-	 * @since 8.1.0
162
-	 */
163
-	public function disallowStyleDomain($domain) {
164
-		$this->allowedStyleDomains = array_diff($this->allowedStyleDomains, [$domain]);
165
-		return $this;
166
-	}
167
-
168
-	/**
169
-	 * Allows using fonts from a specific domain. Use * to allow
170
-	 * fonts from all domains.
171
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
172
-	 * @return $this
173
-	 * @since 8.1.0
174
-	 */
175
-	public function addAllowedFontDomain($domain) {
176
-		$this->allowedFontDomains[] = $domain;
177
-		return $this;
178
-	}
179
-
180
-	/**
181
-	 * Remove the specified allowed font domain from the allowed domains.
182
-	 *
183
-	 * @param string $domain
184
-	 * @return $this
185
-	 * @since 8.1.0
186
-	 */
187
-	public function disallowFontDomain($domain) {
188
-		$this->allowedFontDomains = array_diff($this->allowedFontDomains, [$domain]);
189
-		return $this;
190
-	}
191
-
192
-	/**
193
-	 * Allows embedding images from a specific domain. Use * to allow
194
-	 * images from all domains.
195
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
196
-	 * @return $this
197
-	 * @since 8.1.0
198
-	 */
199
-	public function addAllowedImageDomain($domain) {
200
-		$this->allowedImageDomains[] = $domain;
201
-		return $this;
202
-	}
203
-
204
-	/**
205
-	 * Remove the specified allowed image domain from the allowed domains.
206
-	 *
207
-	 * @param string $domain
208
-	 * @return $this
209
-	 * @since 8.1.0
210
-	 */
211
-	public function disallowImageDomain($domain) {
212
-		$this->allowedImageDomains = array_diff($this->allowedImageDomains, [$domain]);
213
-		return $this;
214
-	}
215
-
216
-	/**
217
-	 * To which remote domains the JS connect to.
218
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
219
-	 * @return $this
220
-	 * @since 8.1.0
221
-	 */
222
-	public function addAllowedConnectDomain($domain) {
223
-		$this->allowedConnectDomains[] = $domain;
224
-		return $this;
225
-	}
226
-
227
-	/**
228
-	 * Remove the specified allowed connect domain from the allowed domains.
229
-	 *
230
-	 * @param string $domain
231
-	 * @return $this
232
-	 * @since 8.1.0
233
-	 */
234
-	public function disallowConnectDomain($domain) {
235
-		$this->allowedConnectDomains = array_diff($this->allowedConnectDomains, [$domain]);
236
-		return $this;
237
-	}
238
-
239
-	/**
240
-	 * From which domains media elements can be embedded.
241
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
242
-	 * @return $this
243
-	 * @since 8.1.0
244
-	 */
245
-	public function addAllowedMediaDomain($domain) {
246
-		$this->allowedMediaDomains[] = $domain;
247
-		return $this;
248
-	}
249
-
250
-	/**
251
-	 * Remove the specified allowed media domain from the allowed domains.
252
-	 *
253
-	 * @param string $domain
254
-	 * @return $this
255
-	 * @since 8.1.0
256
-	 */
257
-	public function disallowMediaDomain($domain) {
258
-		$this->allowedMediaDomains = array_diff($this->allowedMediaDomains, [$domain]);
259
-		return $this;
260
-	}
261
-
262
-	/**
263
-	 * From which domains objects such as <object>, <embed> or <applet> are executed
264
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
265
-	 * @return $this
266
-	 * @since 8.1.0
267
-	 */
268
-	public function addAllowedObjectDomain($domain) {
269
-		$this->allowedObjectDomains[] = $domain;
270
-		return $this;
271
-	}
272
-
273
-	/**
274
-	 * Remove the specified allowed object domain from the allowed domains.
275
-	 *
276
-	 * @param string $domain
277
-	 * @return $this
278
-	 * @since 8.1.0
279
-	 */
280
-	public function disallowObjectDomain($domain) {
281
-		$this->allowedObjectDomains = array_diff($this->allowedObjectDomains, [$domain]);
282
-		return $this;
283
-	}
284
-
285
-	/**
286
-	 * Which domains can be embedded in an iframe
287
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
288
-	 * @return $this
289
-	 * @since 8.1.0
290
-	 */
291
-	public function addAllowedFrameDomain($domain) {
292
-		$this->allowedFrameDomains[] = $domain;
293
-		return $this;
294
-	}
295
-
296
-	/**
297
-	 * Remove the specified allowed frame domain from the allowed domains.
298
-	 *
299
-	 * @param string $domain
300
-	 * @return $this
301
-	 * @since 8.1.0
302
-	 */
303
-	public function disallowFrameDomain($domain) {
304
-		$this->allowedFrameDomains = array_diff($this->allowedFrameDomains, [$domain]);
305
-		return $this;
306
-	}
307
-
308
-	/**
309
-	 * Domains from which web-workers and nested browsing content can load elements
310
-	 * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
311
-	 * @return $this
312
-	 * @since 8.1.0
313
-	 */
314
-	public function addAllowedChildSrcDomain($domain) {
315
-		$this->allowedChildSrcDomains[] = $domain;
316
-		return $this;
317
-	}
318
-
319
-	/**
320
-	 * Remove the specified allowed child src domain from the allowed domains.
321
-	 *
322
-	 * @param string $domain
323
-	 * @return $this
324
-	 * @since 8.1.0
325
-	 */
326
-	public function disallowChildSrcDomain($domain) {
327
-		$this->allowedChildSrcDomains = array_diff($this->allowedChildSrcDomains, [$domain]);
328
-		return $this;
329
-	}
330
-
331
-	/**
332
-	 * Domains which can embed an iFrame of the Nextcloud instance
333
-	 *
334
-	 * @param string $domain
335
-	 * @return $this
336
-	 * @since 13.0.0
337
-	 */
338
-	public function addAllowedFrameAncestorDomain($domain) {
339
-		$this->allowedFrameAncestors[] = $domain;
340
-		return $this;
341
-	}
342
-
343
-	/**
344
-	 * Domains which can embed an iFrame of the Nextcloud instance
345
-	 *
346
-	 * @param string $domain
347
-	 * @return $this
348
-	 * @since 13.0.0
349
-	 */
350
-	public function disallowFrameAncestorDomain($domain) {
351
-		$this->allowedFrameAncestors = array_diff($this->allowedFrameAncestors, [$domain]);
352
-		return $this;
353
-	}
354
-
355
-	/**
356
-	 * Get the generated Content-Security-Policy as a string
357
-	 * @return string
358
-	 * @since 8.1.0
359
-	 */
360
-	public function buildPolicy() {
361
-		$policy = "default-src 'none';";
362
-		$policy .= "base-uri 'none';";
363
-		$policy .= "manifest-src 'self';";
364
-
365
-		if(!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) {
366
-			$policy .= 'script-src ';
367
-			if(is_string($this->useJsNonce)) {
368
-				$policy .= '\'nonce-'.base64_encode($this->useJsNonce).'\'';
369
-				$allowedScriptDomains = array_flip($this->allowedScriptDomains);
370
-				unset($allowedScriptDomains['\'self\'']);
371
-				$this->allowedScriptDomains = array_flip($allowedScriptDomains);
372
-				if(count($allowedScriptDomains) !== 0) {
373
-					$policy .= ' ';
374
-				}
375
-			}
376
-			if(is_array($this->allowedScriptDomains)) {
377
-				$policy .= implode(' ', $this->allowedScriptDomains);
378
-			}
379
-			if($this->inlineScriptAllowed) {
380
-				$policy .= ' \'unsafe-inline\'';
381
-			}
382
-			if($this->evalScriptAllowed) {
383
-				$policy .= ' \'unsafe-eval\'';
384
-			}
385
-			$policy .= ';';
386
-		}
387
-
388
-		if(!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) {
389
-			$policy .= 'style-src ';
390
-			if(is_array($this->allowedStyleDomains)) {
391
-				$policy .= implode(' ', $this->allowedStyleDomains);
392
-			}
393
-			if($this->inlineStyleAllowed) {
394
-				$policy .= ' \'unsafe-inline\'';
395
-			}
396
-			$policy .= ';';
397
-		}
398
-
399
-		if(!empty($this->allowedImageDomains)) {
400
-			$policy .= 'img-src ' . implode(' ', $this->allowedImageDomains);
401
-			$policy .= ';';
402
-		}
403
-
404
-		if(!empty($this->allowedFontDomains)) {
405
-			$policy .= 'font-src ' . implode(' ', $this->allowedFontDomains);
406
-			$policy .= ';';
407
-		}
408
-
409
-		if(!empty($this->allowedConnectDomains)) {
410
-			$policy .= 'connect-src ' . implode(' ', $this->allowedConnectDomains);
411
-			$policy .= ';';
412
-		}
413
-
414
-		if(!empty($this->allowedMediaDomains)) {
415
-			$policy .= 'media-src ' . implode(' ', $this->allowedMediaDomains);
416
-			$policy .= ';';
417
-		}
418
-
419
-		if(!empty($this->allowedObjectDomains)) {
420
-			$policy .= 'object-src ' . implode(' ', $this->allowedObjectDomains);
421
-			$policy .= ';';
422
-		}
423
-
424
-		if(!empty($this->allowedFrameDomains)) {
425
-			$policy .= 'frame-src ' . implode(' ', $this->allowedFrameDomains);
426
-			$policy .= ';';
427
-		}
428
-
429
-		if(!empty($this->allowedChildSrcDomains)) {
430
-			$policy .= 'child-src ' . implode(' ', $this->allowedChildSrcDomains);
431
-			$policy .= ';';
432
-		}
433
-
434
-		if(!empty($this->allowedFrameAncestors)) {
435
-			$policy .= 'frame-ancestors ' . implode(' ', $this->allowedFrameAncestors);
436
-			$policy .= ';';
437
-		}
438
-
439
-		return rtrim($policy, ';');
440
-	}
37
+    /** @var bool Whether inline JS snippets are allowed */
38
+    protected $inlineScriptAllowed = null;
39
+    /** @var string Whether JS nonces should be used */
40
+    protected $useJsNonce = null;
41
+    /**
42
+     * @var bool Whether eval in JS scripts is allowed
43
+     * TODO: Disallow per default
44
+     * @link https://github.com/owncloud/core/issues/11925
45
+     */
46
+    protected $evalScriptAllowed = null;
47
+    /** @var array Domains from which scripts can get loaded */
48
+    protected $allowedScriptDomains = null;
49
+    /**
50
+     * @var bool Whether inline CSS is allowed
51
+     * TODO: Disallow per default
52
+     * @link https://github.com/owncloud/core/issues/13458
53
+     */
54
+    protected $inlineStyleAllowed = null;
55
+    /** @var array Domains from which CSS can get loaded */
56
+    protected $allowedStyleDomains = null;
57
+    /** @var array Domains from which images can get loaded */
58
+    protected $allowedImageDomains = null;
59
+    /** @var array Domains to which connections can be done */
60
+    protected $allowedConnectDomains = null;
61
+    /** @var array Domains from which media elements can be loaded */
62
+    protected $allowedMediaDomains = null;
63
+    /** @var array Domains from which object elements can be loaded */
64
+    protected $allowedObjectDomains = null;
65
+    /** @var array Domains from which iframes can be loaded */
66
+    protected $allowedFrameDomains = null;
67
+    /** @var array Domains from which fonts can be loaded */
68
+    protected $allowedFontDomains = null;
69
+    /** @var array Domains from which web-workers and nested browsing content can load elements */
70
+    protected $allowedChildSrcDomains = null;
71
+    /** @var array Domains which can embed this Nextcloud instance */
72
+    protected $allowedFrameAncestors = null;
73
+
74
+    /**
75
+     * Whether inline JavaScript snippets are allowed or forbidden
76
+     * @param bool $state
77
+     * @return $this
78
+     * @since 8.1.0
79
+     * @deprecated 10.0 CSP tokens are now used
80
+     */
81
+    public function allowInlineScript($state = false) {
82
+        $this->inlineScriptAllowed = $state;
83
+        return $this;
84
+    }
85
+
86
+    /**
87
+     * Use the according JS nonce
88
+     *
89
+     * @param string $nonce
90
+     * @return $this
91
+     * @since 11.0.0
92
+     */
93
+    public function useJsNonce($nonce) {
94
+        $this->useJsNonce = $nonce;
95
+        return $this;
96
+    }
97
+
98
+    /**
99
+     * Whether eval in JavaScript is allowed or forbidden
100
+     * @param bool $state
101
+     * @return $this
102
+     * @since 8.1.0
103
+     */
104
+    public function allowEvalScript($state = true) {
105
+        $this->evalScriptAllowed = $state;
106
+        return $this;
107
+    }
108
+
109
+    /**
110
+     * Allows to execute JavaScript files from a specific domain. Use * to
111
+     * allow JavaScript from all domains.
112
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
113
+     * @return $this
114
+     * @since 8.1.0
115
+     */
116
+    public function addAllowedScriptDomain($domain) {
117
+        $this->allowedScriptDomains[] = $domain;
118
+        return $this;
119
+    }
120
+
121
+    /**
122
+     * Remove the specified allowed script domain from the allowed domains.
123
+     *
124
+     * @param string $domain
125
+     * @return $this
126
+     * @since 8.1.0
127
+     */
128
+    public function disallowScriptDomain($domain) {
129
+        $this->allowedScriptDomains = array_diff($this->allowedScriptDomains, [$domain]);
130
+        return $this;
131
+    }
132
+
133
+    /**
134
+     * Whether inline CSS snippets are allowed or forbidden
135
+     * @param bool $state
136
+     * @return $this
137
+     * @since 8.1.0
138
+     */
139
+    public function allowInlineStyle($state = true) {
140
+        $this->inlineStyleAllowed = $state;
141
+        return $this;
142
+    }
143
+
144
+    /**
145
+     * Allows to execute CSS files from a specific domain. Use * to allow
146
+     * CSS from all domains.
147
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
148
+     * @return $this
149
+     * @since 8.1.0
150
+     */
151
+    public function addAllowedStyleDomain($domain) {
152
+        $this->allowedStyleDomains[] = $domain;
153
+        return $this;
154
+    }
155
+
156
+    /**
157
+     * Remove the specified allowed style domain from the allowed domains.
158
+     *
159
+     * @param string $domain
160
+     * @return $this
161
+     * @since 8.1.0
162
+     */
163
+    public function disallowStyleDomain($domain) {
164
+        $this->allowedStyleDomains = array_diff($this->allowedStyleDomains, [$domain]);
165
+        return $this;
166
+    }
167
+
168
+    /**
169
+     * Allows using fonts from a specific domain. Use * to allow
170
+     * fonts from all domains.
171
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
172
+     * @return $this
173
+     * @since 8.1.0
174
+     */
175
+    public function addAllowedFontDomain($domain) {
176
+        $this->allowedFontDomains[] = $domain;
177
+        return $this;
178
+    }
179
+
180
+    /**
181
+     * Remove the specified allowed font domain from the allowed domains.
182
+     *
183
+     * @param string $domain
184
+     * @return $this
185
+     * @since 8.1.0
186
+     */
187
+    public function disallowFontDomain($domain) {
188
+        $this->allowedFontDomains = array_diff($this->allowedFontDomains, [$domain]);
189
+        return $this;
190
+    }
191
+
192
+    /**
193
+     * Allows embedding images from a specific domain. Use * to allow
194
+     * images from all domains.
195
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
196
+     * @return $this
197
+     * @since 8.1.0
198
+     */
199
+    public function addAllowedImageDomain($domain) {
200
+        $this->allowedImageDomains[] = $domain;
201
+        return $this;
202
+    }
203
+
204
+    /**
205
+     * Remove the specified allowed image domain from the allowed domains.
206
+     *
207
+     * @param string $domain
208
+     * @return $this
209
+     * @since 8.1.0
210
+     */
211
+    public function disallowImageDomain($domain) {
212
+        $this->allowedImageDomains = array_diff($this->allowedImageDomains, [$domain]);
213
+        return $this;
214
+    }
215
+
216
+    /**
217
+     * To which remote domains the JS connect to.
218
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
219
+     * @return $this
220
+     * @since 8.1.0
221
+     */
222
+    public function addAllowedConnectDomain($domain) {
223
+        $this->allowedConnectDomains[] = $domain;
224
+        return $this;
225
+    }
226
+
227
+    /**
228
+     * Remove the specified allowed connect domain from the allowed domains.
229
+     *
230
+     * @param string $domain
231
+     * @return $this
232
+     * @since 8.1.0
233
+     */
234
+    public function disallowConnectDomain($domain) {
235
+        $this->allowedConnectDomains = array_diff($this->allowedConnectDomains, [$domain]);
236
+        return $this;
237
+    }
238
+
239
+    /**
240
+     * From which domains media elements can be embedded.
241
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
242
+     * @return $this
243
+     * @since 8.1.0
244
+     */
245
+    public function addAllowedMediaDomain($domain) {
246
+        $this->allowedMediaDomains[] = $domain;
247
+        return $this;
248
+    }
249
+
250
+    /**
251
+     * Remove the specified allowed media domain from the allowed domains.
252
+     *
253
+     * @param string $domain
254
+     * @return $this
255
+     * @since 8.1.0
256
+     */
257
+    public function disallowMediaDomain($domain) {
258
+        $this->allowedMediaDomains = array_diff($this->allowedMediaDomains, [$domain]);
259
+        return $this;
260
+    }
261
+
262
+    /**
263
+     * From which domains objects such as <object>, <embed> or <applet> are executed
264
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
265
+     * @return $this
266
+     * @since 8.1.0
267
+     */
268
+    public function addAllowedObjectDomain($domain) {
269
+        $this->allowedObjectDomains[] = $domain;
270
+        return $this;
271
+    }
272
+
273
+    /**
274
+     * Remove the specified allowed object domain from the allowed domains.
275
+     *
276
+     * @param string $domain
277
+     * @return $this
278
+     * @since 8.1.0
279
+     */
280
+    public function disallowObjectDomain($domain) {
281
+        $this->allowedObjectDomains = array_diff($this->allowedObjectDomains, [$domain]);
282
+        return $this;
283
+    }
284
+
285
+    /**
286
+     * Which domains can be embedded in an iframe
287
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
288
+     * @return $this
289
+     * @since 8.1.0
290
+     */
291
+    public function addAllowedFrameDomain($domain) {
292
+        $this->allowedFrameDomains[] = $domain;
293
+        return $this;
294
+    }
295
+
296
+    /**
297
+     * Remove the specified allowed frame domain from the allowed domains.
298
+     *
299
+     * @param string $domain
300
+     * @return $this
301
+     * @since 8.1.0
302
+     */
303
+    public function disallowFrameDomain($domain) {
304
+        $this->allowedFrameDomains = array_diff($this->allowedFrameDomains, [$domain]);
305
+        return $this;
306
+    }
307
+
308
+    /**
309
+     * Domains from which web-workers and nested browsing content can load elements
310
+     * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
311
+     * @return $this
312
+     * @since 8.1.0
313
+     */
314
+    public function addAllowedChildSrcDomain($domain) {
315
+        $this->allowedChildSrcDomains[] = $domain;
316
+        return $this;
317
+    }
318
+
319
+    /**
320
+     * Remove the specified allowed child src domain from the allowed domains.
321
+     *
322
+     * @param string $domain
323
+     * @return $this
324
+     * @since 8.1.0
325
+     */
326
+    public function disallowChildSrcDomain($domain) {
327
+        $this->allowedChildSrcDomains = array_diff($this->allowedChildSrcDomains, [$domain]);
328
+        return $this;
329
+    }
330
+
331
+    /**
332
+     * Domains which can embed an iFrame of the Nextcloud instance
333
+     *
334
+     * @param string $domain
335
+     * @return $this
336
+     * @since 13.0.0
337
+     */
338
+    public function addAllowedFrameAncestorDomain($domain) {
339
+        $this->allowedFrameAncestors[] = $domain;
340
+        return $this;
341
+    }
342
+
343
+    /**
344
+     * Domains which can embed an iFrame of the Nextcloud instance
345
+     *
346
+     * @param string $domain
347
+     * @return $this
348
+     * @since 13.0.0
349
+     */
350
+    public function disallowFrameAncestorDomain($domain) {
351
+        $this->allowedFrameAncestors = array_diff($this->allowedFrameAncestors, [$domain]);
352
+        return $this;
353
+    }
354
+
355
+    /**
356
+     * Get the generated Content-Security-Policy as a string
357
+     * @return string
358
+     * @since 8.1.0
359
+     */
360
+    public function buildPolicy() {
361
+        $policy = "default-src 'none';";
362
+        $policy .= "base-uri 'none';";
363
+        $policy .= "manifest-src 'self';";
364
+
365
+        if(!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) {
366
+            $policy .= 'script-src ';
367
+            if(is_string($this->useJsNonce)) {
368
+                $policy .= '\'nonce-'.base64_encode($this->useJsNonce).'\'';
369
+                $allowedScriptDomains = array_flip($this->allowedScriptDomains);
370
+                unset($allowedScriptDomains['\'self\'']);
371
+                $this->allowedScriptDomains = array_flip($allowedScriptDomains);
372
+                if(count($allowedScriptDomains) !== 0) {
373
+                    $policy .= ' ';
374
+                }
375
+            }
376
+            if(is_array($this->allowedScriptDomains)) {
377
+                $policy .= implode(' ', $this->allowedScriptDomains);
378
+            }
379
+            if($this->inlineScriptAllowed) {
380
+                $policy .= ' \'unsafe-inline\'';
381
+            }
382
+            if($this->evalScriptAllowed) {
383
+                $policy .= ' \'unsafe-eval\'';
384
+            }
385
+            $policy .= ';';
386
+        }
387
+
388
+        if(!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) {
389
+            $policy .= 'style-src ';
390
+            if(is_array($this->allowedStyleDomains)) {
391
+                $policy .= implode(' ', $this->allowedStyleDomains);
392
+            }
393
+            if($this->inlineStyleAllowed) {
394
+                $policy .= ' \'unsafe-inline\'';
395
+            }
396
+            $policy .= ';';
397
+        }
398
+
399
+        if(!empty($this->allowedImageDomains)) {
400
+            $policy .= 'img-src ' . implode(' ', $this->allowedImageDomains);
401
+            $policy .= ';';
402
+        }
403
+
404
+        if(!empty($this->allowedFontDomains)) {
405
+            $policy .= 'font-src ' . implode(' ', $this->allowedFontDomains);
406
+            $policy .= ';';
407
+        }
408
+
409
+        if(!empty($this->allowedConnectDomains)) {
410
+            $policy .= 'connect-src ' . implode(' ', $this->allowedConnectDomains);
411
+            $policy .= ';';
412
+        }
413
+
414
+        if(!empty($this->allowedMediaDomains)) {
415
+            $policy .= 'media-src ' . implode(' ', $this->allowedMediaDomains);
416
+            $policy .= ';';
417
+        }
418
+
419
+        if(!empty($this->allowedObjectDomains)) {
420
+            $policy .= 'object-src ' . implode(' ', $this->allowedObjectDomains);
421
+            $policy .= ';';
422
+        }
423
+
424
+        if(!empty($this->allowedFrameDomains)) {
425
+            $policy .= 'frame-src ' . implode(' ', $this->allowedFrameDomains);
426
+            $policy .= ';';
427
+        }
428
+
429
+        if(!empty($this->allowedChildSrcDomains)) {
430
+            $policy .= 'child-src ' . implode(' ', $this->allowedChildSrcDomains);
431
+            $policy .= ';';
432
+        }
433
+
434
+        if(!empty($this->allowedFrameAncestors)) {
435
+            $policy .= 'frame-ancestors ' . implode(' ', $this->allowedFrameAncestors);
436
+            $policy .= ';';
437
+        }
438
+
439
+        return rtrim($policy, ';');
440
+    }
441 441
 }
Please login to merge, or discard this patch.
lib/private/Security/CSP/ContentSecurityPolicy.php 1 patch
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -29,186 +29,186 @@
 block discarded – undo
29 29
  * @package OC\Security\CSP
30 30
  */
31 31
 class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy {
32
-	/**
33
-	 * @return boolean
34
-	 */
35
-	public function isInlineScriptAllowed() {
36
-		return $this->inlineScriptAllowed;
37
-	}
38
-
39
-	/**
40
-	 * @param boolean $inlineScriptAllowed
41
-	 */
42
-	public function setInlineScriptAllowed($inlineScriptAllowed) {
43
-		$this->inlineScriptAllowed = $inlineScriptAllowed;
44
-	}
45
-
46
-	/**
47
-	 * @return boolean
48
-	 */
49
-	public function isEvalScriptAllowed() {
50
-		return $this->evalScriptAllowed;
51
-	}
52
-
53
-	/**
54
-	 * @param boolean $evalScriptAllowed
55
-	 */
56
-	public function setEvalScriptAllowed($evalScriptAllowed) {
57
-		$this->evalScriptAllowed = $evalScriptAllowed;
58
-	}
59
-
60
-	/**
61
-	 * @return array
62
-	 */
63
-	public function getAllowedScriptDomains() {
64
-		return $this->allowedScriptDomains;
65
-	}
66
-
67
-	/**
68
-	 * @param array $allowedScriptDomains
69
-	 */
70
-	public function setAllowedScriptDomains($allowedScriptDomains) {
71
-		$this->allowedScriptDomains = $allowedScriptDomains;
72
-	}
73
-
74
-	/**
75
-	 * @return boolean
76
-	 */
77
-	public function isInlineStyleAllowed() {
78
-		return $this->inlineStyleAllowed;
79
-	}
80
-
81
-	/**
82
-	 * @param boolean $inlineStyleAllowed
83
-	 */
84
-	public function setInlineStyleAllowed($inlineStyleAllowed) {
85
-		$this->inlineStyleAllowed = $inlineStyleAllowed;
86
-	}
87
-
88
-	/**
89
-	 * @return array
90
-	 */
91
-	public function getAllowedStyleDomains() {
92
-		return $this->allowedStyleDomains;
93
-	}
94
-
95
-	/**
96
-	 * @param array $allowedStyleDomains
97
-	 */
98
-	public function setAllowedStyleDomains($allowedStyleDomains) {
99
-		$this->allowedStyleDomains = $allowedStyleDomains;
100
-	}
101
-
102
-	/**
103
-	 * @return array
104
-	 */
105
-	public function getAllowedImageDomains() {
106
-		return $this->allowedImageDomains;
107
-	}
108
-
109
-	/**
110
-	 * @param array $allowedImageDomains
111
-	 */
112
-	public function setAllowedImageDomains($allowedImageDomains) {
113
-		$this->allowedImageDomains = $allowedImageDomains;
114
-	}
115
-
116
-	/**
117
-	 * @return array
118
-	 */
119
-	public function getAllowedConnectDomains() {
120
-		return $this->allowedConnectDomains;
121
-	}
122
-
123
-	/**
124
-	 * @param array $allowedConnectDomains
125
-	 */
126
-	public function setAllowedConnectDomains($allowedConnectDomains) {
127
-		$this->allowedConnectDomains = $allowedConnectDomains;
128
-	}
129
-
130
-	/**
131
-	 * @return array
132
-	 */
133
-	public function getAllowedMediaDomains() {
134
-		return $this->allowedMediaDomains;
135
-	}
136
-
137
-	/**
138
-	 * @param array $allowedMediaDomains
139
-	 */
140
-	public function setAllowedMediaDomains($allowedMediaDomains) {
141
-		$this->allowedMediaDomains = $allowedMediaDomains;
142
-	}
143
-
144
-	/**
145
-	 * @return array
146
-	 */
147
-	public function getAllowedObjectDomains() {
148
-		return $this->allowedObjectDomains;
149
-	}
150
-
151
-	/**
152
-	 * @param array $allowedObjectDomains
153
-	 */
154
-	public function setAllowedObjectDomains($allowedObjectDomains) {
155
-		$this->allowedObjectDomains = $allowedObjectDomains;
156
-	}
157
-
158
-	/**
159
-	 * @return array
160
-	 */
161
-	public function getAllowedFrameDomains() {
162
-		return $this->allowedFrameDomains;
163
-	}
164
-
165
-	/**
166
-	 * @param array $allowedFrameDomains
167
-	 */
168
-	public function setAllowedFrameDomains($allowedFrameDomains) {
169
-		$this->allowedFrameDomains = $allowedFrameDomains;
170
-	}
171
-
172
-	/**
173
-	 * @return array
174
-	 */
175
-	public function getAllowedFontDomains() {
176
-		return $this->allowedFontDomains;
177
-	}
178
-
179
-	/**
180
-	 * @param array $allowedFontDomains
181
-	 */
182
-	public function setAllowedFontDomains($allowedFontDomains) {
183
-		$this->allowedFontDomains = $allowedFontDomains;
184
-	}
185
-
186
-	/**
187
-	 * @return array
188
-	 */
189
-	public function getAllowedChildSrcDomains() {
190
-		return $this->allowedChildSrcDomains;
191
-	}
192
-
193
-	/**
194
-	 * @param array $allowedChildSrcDomains
195
-	 */
196
-	public function setAllowedChildSrcDomains($allowedChildSrcDomains) {
197
-		$this->allowedChildSrcDomains = $allowedChildSrcDomains;
198
-	}
199
-
200
-	/**
201
-	 * @return array
202
-	 */
203
-	public function getAllowedFrameAncestors() {
204
-		return $this->allowedFrameAncestors;
205
-	}
206
-
207
-	/**
208
-	 * @param array $allowedFrameAncestors
209
-	 */
210
-	public function setAllowedFrameAncestors($allowedFrameAncestors) {
211
-		$this->allowedFrameAncestors = $allowedFrameAncestors;
212
-	}
32
+    /**
33
+     * @return boolean
34
+     */
35
+    public function isInlineScriptAllowed() {
36
+        return $this->inlineScriptAllowed;
37
+    }
38
+
39
+    /**
40
+     * @param boolean $inlineScriptAllowed
41
+     */
42
+    public function setInlineScriptAllowed($inlineScriptAllowed) {
43
+        $this->inlineScriptAllowed = $inlineScriptAllowed;
44
+    }
45
+
46
+    /**
47
+     * @return boolean
48
+     */
49
+    public function isEvalScriptAllowed() {
50
+        return $this->evalScriptAllowed;
51
+    }
52
+
53
+    /**
54
+     * @param boolean $evalScriptAllowed
55
+     */
56
+    public function setEvalScriptAllowed($evalScriptAllowed) {
57
+        $this->evalScriptAllowed = $evalScriptAllowed;
58
+    }
59
+
60
+    /**
61
+     * @return array
62
+     */
63
+    public function getAllowedScriptDomains() {
64
+        return $this->allowedScriptDomains;
65
+    }
66
+
67
+    /**
68
+     * @param array $allowedScriptDomains
69
+     */
70
+    public function setAllowedScriptDomains($allowedScriptDomains) {
71
+        $this->allowedScriptDomains = $allowedScriptDomains;
72
+    }
73
+
74
+    /**
75
+     * @return boolean
76
+     */
77
+    public function isInlineStyleAllowed() {
78
+        return $this->inlineStyleAllowed;
79
+    }
80
+
81
+    /**
82
+     * @param boolean $inlineStyleAllowed
83
+     */
84
+    public function setInlineStyleAllowed($inlineStyleAllowed) {
85
+        $this->inlineStyleAllowed = $inlineStyleAllowed;
86
+    }
87
+
88
+    /**
89
+     * @return array
90
+     */
91
+    public function getAllowedStyleDomains() {
92
+        return $this->allowedStyleDomains;
93
+    }
94
+
95
+    /**
96
+     * @param array $allowedStyleDomains
97
+     */
98
+    public function setAllowedStyleDomains($allowedStyleDomains) {
99
+        $this->allowedStyleDomains = $allowedStyleDomains;
100
+    }
101
+
102
+    /**
103
+     * @return array
104
+     */
105
+    public function getAllowedImageDomains() {
106
+        return $this->allowedImageDomains;
107
+    }
108
+
109
+    /**
110
+     * @param array $allowedImageDomains
111
+     */
112
+    public function setAllowedImageDomains($allowedImageDomains) {
113
+        $this->allowedImageDomains = $allowedImageDomains;
114
+    }
115
+
116
+    /**
117
+     * @return array
118
+     */
119
+    public function getAllowedConnectDomains() {
120
+        return $this->allowedConnectDomains;
121
+    }
122
+
123
+    /**
124
+     * @param array $allowedConnectDomains
125
+     */
126
+    public function setAllowedConnectDomains($allowedConnectDomains) {
127
+        $this->allowedConnectDomains = $allowedConnectDomains;
128
+    }
129
+
130
+    /**
131
+     * @return array
132
+     */
133
+    public function getAllowedMediaDomains() {
134
+        return $this->allowedMediaDomains;
135
+    }
136
+
137
+    /**
138
+     * @param array $allowedMediaDomains
139
+     */
140
+    public function setAllowedMediaDomains($allowedMediaDomains) {
141
+        $this->allowedMediaDomains = $allowedMediaDomains;
142
+    }
143
+
144
+    /**
145
+     * @return array
146
+     */
147
+    public function getAllowedObjectDomains() {
148
+        return $this->allowedObjectDomains;
149
+    }
150
+
151
+    /**
152
+     * @param array $allowedObjectDomains
153
+     */
154
+    public function setAllowedObjectDomains($allowedObjectDomains) {
155
+        $this->allowedObjectDomains = $allowedObjectDomains;
156
+    }
157
+
158
+    /**
159
+     * @return array
160
+     */
161
+    public function getAllowedFrameDomains() {
162
+        return $this->allowedFrameDomains;
163
+    }
164
+
165
+    /**
166
+     * @param array $allowedFrameDomains
167
+     */
168
+    public function setAllowedFrameDomains($allowedFrameDomains) {
169
+        $this->allowedFrameDomains = $allowedFrameDomains;
170
+    }
171
+
172
+    /**
173
+     * @return array
174
+     */
175
+    public function getAllowedFontDomains() {
176
+        return $this->allowedFontDomains;
177
+    }
178
+
179
+    /**
180
+     * @param array $allowedFontDomains
181
+     */
182
+    public function setAllowedFontDomains($allowedFontDomains) {
183
+        $this->allowedFontDomains = $allowedFontDomains;
184
+    }
185
+
186
+    /**
187
+     * @return array
188
+     */
189
+    public function getAllowedChildSrcDomains() {
190
+        return $this->allowedChildSrcDomains;
191
+    }
192
+
193
+    /**
194
+     * @param array $allowedChildSrcDomains
195
+     */
196
+    public function setAllowedChildSrcDomains($allowedChildSrcDomains) {
197
+        $this->allowedChildSrcDomains = $allowedChildSrcDomains;
198
+    }
199
+
200
+    /**
201
+     * @return array
202
+     */
203
+    public function getAllowedFrameAncestors() {
204
+        return $this->allowedFrameAncestors;
205
+    }
206
+
207
+    /**
208
+     * @param array $allowedFrameAncestors
209
+     */
210
+    public function setAllowedFrameAncestors($allowedFrameAncestors) {
211
+        $this->allowedFrameAncestors = $allowedFrameAncestors;
212
+    }
213 213
 
214 214
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/ContentSecurityPolicy.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -38,53 +38,53 @@
 block discarded – undo
38 38
  * @since 8.1.0
39 39
  */
40 40
 class ContentSecurityPolicy extends EmptyContentSecurityPolicy {
41
-	/** @var bool Whether inline JS snippets are allowed */
42
-	protected $inlineScriptAllowed = false;
43
-	/**
44
-	 * @var bool Whether eval in JS scripts is allowed
45
-	 * TODO: Disallow per default
46
-	 * @link https://github.com/owncloud/core/issues/11925
47
-	 */
48
-	protected $evalScriptAllowed = true;
49
-	/** @var array Domains from which scripts can get loaded */
50
-	protected $allowedScriptDomains = [
51
-		'\'self\'',
52
-	];
53
-	/**
54
-	 * @var bool Whether inline CSS is allowed
55
-	 * TODO: Disallow per default
56
-	 * @link https://github.com/owncloud/core/issues/13458
57
-	 */
58
-	protected $inlineStyleAllowed = true;
59
-	/** @var array Domains from which CSS can get loaded */
60
-	protected $allowedStyleDomains = [
61
-		'\'self\'',
62
-	];
63
-	/** @var array Domains from which images can get loaded */
64
-	protected $allowedImageDomains = [
65
-		'\'self\'',
66
-		'data:',
67
-		'blob:',
68
-	];
69
-	/** @var array Domains to which connections can be done */
70
-	protected $allowedConnectDomains = [
71
-		'\'self\'',
72
-	];
73
-	/** @var array Domains from which media elements can be loaded */
74
-	protected $allowedMediaDomains = [
75
-		'\'self\'',
76
-	];
77
-	/** @var array Domains from which object elements can be loaded */
78
-	protected $allowedObjectDomains = [];
79
-	/** @var array Domains from which iframes can be loaded */
80
-	protected $allowedFrameDomains = [];
81
-	/** @var array Domains from which fonts can be loaded */
82
-	protected $allowedFontDomains = [
83
-		'\'self\'',
84
-	];
85
-	/** @var array Domains from which web-workers and nested browsing content can load elements */
86
-	protected $allowedChildSrcDomains = [];
41
+    /** @var bool Whether inline JS snippets are allowed */
42
+    protected $inlineScriptAllowed = false;
43
+    /**
44
+     * @var bool Whether eval in JS scripts is allowed
45
+     * TODO: Disallow per default
46
+     * @link https://github.com/owncloud/core/issues/11925
47
+     */
48
+    protected $evalScriptAllowed = true;
49
+    /** @var array Domains from which scripts can get loaded */
50
+    protected $allowedScriptDomains = [
51
+        '\'self\'',
52
+    ];
53
+    /**
54
+     * @var bool Whether inline CSS is allowed
55
+     * TODO: Disallow per default
56
+     * @link https://github.com/owncloud/core/issues/13458
57
+     */
58
+    protected $inlineStyleAllowed = true;
59
+    /** @var array Domains from which CSS can get loaded */
60
+    protected $allowedStyleDomains = [
61
+        '\'self\'',
62
+    ];
63
+    /** @var array Domains from which images can get loaded */
64
+    protected $allowedImageDomains = [
65
+        '\'self\'',
66
+        'data:',
67
+        'blob:',
68
+    ];
69
+    /** @var array Domains to which connections can be done */
70
+    protected $allowedConnectDomains = [
71
+        '\'self\'',
72
+    ];
73
+    /** @var array Domains from which media elements can be loaded */
74
+    protected $allowedMediaDomains = [
75
+        '\'self\'',
76
+    ];
77
+    /** @var array Domains from which object elements can be loaded */
78
+    protected $allowedObjectDomains = [];
79
+    /** @var array Domains from which iframes can be loaded */
80
+    protected $allowedFrameDomains = [];
81
+    /** @var array Domains from which fonts can be loaded */
82
+    protected $allowedFontDomains = [
83
+        '\'self\'',
84
+    ];
85
+    /** @var array Domains from which web-workers and nested browsing content can load elements */
86
+    protected $allowedChildSrcDomains = [];
87 87
 
88
-	/** @var array Domains which can embed this Nextcloud instance */
89
-	protected $allowedFrameAncestors = [];
88
+    /** @var array Domains which can embed this Nextcloud instance */
89
+    protected $allowedFrameAncestors = [];
90 90
 }
Please login to merge, or discard this patch.